paintbalbot

amtikappa.user.js

Dec 31st, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         AntiKappa - Remove chat spam from Twitch.tv
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.84
  5. // @description  Removes repetitive spam from Twitch.tv. Includes personal r9k mode, and removes caps lock, ascii, repetitive text if you want (and more).
  6. // @author       BlackOdd & Judge2020 (Reddit: /u/BlackOdder & /u/judge2020)
  7. // @include      http*://www.twitch.tv*
  8. // @grant        none
  9. // @require      http://code.jquery.com/jquery-latest.js
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12.  
  13. var AntiKappa = {      
  14.  
  15.     //CHANGE SETTINGS HERE
  16.     r9kModeBool: true, //personal twitch r9k
  17.     blockExclusiveUpperCaseBool: true, //removes exclusive caps lock
  18.     blockMostlyUpperCaseBool: true, //blocks messages with mostly caps lock
  19.     blockVeryLongMessagesBool: false, //removes long messages which usually contains repetitive copy pastes
  20.     blockRepeatedWordInSentenceBool: true, //removes repeated words, like "Kappa Kappa Kappa"
  21.     blockTypicalSpamBool: true, //removes suspected random spam
  22.     blockNonEnglishCharactersBool: false, //blocks everything that isn't the standard ASCII character set
  23.     //CHANGE SETTINGS HERE
  24.  
  25.     messageArray: [],
  26.     debugModeBool: true,
  27.     longMessageCountInt: 140,
  28.     mostlyUpperCaseTheshholdPercentage: 70,
  29.     repeatedWordInSentenceCountInt: 3,
  30.     typicalSpamStringArray: [ //will block the sentence if it contains any of these words, and you have "blockTypicalSpamBool" set to true
  31.         "gachi", "feelsgoodman", "feelsbadman", "kkona",
  32.     ],
  33. };
  34.  
  35. $(document).ready(function(){  
  36.     'use strict';
  37.  
  38.     AntiKappa.logDebugMessage = function(message){        
  39.         if(AntiKappa.debugModeBool){
  40.             console.log("AntiKappa - " + message);
  41.         }
  42.     };
  43.  
  44.     AntiKappa.mainLoop = function(){
  45.         //AntiKappa.logDebugMessage('mainLoop');
  46.         AntiKappa.checkMessages();
  47.         AntiKappa.cleanUp();
  48.     };
  49.  
  50.     AntiKappa.checkMessages = function(){
  51.         //AntiKappa.logDebugMessage('addMessages');                
  52.         $('ul.chat-lines span.message:not(.AntiKappaAccepted)').each(function(){            
  53.             var $message = $(this);
  54.             var $parent = $(this).parent().parent();
  55.             //var text = AntiKappa.translateEmoticonsAndReturnTextFromMessage($message).trim();
  56.             var textWithoutEmotes = $message.text();
  57.            
  58.             //AntiKappa.checkMessage(text, $message, $parent);
  59.             AntiKappa.checkMessage(textWithoutEmotes, $message, $parent);
  60.         });
  61.     };
  62.    
  63.     AntiKappa.checkMessage = function(text, $message, $parent){
  64.         if(!AntiKappa.isSpam(text)){
  65.             AntiKappa.logDebugMessage('ACCEPTED: ' + text);
  66.  
  67.             $message.addClass('AntiKappaAccepted');
  68.             $parent.addClass('AntiKappaAccepted');
  69.             AntiKappa.messageArray.push(text);                        
  70.         }
  71.         else
  72.         {            
  73.             AntiKappa.logDebugMessage('REJECTED: ' + text);
  74.  
  75.             $parent.remove();
  76.         }        
  77.     };    
  78.    
  79.     AntiKappa.translateEmoticonsAndReturnTextFromMessage = function($message){
  80.         var text = $message.text();        
  81.         $message.children('.emoticon').each(function(){
  82.             text = text + " " + $(this).attr('alt');
  83.         });
  84.        
  85.         return text;
  86.     };
  87.  
  88.     AntiKappa.purgeEntries = function(){
  89.         AntiKappa.messageArray = [];
  90.     };
  91.  
  92.     AntiKappa.cleanUp = function(){
  93.         $('span.deleted').each(function(){
  94.             $(this).parent().parent().remove();
  95.         });
  96.     };
  97.  
  98.     AntiKappa.isSpam = function(text){        
  99.         if(text === ""){
  100.             return true;
  101.         }
  102.  
  103.         if(AntiKappa.blockVeryLongMessagesBool){
  104.             if(text.length > AntiKappa.longMessageCountInt){
  105.                 return true;
  106.             }
  107.         }
  108.        
  109.         if(AntiKappa.blockMostlyUpperCaseBool){
  110.             if(AntiKappa.isMostlyUpperCase(text)){
  111.                return true;
  112.             }
  113.         }
  114.  
  115.         if(AntiKappa.blockExclusiveUpperCaseBool){
  116.             if(text === text.toUpperCase()){
  117.                 return true;
  118.             }            
  119.         }        
  120.  
  121.         if(AntiKappa.blockRepeatedWordInSentenceBool && AntiKappa.isRepeatedWordInSentence(text)){
  122.             return true;
  123.         }
  124.  
  125.         if(AntiKappa.blockTypicalSpamBool){
  126.             for (var i = 0; i < AntiKappa.typicalSpamStringArray.length - 1; i++) {
  127.                 var entry = AntiKappa.typicalSpamStringArray[i].toUpperCase();
  128.                 var compare = text.toUpperCase();
  129.                 if(compare.indexOf(entry) > -1){
  130.                     return true;
  131.                 }
  132.             }
  133.         }
  134.  
  135.         if(AntiKappa.r9kModeBool){
  136.             if(AntiKappa.messageArray.indexOf(text) > -1){
  137.                 return true;
  138.             }                
  139.         }                
  140.  
  141.         if(AntiKappa.blockNonEnglishCharactersBool){
  142.             if(AntiKappa.isNonEnglishCharacter(text)){
  143.                 return true;
  144.             }                
  145.         }            
  146.  
  147.         return false;
  148.     };
  149.  
  150.     AntiKappa.isRepeatedWordInSentence = function(text){
  151.         var sortedStringArray = text.split(" ").sort();        
  152.         var duplicatesStringArray = [];
  153.         for (var i = 0; i < sortedStringArray.length - 1; i++) {
  154.             if (sortedStringArray[i + 1] == sortedStringArray[i]) {
  155.                 duplicatesStringArray.push(sortedStringArray[i]);
  156.             }
  157.         }
  158.        
  159.         return duplicatesStringArray.length >= AntiKappa.repeatedWordInSentenceCountInt;
  160.     };
  161.    
  162.     AntiKappa.isMostlyUpperCase = function(text){
  163.         var textLength = text.length;
  164.         var amountUpperCaseInt = 0;
  165.         for (var i = 0, len = textLength; i < len; i++) {
  166.             var char = text[i];
  167.             if(char === char.toUpperCase()){
  168.                 amountUpperCaseInt++;
  169.             }
  170.         }
  171.        
  172.         var percentageUpperCase = 100 - (textLength - amountUpperCaseInt) / textLength * 100;
  173.        
  174.         return percentageUpperCase >= AntiKappa.mostlyUpperCaseTheshholdPercentage;
  175.     };
  176.  
  177.     AntiKappa.isNonEnglishCharacter = function(text){
  178.         var regex = /[^\u0000-\u007F]+/;
  179.         return regex.test(text);
  180.     };
  181.  
  182.     AntiKappa.addGlobalStyle = function(css) {
  183.         var head, style;
  184.         head = document.getElementsByTagName('head')[0];
  185.         if (!head) { return; }
  186.         style = document.createElement('style');
  187.         style.type = 'text/css';
  188.         style.innerHTML = css;
  189.         head.appendChild(style);
  190.     };
  191.  
  192.     AntiKappa.addGlobalStyle('.chat-lines div.ember-view { display: none; }');
  193.     AntiKappa.addGlobalStyle('.AntiKappaAccepted { display: inline !important; }');
  194.     AntiKappa.addGlobalStyle('.player-hover { display: block !important; }');
  195.     setInterval(AntiKappa.mainLoop, 200);    
  196.     setInterval(AntiKappa.purgeEntries, 1000 * 60 * 10);
  197. });
Advertisement
Add Comment
Please, Sign In to add comment