Guest User

Untitled

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