DH2 Chat Filter

目前為 2017-03-16 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        DH2 Chat Filter
// @namespace   siderislabs
// @include     http://*.diamondhunt.co/game.php
// @version     1
// @locale us_EN
// @description:en This script lets you filter out words you don't like in DH2 chat.
// ==/UserScript==  

var sendBytesProxy = window.sendBytes;
var chatProxy = window.addToChatBox;
var tmp = "";
var filteredWords = [];
var wordDetected;
var isFound = 0;
var override;

console.log("DH2 Chat Filter active.");

window.sendBytes = function(e) {
	if(e.startsWith("CHAT=!addfilter")) {
		doAddFilter(e);
	}
	else if(e.startsWith("CHAT=!listfilters")) {
		doListFilters();
	}
	else if(e.startsWith("CHAT=!removefilter")) {
		doRemoveFilter(e);
	}
	else if(e.startsWith("CHAT=!help")) {
		doPrintHelp();
	}
	else {
		sendBytesProxy.apply(this, arguments);
	}
}

window.addToChatBox = function(username, icon, tag, message, isPM) {
	for(i = 0; i < filteredWords.length; i++) {
		if(arguments[3].includes(filteredWords[i]) && override == 0) {
			wordDetected = 1;
		}
	}
	if(wordDetected == 1) {
		wordDetected = 0;
		return;
	}
	else {
		chatProxy.apply(this, arguments);
	}
	wordDetected = 0;
}

doAddFilter = function(e) {
	tmp = e.replace("CHAT=", "");
	tmp = tmp.replace("!addfilter ", "");
	for(i = 0; i < filteredWords.length; i++) {
		if(tmp == filteredWords[i]) {
			isFound = 1;
		}
	}
	if(isFound == 0) {
		filteredWords.push(tmp);
		window.addToChatBox("placeholder", "0", "5", "Word successfully added to filter list.", "0");
		console.log(filteredWords);
	}
	else {
		window.addToChatBox("placeholder", "0", "5", "That word is already in your filter list.", "0");
	}
}

doRemoveFilter = function(e) {
	tmp = e.replace("CHAT=", "");
	tmp = tmp.replace("!removefilter ", "");
	if(filteredWords.indexOf(tmp) != -1) {
		filteredWords.splice(filteredWords.indexOf(tmp), 1);
		window.addToChatBox("placeholder", "0", "5", "Word successfully removed from filter list.", "0");
		console.log(filteredWords);
	}
	else {
		window.addToChatBox("placeholder", "0", "5", "That word is not in your filter list.", "0");
	}
}

doListFilters = function() {
	override = 1;
	window.addToChatBox("placeholder", "0", "5", "List of filtered words: " + filteredWords.toString(), "0");
	override = 0;
}

doPrintHelp = function() {
	window.addToChatBox("placeholder", "0", "5", "!addfilter [word]: Adds a word to your filter list.", "0");
	window.addToChatBox("placeholder", "0", "5", "!listfilters: Lists the words you have filtered.", "0");
	window.addToChatBox("placeholder", "0", "5", "!removefilter [word]: Removes a world from your filter list.", "0");
}