Guest User

Robin chat enhancement script

a guest
Apr 2nd, 2016
247
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.5
  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 10 chars
  34.             (line.indexOf(" ") === -1 && line.length > 10)
  35.         ) {
  36.             $ele.css("opacity","0.3");
  37.         }
  38.  
  39.         // Highlight mentions
  40.         if(line.indexOf(robin_user) !== -1){
  41.             $ele.css("font-weight", "bold");
  42.         }
  43.  
  44.         // Auto link links
  45.         if(line.indexOf("http") !== -1){
  46.             var text = $msg.html(); // with caps etc (read as html so stuff stays escaped)
  47.             // normal links
  48.             text = text.replace(/\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim, '<a target="blank" href="$&">$&</a>');
  49.             // reddit subreddit links
  50.             text = text.replace(/ \/r\/(\w+)/gim, ' <a target="blank" href="https://reddit.com/r/$1">/r/$1</a>');
  51.             // update text
  52.             $msg.html(text);
  53.         }
  54.     };
  55.  
  56.     // Detect changes, are parse the new message
  57.     $("#robinChatWindow").on('DOMNodeInserted', function(e) {
  58.         if ($(e.target).is('div.robin-message')) {
  59.             parse_line($(e.target));
  60.         }
  61.     });
  62.  
  63.     // stop stacking unicode chars escaping the original message
  64.     document.styleSheets[0].insertRule(".robin-message--message {overflow:hidden;}", 0);
  65. })();
Add Comment
Please, Sign In to add comment