Hide Piazza Stories Badge

Exclude Piazza Stories from the overall notifications badge

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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;
}