Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name robin-spam-filter
- // @namespace http://tampermonkey.net/
- // @version 0.4
- // @description Robin Spam Filter
- // @author u/AyrA_ch
- // @match https://www.reddit.com/robin*
- // @grant none
- // ==/UserScript==
- function injectMessage(message)
- {
- var d2=function(q)
- {
- if(q<10)
- {
- return "0"+q;
- }
- return q;
- };
- var dt=new Date();
- var time=(dt.getHours()>12?dt.getHours()-12:dt.getHours())+":"+d2(dt.getMinutes())+":"+d2(dt.getSeconds())+" "+(dt.getHours()>=12?"PM":"AM");
- var template="<div class=\"robin-message robin--flair-class--no-flair robin--message-class--message robin--user-class--system\">"+
- "<span class=\"robin-message--timestamp\">"+time+"</span>"+
- "<span class=\"robin-message--from robin--username\">[SCRIPT]</span>"+
- "<span class=\"robin-message--message\">"+message+"</span>"+
- "</div>";
- document.querySelector('#robinChatMessageList').innerHTML+=template;
- return template;
- }
- function spamFilterInit(){
- //CONFIG HERE//
- //Add stuff to block in the list below. Be sure to add commas except after the last item
- var Block=[
- "voted to GROW",
- "voted to STAY",
- "voted to ABANDON",
- "/4cyqiy",
- "/4cwk2s",
- "Current grow(",
- "Current stay(",
- "Current abandon(",
- "Available commands:",
- "[Robin Autovoter",
- "[Silent Robin",
- "Current standings [",
- "RobinFacts",
- "[Robin-",
- "[STATS]",
- "Autovote",
- "autovote",
- "oooooooooooo",
- "卐",
- "http://",
- "https://",
- "www.",
- "---DEV---",
- "doot",
- "777",
- ">>>",
- " - - -"
- ];
- //Add users to block here:
- var Users=[];
- //Add users to never block here. Same comma rule as with the "Users" variable above
- var Whitelist=[
- "AyrA_ch",
- "[robin]"
- ];
- //set to true, to see notes in the console when a message is blocked
- var printer=false;
- //set to true, to hide text containing excessive unicode crap
- var HideUnicode=true;
- //set the unicode cutoff. Lower removes more messages, but might hide legit messages too
- var UnicodeSegments=20;
- //Hides uppercase spam if it exceeds 1/4 of all chars
- var HideUppercase=true;
- //STOP HERE//
- //generic stuff
- var title=document.title.split(" ")[2];
- var usercount=title.length/2;
- var target=document.querySelector('#robinChatMessageList');
- var txtBox=$("#robinSendMessage > input[type='text']");
- if(localStorage.getItem("robin.blockedUsers"))
- {
- Users=Users.concat(localStorage.getItem("robin.blockedUsers").split(','));
- console.debug("Loaded blocked users list:",Users);
- }
- var isUnicodeSpam=function(m)
- {
- return encodeURIComponent(m).replace(/\%20/g,"_").split("%").length>UnicodeSegments;
- };
- var isUppercaseSpam=function(m)
- {
- var uc="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- return m.split("").filter(function(v){return uc.indexOf(v)>=0;}).length>m.length/4;
- };
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- var hide=function()
- {
- mutation.addedNodes[0].style.display = "none";
- };
- var msg = mutation.addedNodes[0].lastElementChild.textContent;
- var username = mutation.addedNodes[0].lastElementChild.previousElementSibling.textContent;
- //if the username is the time, because it was missing. We add it from the previous node
- if(mutation.addedNodes[0].lastElementChild.previousElementSibling.nodeName===document.createElement("time").nodeName)
- {
- username=mutation.addedNodes[0].previousElementSibling.lastElementChild.previousElementSibling.textContent;
- var ele=document.createElement("span");
- ele.textContent=username;
- ele.setAttribute("class","robin-message--from robin--username");
- mutation.addedNodes[0].insertBefore(ele,mutation.addedNodes[0].lastElementChild);
- console.debug("detected user:",username);
- }
- //always show our messages and system messages
- if(username===$(".user > a").text() || Whitelist.indexOf(username)>=0)
- {
- return;
- }
- mutation.addedNodes[0].lastElementChild.previousElementSibling.onclick=function()
- {
- if(confirm("block "+username+"?"))
- {
- Users.push(username);
- localStorage.setItem("robin.blockedUsers",Users.join(","));
- injectMessage("User blocked: "+username);
- }
- };
- if(Users.indexOf(username)>=0)
- {
- hide();
- if(printer)
- {
- console.log("[USER] blocked:",username);
- }
- return;
- }
- for(var x in Block)
- {
- if(msg.indexOf(Block[x])>=0)
- {
- hide();
- if(printer)
- {
- console.log("[CONTENT] blocked:",Block[x]);
- }
- return;
- }
- }
- if(HideUppercase && isUppercaseSpam(msg))
- {
- hide();
- if(printer)
- {
- console.log("[UPPERCASE] blocked");
- }
- }
- if(HideUnicode && isUnicodeSpam(msg))
- {
- hide();
- if(printer)
- {
- console.log("[UNICODE] blocked");
- }
- }
- });
- });
- observer.observe(target, {childList: true});
- txtBox.on("keyup",function(e){
- if(e.keyCode==13)
- {
- if(txtBox.val().indexOf("/unblock ")===0)
- {
- var param=txtBox.val().split(' ')[1];
- if(Users.indexOf(param)>=0)
- {
- Users=Users.filter(function(v){return v!=param;});
- txtBox.val("");
- injectMessage("Unblocked "+param);
- }
- else
- {
- injectMessage("This user is not in the block list. Use /blist to show blocked users");
- }
- }
- else if(txtBox.val()=="/blist")
- {
- txtBox.val("");
- injectMessage("List of blocked users:\r\n"+Users.join(", "));
- }
- else if(txtBox.val()=="/cls")
- {
- txtBox.val("");
- target.innerHTML=injectMessage("Chat cleared");
- }
- else if(txtBox.val()=="/title")
- {
- txtBox.val("");
- injectMessage(title);
- }
- }
- });
- console.debug("Spam filter ready");
- injectMessage("Spam filter ready");
- injectMessage(title);
- injectMessage(usercount+" users here");
- }
- //setTimeout(spamFilterInit, 5000);
- if(typeof($)==typeof(undefined))
- {
- console.debug("no jQuery");
- }
- else
- {
- spamFilterInit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement