From ed027cc3fa4dd98935bfaa2b6e84d9f38655dfaf Mon Sep 17 00:00:00 2001 From: Jakob Struye Date: Sat, 7 Jul 2018 20:27:28 +0200 Subject: [PATCH 1/3] Removed the 'dont_update_from_title' flag, now updates from title iff no js_unread is set --- app/model/Readme.md | 5 +---- app/model/ServiceList.js | 4 ---- app/store/ServicesList.js | 14 -------------- app/ux/WebView.js | 5 +++-- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/app/model/Readme.md b/app/model/Readme.md index 14774c7a..fd11f488 100644 --- a/app/model/Readme.md +++ b/app/model/Readme.md @@ -15,13 +15,10 @@ Structure of a service entry: |note|Additional info to display when adding the service.|no| |manual_notifications|Set to `true` to let Rambox trigger notifications. Can be used for services that doesn't support browser notifications.|no| |js_unread|JavaScript code for setting the unread count (see below).|no| -|dont_update_unread_from_title|Set to `true` to prevent updating the unread count from the window title (see below).|no| ### Setting the unread count -While there is also a way to set the unread count by adding ` (COUNT)` to the window title, this describes the preferred way of doing it: - -First set `dont_update_unread_from_title` in the service config to `true`. +While by default the unread count is determined by looking for ` (COUNT)` to the window title, this describes the preferred way of doing it: Code provided by `js_unread` will be injected into the service website. You can retrieve the unread count in this JavaScript code e.g. by parsing elements. diff --git a/app/model/ServiceList.js b/app/model/ServiceList.js index a2c45e93..db337612 100644 --- a/app/model/ServiceList.js +++ b/app/model/ServiceList.js @@ -48,9 +48,5 @@ Ext.define('Rambox.model.ServiceList', { name: 'custom_domain' ,type: 'boolean' ,defaultValue: false - },{ - name: 'dont_update_unread_from_title' - ,type: 'boolean' - ,defaultValue: false }] }); diff --git a/app/store/ServicesList.js b/app/store/ServicesList.js index e2d21734..0e9ef819 100644 --- a/app/store/ServicesList.js +++ b/app/store/ServicesList.js @@ -29,7 +29,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://web.whatsapp.com/' ,type: 'messaging' ,js_unread: 'function checkUnread(){const elements = document.querySelectorAll(\'.CxUIE, .unread\');let count = 0;for (let i = 0; i < elements.length; i++) {if (elements[i].querySelectorAll(\'*[data-icon="muted"]\').length === 0) {count++;}}updateBadge(count);}function updateBadge(count){if(count && count>=1){rambox.setUnreadCount(count);}else{rambox.clearUnreadCount();}}setInterval(checkUnread, 1e3);' - ,dont_update_unread_from_title: true }, { id: 'slack' @@ -77,7 +76,6 @@ Ext.define('Rambox.store.ServicesList', { ,type: 'messaging' ,titleBlink: true ,manual_notifications: true - ,dont_update_unread_from_title: true ,js_unread: 'function checkUnread(){updateBadge(document.getElementById("hangout-landing-chat").lastChild.contentWindow.document.body.getElementsByClassName("ee").length)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);' }, { @@ -98,7 +96,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://web.telegram.org/' ,type: 'messaging' ,js_unread: 'function checkUnread(){var e=document.getElementsByClassName("im_dialog_badge badge"),t=0;for(i=0;i=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);' - ,dont_update_unread_from_title: true }, { id: 'wechat' @@ -118,7 +115,6 @@ Ext.define('Rambox.store.ServicesList', { ,allow_popups: true ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("aim")[0];updateBadge(-1!=a.textContent.indexOf("(")&&(t=parseInt(a.textContent.replace(/[^0-9]/g,""))))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' ,note: 'To enable desktop notifications, you have to go to Settings inside Gmail. Read more...' - ,dont_update_unread_from_title: true }, { id: 'inbox' @@ -149,7 +145,6 @@ Ext.define('Rambox.store.ServicesList', { ,type: 'messaging' ,note: 'To enable desktop notifications, you have to go to Options inside GroupMe. To count unread messages, be sure to be in Chats.' ,js_unread: 'function checkUnread(){var a=document.querySelectorAll(".badge-count:not(.ng-hide)"),b=0;for(i=0;i=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' - ,dont_update_unread_from_title: true }, { id: 'grape' @@ -514,7 +509,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://www.icloud.com/#mail' ,type: 'email' ,js_unread: 'function checkUnread(){updateBadge(document.querySelector(".current-app").querySelector(".sb-badge").style.display==="none"?0:parseInt(document.querySelector(".current-app").querySelector(".text").innerHTML.trim()))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' - ,dont_update_unread_from_title: true }, { id: 'rainloop' @@ -644,7 +638,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://web.flock.co/' ,type: 'messaging' ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unreadMessages no-unread-mentions has-unread"),b=0;for(i=0;i=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' - ,dont_update_unread_from_title: true }, { @@ -671,7 +664,6 @@ Ext.define('Rambox.store.ServicesList', { url: 'https://www.xing.com/messages/conversations', type: 'messaging', js_unread: '(function() { let originalTitle = document.title; function checkUnread() { let count = null; let notificationElement = document.querySelector(\'[data-update="unread_conversations"]\'); if (notificationElement && notificationElement.style.display !== \'none\') { count = parseInt(notificationElement.textContent.trim(), 10); } updateBadge(count); } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();', - dont_update_unread_from_title: true }, { id: 'threema', @@ -681,7 +673,6 @@ Ext.define('Rambox.store.ServicesList', { url: 'https://web.threema.ch/', type: 'messaging', js_unread: '(function () { let unreadCount = 0; function checkUnread() { let newUnread = 0; try { let webClientService = angular.element(document.documentElement).injector().get(\'WebClientService\'); let conversations = webClientService.conversations.conversations; conversations.forEach(function(conversation) { newUnread += conversation.unreadCount; }); } catch (e) { } if (newUnread !== unreadCount) { unreadCount = newUnread; updateBadge(unreadCount); } } function updateBadge(count) { if (count && count >= 1) { rambox.setUnreadCount(count); } else { rambox.clearUnreadCount(); } } setInterval(checkUnread, 3000); checkUnread(); })();', - dont_update_unread_from_title: true }, { id: 'workplace' @@ -733,7 +724,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://app.zyptonite.com/' ,type: 'messaging' ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("z-messages"),b=0;for(i=0;i=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' - ,dont_update_unread_from_title: true }, { id: 'fastmail' @@ -806,7 +796,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://___/chat' ,type: 'messaging' ,js_unread: 'function checkUnread(){updateBadge(parseInt(document.getElementsByClassName("sidebar-notification-indicator").length > 0 ? document.getElementsByClassName("sidebar-notification-indicator")[0].innerHTML : 0))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' - ,dont_update_unread_from_title: true }, { id: 'clocktweets' @@ -824,7 +813,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://app.intercom.io' ,type: 'messaging' ,js_unread: 'function checkUnread(){var a=document.getElementsByClassName("unread")[0];updateBadge(t=a===undefined?0:parseInt(a.textContent.replace(/[^0-9]/g,"")))}function updateBadge(a){a>=1?rambox.setUnreadCount(a):rambox.clearUnreadCount()}setInterval(checkUnread,3000);' - ,dont_update_unread_from_title: true }, { id: 'allo' @@ -834,7 +822,6 @@ Ext.define('Rambox.store.ServicesList', { ,url: 'https://allo.google.com/web' ,type: 'messaging' ,js_unread: 'function checkUnread(){var e=document.querySelectorAll(".hasUnread.conversation_item"),n=0;for(i=0;i=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3e3);' - ,dont_update_unread_from_title: true }, { id: 'Kune' @@ -906,7 +893,6 @@ Ext.define('Rambox.store.ServicesList', { ,type: 'messaging' ,titleBlink: true ,manual_notifications: true - ,dont_update_unread_from_title: true ,js_unread: 'function checkUnread(){updateBadge(document.querySelectorAll(".SSPGKf.EyyDtb.Q6oXP:not(.oCHqfe) .eM5l9e.FVKzAb").length)}function updateBadge(e){e>=1?rambox.setUnreadCount(e):rambox.clearUnreadCount()}setInterval(checkUnread,3000);' } ] diff --git a/app/ux/WebView.js b/app/ux/WebView.js index 51af59cf..70139821 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -497,9 +497,10 @@ Ext.define('Rambox.ux.WebView',{ }); /** - * Register page title update event listener only for services that don't prevent it by setting 'dont_update_unread_from_title' to true. + * Register page title update event listener only for services that don't specify a js_unread */ - if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('dont_update_unread_from_title') !== true) { + if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('js_unread') === '' && + me.record.get('js_unread') === '') { webview.addEventListener("page-title-updated", function(e) { var count = e.title.match(/\(([^)]+)\)/); // Get text between (...) count = count ? count[1] : '0'; From 481da048051b44b8e46f7422941b503b5172ac97 Mon Sep 17 00:00:00 2001 From: Jakob Struye Date: Sun, 22 Jul 2018 18:08:22 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Setting=20"=E2=80=A2"=20as=20unread=20count?= =?UTF-8?q?=20now=20possible=20from=20js=5Funread,=20updated=20Slack=20js?= =?UTF-8?q?=5Funread=20to=20do=20this.=20TODO=20add=20for=20other=20servic?= =?UTF-8?q?es=20with=20"=E2=80=A2".?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/ServicesList.js | 2 +- app/ux/WebView.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/store/ServicesList.js b/app/store/ServicesList.js index 0e9ef819..3fe2d703 100644 --- a/app/store/ServicesList.js +++ b/app/store/ServicesList.js @@ -37,7 +37,7 @@ Ext.define('Rambox.store.ServicesList', { ,description: locale['services[1]'] ,url: 'https://___.slack.com/' ,type: 'messaging' - ,js_unread: 'function checkUnread(){var e=$(".p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)").length,a=0;$(".p-channel_sidebar__badge").each(function(){a+=isNaN(parseInt($(this).html()))?0:parseInt($(this).html())}),updateBadge(e,a)}function updateBadge(e,a){var n=a>0?"("+a+") ":e>0?"(•) ":"";document.title=n+originalTitle}var originalTitle=document.title;setInterval(checkUnread,3e3);' + ,js_unread: 'function checkUnread(){var e=$(".p-channel_sidebar__channel--unread:not(.p-channel_sidebar__channel--muted)").length,n=0;$(".p-channel_sidebar__badge").each(function(){n+=isNaN(parseInt($(this).html()))?0:parseInt($(this).html())}),count=0 0) { var count = event.args[0]; - if (count === parseInt(count, 10)) { + if (count === parseInt(count, 10) || "•" === count) { me.setUnreadCount(count); } } From 1bcdfa814c6f6d03a291c2957b85b80cec29eceb Mon Sep 17 00:00:00 2001 From: Ramiro Saenz Date: Fri, 31 Aug 2018 16:44:42 -0300 Subject: [PATCH 3/3] Merging --- app/model/Readme.md | 4 ++-- app/ux/WebView.js | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/model/Readme.md b/app/model/Readme.md index fd11f488..ba158430 100644 --- a/app/model/Readme.md +++ b/app/model/Readme.md @@ -18,8 +18,8 @@ Structure of a service entry: ### Setting the unread count -While by default the unread count is determined by looking for ` (COUNT)` to the window title, this describes the preferred way of doing it: +While by default the unread count is determined by looking for `(COUNT)` to the window title, this describes the preferred way of doing it: Code provided by `js_unread` will be injected into the service website. You can retrieve the unread count in this JavaScript code e.g. by parsing elements. -Set the unread count by calling `rambox.setUnreadCount(COUNT)` or clear it by calling `rambox.clearUnreadCount()`. +Set the unread count by calling `rambox.setUnreadCount(COUNT)` or clear it by calling `rambox.clearUnreadCount()`. diff --git a/app/ux/WebView.js b/app/ux/WebView.js index d7eb9e01..4b63200d 100644 --- a/app/ux/WebView.js +++ b/app/ux/WebView.js @@ -477,8 +477,7 @@ Ext.define('Rambox.ux.WebView',{ /** * Handles 'rambox.setUnreadCount' messages. - * Sets the badge text if the event contains an integer - * or a '•' (indicating non-zero but unknown number of unreads) as first argument. + * Sets the badge text if the event contains an integer or a '•' (indicating non-zero but unknown number of unreads) as first argument. * * @param event */ @@ -500,8 +499,7 @@ Ext.define('Rambox.ux.WebView',{ /** * Register page title update event listener only for services that don't specify a js_unread */ - if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('js_unread') === '' && - me.record.get('js_unread') === '') { + if (Ext.getStore('ServicesList').getById(me.record.get('type')).get('js_unread') === '' && me.record.get('js_unread') === '') { webview.addEventListener("page-title-updated", function(e) { var count = e.title.match(/\(([^)]+)\)/); // Get text between (...) count = count ? count[1] : '0';