Greasy Fork

来自缓存

Greasy Fork is available in English.

Taigachat Notifier

Alerts you when your name is mentioned

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Taigachat Notifier
// @namespace    Terrium.net
// @version      1.2.2
// @description  Alerts you when your name is mentioned
// @author       Lamp
// @include      http://terrium.net/index.php?taigachat/
// @include      http://terrium.net/index.php?taigachat/popup
// @include      http://terrium.net/index.php
// @grant        none
// ==/UserScript==

// ==Settings==
var yourName = "Potato"; // Your name or the text that will trigger the notification (not case-sensitive)
var changeFaviconEnabled = true; // Enable/disable changing the favicon when notifying
var soundEnabled = true; // Enable/disable playing sound when notifying
var PushNotificationEnabled = true; // Enable/disable sending push/desktop/browser notification when notifying
var modifyRefreshRateEnabled = false; // Enable/disable modifying the chat refresh rate for faster response and greater reliability
var customRefreshRate = 1; // The new refresh rate to use when modifying refresh rate is enabled; Time in seconds between chat refreshes
var soundFileURL = "http://a.pomf.cat/sqlnkb.mp3"; // URL to notification sound file
var alertFaviconURL = "http://a.pomf.cat/rlnuys.ICO"; // URL to notification favicon file
// ============

var msg;
var isNotified = false;
var sound = new Audio(soundFileURL);
if(PushNotificationEnabled) checkNotification();
if(modifyRefreshRateEnabled) {setTimeout(function () {taigachat.refreshtime = customRefreshRate;
													  taigachat.focusedRefreshTime = customRefreshRate;
													  taigachat.unfocusedRefreshTime = customRefreshRate;
													  taigachat.tabUnfocusedRefreshTime = customRefreshRate;
													 },1000);}
window.onblur = denotify;

setInterval(function() {
	msg = $(".taigachat_messagetext").last()[0].innerText;
	if (msg.toLowerCase().includes(yourName.toLowerCase())) notify();
}, 1000);

function notify() {
	if (!isNotified) {
		if (changeFaviconEnabled) changeFavicon(alertFaviconURL);
		if (soundEnabled) sound.play();
		if (PushNotificationEnabled) {var idk = new Notification('“'+msg+'”');}
	}
	isNotified = true;
}

function denotify() {
	if (isNotified) {
		if (changeFaviconEnabled) changeFavicon('/favicon.ico');
		isNotified = false;
	}
}

// http://stackoverflow.com/a/2995536
document.head = document.head || document.getElementsByTagName('head')[0];
function changeFavicon(src) {
	var link = document.createElement('link'),
		oldLink = document.getElementById('dynamic-favicon');
	link.id = 'dynamic-favicon';
	link.rel = 'shortcut icon';
	link.href = src;
	if (oldLink) {
		document.head.removeChild(oldLink);
	}
	document.head.appendChild(link);
}

// derived from https://jsfiddle.net/3sdr9Lqj/2/
function checkNotification() {
	if (!("Notification" in window)) {
		alert("This browser does not support push notifications.");
	} else if (Notification.permission !== 'denied') {
		Notification.requestPermission(function(permission) {
			if (!('permission' in Notification)) {
				Notification.permission = permission;
			}

		});
	}
}