Ukagaka Shell Title Notifier

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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
});