Hide Piazza Stories Badge

Exclude Piazza Stories from the overall notifications badge

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name Hide Piazza Stories Badge
// @description Exclude Piazza Stories from the overall notifications badge
// @match *://piazza.com/*
// @grant none
// @noframes
// @version 1.1
// @icon https://piazza.com/favicon.ico
// @namespace https://greasyfork.org/users/167667
// ==/UserScript==

//console.log("Userscript is running");

globalBadge = document.getElementById("global_notifications_indicator");
if (globalBadge === null || globalBadge === undefined) {
  console.log("Userscript error: Global notification indicator not found");
  return;
}

storiesBadge = document.getElementById("dropdown_notifications_stories_ixoaerg0y5u6e6");
if (storiesBadge === null || storiesBadge === undefined) {
  console.log("Userscript error: Piazza Stories notification badge not found");
  return;
}

storiesNum = Number(storiesBadge.innerText);
if (storiesNum === null || storiesNum === undefined || isNaN(storiesNum)) {
  console.log("Userscript error: Piazza Stories notification badge has non-numeric value");
  return;
} else if (storiesNum < 0) {
  console.log("Userscript error: Piazza Stories notification badge has negative value");
  return;
}

globalNum = Number(globalBadge.innerText) - storiesNum;

if (globalNum === null || globalNum === undefined) {
  return;
} else if (globalNum < 0) {
  console.log("Userscript error: Notification number shouldn't be negative!");
  return;
} else if (globalNum === 0) {
  globalBadge.parentNode.style.visibility = 'hidden';
} else {
  globalBadge.innerText = globalNum;
}