Guest User

Untitled

a guest
Apr 2nd, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Robin chat enhancement script
  3. // @namespace    https://www.reddit.com/
  4. // @version      0.6
  5. // @description  Highlight @you messages, hide spam & auto link links
  6. // @author       mr_bag
  7. // @match        https://www.reddit.com/robin/
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.  
  13.     // for highlighting messages mentioning the current user
  14.     var robin_user = $("#header-bottom-right .user a").first().text();
  15.  
  16.     // Handle each line
  17.     var parse_line = function($ele){
  18.         var $msg = $ele.find(".robin-message--message");
  19.         var line = $msg.text().toLowerCase();
  20.  
  21.         // Spam filter
  22.         if (
  23.             // Hide auto vote messages
  24.             (/^voted to (grow|stay|abandon)/.test(line)) ||
  25.             // Unicode?
  26.             (/[\u0080-\uFFFF]/.test(line)) ||
  27.             // hide any auto voter messages
  28.             (/\[.*autovoter.*\]/.test(line)) ||
  29.             // repeating chars in line (more than 6). e.g. aaaaaaa !!!!!!!!
  30.             (/(.)\1{6,}/.test(line)) ||
  31.             // Some common messages
  32.             (/voting will end in approximately/.test(line)) ||
  33.             // no spaces = spam if its longer than 25 chars (dont filter links)
  34.             (line.indexOf(" ") === -1 && line.length > 25 && line.indexOf("http") === -1) ||
  35.             // repeating same word
  36.             /(\b\S+\b)\s+\b\1\b/i.test(line)
  37.         ) {
  38.             $ele.css("opacity","0.3").css("font-size", "1.2em");
  39.         }
  40.  
  41.         // Highlight mentions
  42.         if(line.indexOf(robin_user) !== -1){
  43.             $ele.css("font-weight", "bold");
  44.         }
  45.  
  46.         // Auto link links
  47.         if(line.indexOf("http") !== -1){
  48.             var text = $msg.html(); // with caps etc (read as html so stuff stays escaped)
  49.             // normal links
  50.             text = text.replace(/\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim, '<a target="blank" href="$&">$&</a>');
  51.             // reddit subreddit links
  52.             text = text.replace(/ \/r\/(\w+)/gim, ' <a target="blank" href="https://reddit.com/r/$1">/r/$1</a>');
  53.             // update text
  54.             $msg.html(text);
  55.         }
  56.     };
  57.  
  58.     // Detect changes, are parse the new message
  59.     $("#robinChatWindow").on('DOMNodeInserted', function(e) {
  60.         if ($(e.target).is('div.robin-message')) {
  61.             parse_line($(e.target));
  62.         }
  63.     });
  64.  
  65.     // stop stacking unicode chars escaping the original message
  66.     document.styleSheets[0].insertRule(".robin-message--message {overflow:hidden;}", 0);
  67. })();
Add Comment
Please, Sign In to add comment