Ukagaka Shell Title Notifier

检测#robot_speech_js 中包含"你有"时闪烁网页标题,提醒用户有新消息。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Ukagaka Shell Title Notifier
// @namespace    https://jirehlov.com
// @version      0.1
// @description  检测#robot_speech_js 中包含"你有"时闪烁网页标题,提醒用户有新消息。
// @author       Jirehlov
// @match        https://bgm.tv/*
// @match        https://bangumi.tv/*
// @match        https://chii.in/*
// @grant        none
// @license      MIT
// ==/UserScript==
let originalTitle = document.title;
let interval;
function updateTitle() {
	if ($("#robot_speech_js:contains(\"你有\")").length > 0) {
		if (!interval) {
			interval = setInterval(() => {
				document.title = document.title.startsWith("\u3010新消息\u3011") ? originalTitle : "\u3010新消息\u3011" + originalTitle;
			}, 500);
		}
	} else {
		clearInterval(interval);
		interval = null;
		document.title = originalTitle;
	}
}
updateTitle();
new MutationObserver(updateTitle).observe(document.querySelector("#robot_speech_js"), {
	childList: true,
	subtree: true
});