Hide Piazza Stories Badge

Exclude Piazza Stories from the overall notifications badge

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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