Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Barfly Tools
- // @namespace DriveByScripting
- // @description Moon of Alabama poster blocking, various fixes.
- // @include https://www.moonofalabama.org/*
- // @version 2
- // @grant none
- // @run-at document-idle
- // ==/UserScript==
- // Reminder: Copy the contents of the textbox at the bottom of the page to back up the blocklist.
- // The blocklist is wiped when browser cache/browsing history/site preferences is cleared.
- // SETTINGS
- // Show poster name before comment text
- // (Disabled by default. Set to true to enable.)
- var PosterNameFirst = true;
- // Force wrapping of page-breaking long links.
- var BadLinkFix = true;
- // Hide bad posters (Enabled by default. Set to false to show posts.)
- // Post is highlighted with the specifed color.
- var HideBadPosts = true;
- var BadPostColor = 'pink';
- // ---CODE STARTS HERE---
- head = document.getElementsByTagName('head')[0];
- if (head)
- {
- style = document.createElement('style');
- style.type = 'text/css';
- style.innerHTML = '.badpost { background-color: '+BadPostColor+'; }';
- if (HideBadPosts)
- style.innerHTML += ' .badpost > *:not(.posted) { display: none; }';
- if (PosterNameFirst)
- style.innerHTML += ' .comments-body { position: relative; padding-top: 2.5em; } .comments-body .posted { position: absolute; top: 0px; }';
- if (BadLinkFix)
- style.innerHTML += ' #comment-preview-content p a, .comments-body a { display: inline-block; word-break: break-all; }';
- head.appendChild(style);
- }
- window.blockList = JSON.parse(localStorage.getItem("blockList"));
- if (window.blockList === null)
- window.blockList = new Array();
- else
- document.body.innerHTML += '<p>Poster Blocklist:<br><textarea>'+JSON.stringify(window.blockList)+'</textarea></p>';
- document.body.innerHTML += '<p><input type="button" value="Import Blocklist" onclick="var badImport = prompt(\'Paste exported text here:\'); if(badImport) if (Array.isArray(JSON.parse(badImport))) { localStorage.setItem(\'blockList\', badImport); window.location.reload(); } else alert(\'Error importing blocklist.\')"><input type="button" value="Clear Blocklist" onclick="if (confirm(\'Really clear blocklist?\')) { localStorage.removeItem(\'blockList\'); alert(\'Done.\'); }"></p>';
- var c = document.body.getElementsByClassName('posted');
- for (i=1;i<c.length;i++)
- {
- if (c[i].parentNode.className.indexOf('comments-body') != -1)
- {
- var poster = c[i].textContent.match(/Posted by: ([^|]+) |/);
- if (poster)
- {
- poster = poster[1];
- if (window.blockList.includes(poster))
- {
- c[i].innerHTML += ' <input type="button" value="Unblock" onClick="window.blockList=JSON.parse(localStorage.getItem(\'blockList\')); window.blockList===null? window.blockList=newArray:window.blockList=window.blockList; window.blockList = window.blockList.filter(item => item !== \''+poster+'\'); localStorage.setItem(\'blockList\', JSON.stringify(window.blockList)); window.location.reload();">';
- c[i].parentNode.classList.add('badpost');
- }
- else
- {
- c[i].innerHTML += ' <input type="button" value="Block" onClick="window.blockList=JSON.parse(localStorage.getItem(\'blockList\')); window.blockList===null? window.blockList=new Array():window.blockList=window.blockList; window.blockList.push(\''+poster+'\'); localStorage.setItem(\'blockList\', JSON.stringify(window.blockList)); window.location.reload();">';
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement