summarylogtreecommitdiffstats
path: root/counter.js
diff options
context:
space:
mode:
authorAlexandria2020-12-25 11:00:49 -0800
committerAlexandria2020-12-25 11:00:49 -0800
commitb8d537ccdaef312a42c20c5240059a15f1b94e48 (patch)
treeaa2c8d16182a1ff81cd37e213d28713c377346d9 /counter.js
downloadaur-b8d537ccdaef312a42c20c5240059a15f1b94e48.tar.gz
first
Diffstat (limited to 'counter.js')
-rw-r--r--counter.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/counter.js b/counter.js
new file mode 100644
index 000000000000..ea4bea87fdec
--- /dev/null
+++ b/counter.js
@@ -0,0 +1,37 @@
+function updateBadgeCount()
+{
+ var targetNodes = document.getElementsByClassName("navItemBadge");
+
+ var count = 0;
+ for (var i = 0; i < targetNodes.length; ++i)
+ {
+ // ignore the unreads in spam
+ // previousElementSibling is of class navItemLabel and has the name of the section in it (e.g., " Spam ")
+ if (targetNodes[i].previousElementSibling.innerHTML.trim().toLowerCase().localeCompare("spam") == 0)
+ {
+ continue;
+ }
+ count += parseInt(targetNodes[i].innerHTML);
+ }
+ count /= 2; // because Google Voice has duplicate nodes for some reason
+
+ var newTitle = "Voice" + (count > 0 ? " (" + count + ")" : "");
+ if (document.title !== newTitle)
+ {
+ document.title = newTitle;
+ }
+}
+
+// Update the badge every 5 seconds
+setInterval(updateBadgeCount, 5000);
+
+// update the badge as user clicks in the app, because GV updates the title with selected item's phone number
+new MutationObserver(function(mutations) {
+ updateBadgeCount();
+}).observe(
+ document.querySelector('title'), {
+ subtree: true,
+ characterData: true,
+ childList: true
+ }
+);