PASTEDOWN
145
0
918 8.56 KB 249
918 8.56 KB 249
CyTube Retard Filter
By FloorbCreated: 2024-10-06 02:17:46
Updated: 2024-10-09 07:07:31
Expiry: Never
This is another user script that filters out messages that I don't like from CyTube chat. It also adds a counter for filtered messages, as well as an average of number of messages filtered per second. You can change the arrays to make it filter messages (you) don't like instead!
New version (works on Firefox for sure, not tested on Chrome yet)
// @name CyTube Retard Filter
// @namespace http://neet.horse/
// @version 0.3.0
// @description Filter fucking retarded chat messages (AKA messages I personally don't like) from CyTube
// @author Floorb
// @match https://cytu.be/r/mlpanniversary
// @icon https://www.google.com/s2/favicons?sz=64&domain=cytu.be
// @grant none
// ==/UserScript==
// Trying to make scripts that fuck with global functions like this is fucking annoying because of Greasemonkey's retarded
// sandboxing that you can just get around by injecting a <script> node anyways.
(function() {
unsafeWindow.backupAddChatMessage = null;
var backupAddChatMessage = unsafeWindow.addChatMessage;
// If a message contains any of these strings, bypass filtering on it
var whitelist = ['floorb'];
// If a message contains any of these strings, kill it.
var blacklist = ['i hate the antifim', 'haber', 'remove creatures', 'i hate the anti fim', ':writers.room:', ':moonman:', 'not canon', 'i hate this episode'];
// If a message matches any of these regexes, kill it.
var niggeregexes = [/:i.think.ponyville.sucks: [0-9]+ :i.think.ponyville.sucks:/];
// Counter of number of messages we killed.
var killedMessages = 0;
// Moving average stuff for stats.
var avgWindow = 30 * 1000;
var alpha = 2 / (31); // Smoothing factor for 30-second window
var filteredMessages = [];
var ema = 0;
function messagesFilteredLastSecond() {
var now = Date.now();
return filteredMessages.filter(timestamp => now - timestamp <= 1000).length;
}
function updateEMA() {
const currentValue = messagesFilteredLastSecond();
ema = alpha * currentValue + (1 - alpha) * ema;
updateKilledMessages();
}
function updateKilledMessages() {
var elem = document.getElementById('rf-killed');
if (!elem) {
var child = document.getElementById('ugh'); // Embiggen Emote List button
if (!child) return;
elem = document.createElement('span');
elem.id = 'rf-killed';
child.parentElement.insertBefore(elem, child.nextSibling);
}
elem.innerText = "Filtered: " + killedMessages + " (" + ema.toFixed(2) + "/sec)";
}
// Called whenever we kill a message
function killedMessage(data) {
var now = Date.now();
console.log('[CyTube Retard Filter] Killed message (' + killedMessages + ' total)');
console.log(data);
filteredMessages.push(now);
// Remove messages outside the 30-second window
filteredMessages = filteredMessages.filter(timestamp => now - timestamp <= avgWindow);
killedMessages++;
updateKilledMessages();
return null;
}
function hookAddChatMessage(data) {
var msg = data.msg.toLowerCase();
// Don't filter messages that mention us
if (unsafeWindow.CLIENT && unsafeWindow.CLIENT.name && msg.indexOf(unsafeWindow.CLIENT.name.toLowerCase()) !== -1) {
return unsafeWindow.backupAddChatMessage(data);
}
for (const wl of whitelist) {
if (msg.indexOf(wl) !== -1) {
return backupAddChatMessage(data);
}
}
for (const bl of blacklist) {
if (msg.indexOf(bl) !== -1) {
killedMessage(data);
return null;
}
}
for (const nr of niggeregexes) {
if (nr.test(msg)) {
killedMessage(data);
return null;
}
}
return unsafeWindow.backupAddChatMessage(data);
}
exportFunction(hookAddChatMessage, unsafeWindow, {defineAs: "hookAddChatMessage"});
// This is in a setTimeout() because we need to wait for all the Xae shit to finish loading.
// This will have the effect of redefining the global addChatMessage() function to call our hook.
setTimeout(() => {
var script = document.createElement('script');
script.textContent = `
window.backupAddChatMessage = window.addChatMessage;
window.addChatMessage = function(data) {
return hookAddChatMessage(data);
}
console.log('[CyTube Chat Filter] Hooked addChatMessage()');
`;
document.body.appendChild(script);
}, 10000);
setInterval(updateEMA, 1000);
})();
Old version (only works on Chrome, does not work on Firefox)
// ==UserScript==
// @name CyTube Retard Filter
// @namespace http://neet.horse/
// @version 0.2.0
// @description Filter fucking retarded chat messages (AKA messages I personally don't like) from CyTube
// @author Floorb
// @match https://cytu.be/r/mlpanniversary
// @icon https://www.google.com/s2/favicons?sz=64&domain=cytu.be
// @grant none
// ==/UserScript==
// I was really drunk when I wrote most of this so please don't judge too much.
(function() {
var backupAddChatMessage = window.addChatMessage;
// If a message contains any of these strings, bypass filtering on it
var whitelist = ['floorb'];
// If a message contains any of these strings, kill it.
var blacklist = ['i hate the antifim', 'haber', 'remove creatures', 'i hate the anti fim', ':writers.room:', ':moonman:', 'not canon', 'i hate this episode'];
// If a message matches any of these regexes, kill it.
var niggeregexes = [/:i.think.ponyville.sucks: [0-9]+ :i.think.ponyville.sucks:/];
// Counter of number of messages we killed.
var killedMessages = 0;
// Moving average stuff for stats.
var avgWindow = 30 * 1000;
var alpha = 2 / (31); // Smoothing factor for 30-second window
var filteredMessages = [];
var ema = 0;
function messagesFilteredLastSecond() {
var now = Date.now();
return filteredMessages.filter(timestamp => now - timestamp <= 1000).length;
}
function updateEMA() {
const currentValue = messagesFilteredLastSecond();
ema = alpha * currentValue + (1 - alpha) * ema;
updateKilledMessages();
// console.log("Current EMA of messages filtered per second:", ema);
}
function updateKilledMessages() {
var elem = document.getElementById('rf-killed');
if (!elem) {
var child = document.getElementById('ugh'); // Embiggen Emote List button
if (!child) return;
elem = document.createElement('span');
elem.id = 'rf-killed';
child.parentElement.insertBefore(elem, child.nextSibling);
}
elem.innerText = "Filtered: " + killedMessages + " (" + ema.toFixed(2) + "/sec)";
}
// Called whenever we kill a message
function killedMessage(data) {
var now = Date.now();
console.log('[CyTube Retard Filter] Killed message (' + killedMessages + ' total)');
console.log(data);
filteredMessages.push(now);
// Remove messages outside the 30-second window
filteredMessages = filteredMessages.filter(timestamp => now - timestamp <= avgWindow);
killedMessages++;
updateKilledMessages();
return null;
}
function hookAddChatMessage(data) {
var msg = data.msg.toLowerCase();
// Don't filter messages that mention us
if (window.CLIENT && window.CLIENT.name && msg.indexOf(window.CLIENT.name.toLowerCase()) !== -1) {
return backupAddChatMessage(data);
}
for (const wl of whitelist) {
if (msg.indexOf(wl) !== -1) {
return backupAddChatMessage(data);
}
}
for (const bl of blacklist) {
if (msg.indexOf(bl) !== -1) {
killedMessage(data);
return null;
}
}
for (const nr of niggeregexes) {
if (nr.test(msg)) {
killedMessage(data);
return null;
}
}
return backupAddChatMessage(data);
}
var interval = setInterval(function() {
if (window.addChatMessage != hookAddChatMessage) {
backupAddChatMessage = window.addChatMessage;
window.addChatMessage = hookAddChatMessage;
console.log('[CyTube Retard Filter] Hooked window.addChatMessage');
}
}, 1000);
// Update moving average every second
setInterval(updateEMA, 1000);
})();