Advertisement
David_F

MOA Block User Script

Apr 17th, 2020
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Barfly Tools
  3. // @namespace DriveByScripting
  4. // @description Moon of Alabama poster blocking, various fixes.
  5. // @include https://www.moonofalabama.org/*
  6. // @version 2
  7. // @grant none
  8. // @run-at document-idle
  9. // ==/UserScript==
  10.  
  11. // Reminder: Copy the contents of the textbox at the bottom of the page to back up the blocklist.
  12. // The blocklist is wiped when browser cache/browsing history/site preferences is cleared.
  13.  
  14. // SETTINGS
  15.  
  16. // Show poster name before comment text
  17. // (Disabled by default. Set to true to enable.)
  18. var PosterNameFirst = true;
  19.  
  20. // Force wrapping of page-breaking long links.
  21. var BadLinkFix = true;
  22.  
  23. // Hide bad posters (Enabled by default. Set to false to show posts.)
  24. // Post is highlighted with the specifed color.
  25. var HideBadPosts = true;
  26. var BadPostColor = 'pink';
  27.  
  28.  
  29.  
  30. // ---CODE STARTS HERE---
  31.  
  32. head = document.getElementsByTagName('head')[0];
  33. if (head)
  34. {
  35. style = document.createElement('style');
  36. style.type = 'text/css';
  37. style.innerHTML = '.badpost { background-color: '+BadPostColor+'; }';
  38. if (HideBadPosts)
  39. style.innerHTML += ' .badpost > *:not(.posted) { display: none; }';
  40. if (PosterNameFirst)
  41. style.innerHTML += ' .comments-body { position: relative; padding-top: 2.5em; } .comments-body .posted { position: absolute; top: 0px; }';
  42. if (BadLinkFix)
  43. style.innerHTML += ' #comment-preview-content p a, .comments-body a { display: inline-block; word-break: break-all; }';
  44. head.appendChild(style);
  45. }
  46.  
  47.  
  48. window.blockList = JSON.parse(localStorage.getItem("blockList"));
  49. if (window.blockList === null)
  50. window.blockList = new Array();
  51. else
  52. document.body.innerHTML += '<p>Poster Blocklist:<br><textarea>'+JSON.stringify(window.blockList)+'</textarea></p>';
  53. 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>';
  54.  
  55. var c = document.body.getElementsByClassName('posted');
  56. for (i=1;i<c.length;i++)
  57. {
  58. if (c[i].parentNode.className.indexOf('comments-body') != -1)
  59. {
  60. var poster = c[i].textContent.match(/Posted by: ([^|]+) |/);
  61. if (poster)
  62. {
  63. poster = poster[1];
  64. if (window.blockList.includes(poster))
  65. {
  66. 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();">';
  67. c[i].parentNode.classList.add('badpost');
  68. }
  69. else
  70. {
  71. 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();">';
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement