Skip to content

Instantly share code, notes, and snippets.

@qatoqat
Created July 30, 2023 04:39
Show Gist options
  • Save qatoqat/58fb01985bd30ba088afd7b84cfe0cd9 to your computer and use it in GitHub Desktop.
Save qatoqat/58fb01985bd30ba088afd7b84cfe0cd9 to your computer and use it in GitHub Desktop.
Append notification number to title
// ==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