Hide Piazza Stories Badge

Exclude Piazza Stories from the overall notifications badge

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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