Created
July 30, 2023 04:39
-
-
Save qatoqat/58fb01985bd30ba088afd7b84cfe0cd9 to your computer and use it in GitHub Desktop.
Append notification number to title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Append notification, probably for Firefox | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Change the website's favicon to Stack Overflow's favicon. | |
// @author You | |
// @match https://*.twitter.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=twitter.com | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
function findNotificationsNum(query) { | |
const divElements = document.querySelectorAll('div[aria-label]'); | |
const matchingDivs = []; | |
divElements.forEach((div) => { | |
const ariaLabel = div.getAttribute('aria-label'); | |
if (ariaLabel.endsWith('unread items') ) { | |
const wordsArray = ariaLabel.split(' '); | |
const firstWord = wordsArray[0]; // Get the first element of the array | |
if (!isNaN(firstWord)){ | |
if (document.title.startsWith("(")){ | |
const titleArray = document.title.split(' '); | |
document.title = "(" + firstWord + ") " + titleArray.slice(1).join(' ');; | |
} | |
else{ | |
document.title = "(" + firstWord + ") " + document.title; | |
} | |
} | |
} | |
}); | |
} | |
setInterval(findNotificationsNum, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment