Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Robin chat enhancement script
- // @namespace https://www.reddit.com/
- // @version 0.7
- // @description Highlight @you messages, hide spam & auto link links
- // @author mr_bag
- // @match https://www.reddit.com/robin/
- // @grant none
- // ==/UserScript==
- (function() {
- // for highlighting messages mentioning the current user
- var robin_user = $("#header-bottom-right .user a").first().text();
- // Handle each line
- var parse_line = function($ele){
- var $msg = $ele.find(".robin-message--message");
- var line = $msg.text().toLowerCase();
- // Spam filter
- if (
- // Hide auto vote messages
- (/^voted to (grow|stay|abandon)/.test(line)) ||
- // Unicode?
- (/[\u0080-\uFFFF]/.test(line)) ||
- // hide any auto voter messages
- (/\[.*autovoter.*\]/.test(line)) ||
- // repeating chars in line (more than 6). e.g. aaaaaaa !!!!!!!!
- (/(.)\1{6,}/.test(line)) ||
- // Some common messages
- (/(voting will end in approximately|\[robin-grow\]|\[i spam the most used phrase\])/.test(line)) ||
- // no spaces = spam if its longer than 25 chars (dont filter links)
- (line.indexOf(" ") === -1 && line.length > 25 && line.indexOf("http") === -1) ||
- // repeating same word
- /(\b\S+\b)\s+\b\1\b/i.test(line)
- ) {
- $ele.css("opacity","0.3").css("font-size", "1.2em");
- }
- // Highlight mentions
- if(line.indexOf(robin_user) !== -1){
- $ele.css("font-weight", "bold");
- }
- // Auto link links
- if(line.indexOf("http") !== -1){
- var text = $msg.html(); // with caps etc (read as html so stuff stays escaped)
- // normal links
- text = text.replace(/\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim, '<a target="blank" href="$&">$&</a>');
- // reddit subreddit links
- text = text.replace(/ \/r\/(\w+)/gim, ' <a target="blank" href="https://reddit.com/r/$1">/r/$1</a>');
- // update text
- $msg.html(text);
- }
- };
- // Detect changes, are parse the new message
- $("#robinChatWindow").on('DOMNodeInserted', function(e) {
- if ($(e.target).is('div.robin-message')) {
- parse_line($(e.target));
- }
- });
- // stop stacking unicode chars escaping the original message
- document.styleSheets[0].insertRule(".robin-message--message {overflow:hidden;}", 0);
- })();
Add Comment
Please, Sign In to add comment