Advertisement
Guest User

polbanter

a guest
Jul 5th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. // ==UserScript==
  2. // @name polremover
  3. // @namespace
  4. // @match https://boards.4chan.org/bant/catalog
  5. // @grant none
  6. // @version 1.0
  7. // @run-at document-idle
  8. // @author Anonymous
  9. // @description Hide all threads moved from /pol/ on /bant/.
  10. // @description Warning: It only works if you use the catalog. Warning: You will get timed out if you refresh the catalog too much.
  11. // @description Technical: Fetch all Mod posts from /pol/ with 4plebs API. Filter /bant/ of moved /pol/ posts.
  12. // ==/UserScript==
  13.  
  14.  
  15. let html = document.getElementById("threads");
  16.  
  17. let h1 = document.createElement("h1")
  18. h1.style.textAlign = "center";
  19. h1.appendChild(document.createTextNode("/pol/bant/"))
  20.  
  21. let div = document.createElement("div");
  22. div.id = "polbant";
  23. div.style.backgroundColor = "rgba(201, 76, 76, 0.3)"
  24.  
  25. let a = document.createElement("a");
  26. a.text = "Show";
  27. div.style.display= "none";
  28.  
  29. a.addEventListener("click", () => {
  30. if (a.text == "Show") {
  31. a.text = "Hide"
  32. div.style.display= "";
  33. } else {
  34. a.text = "Show"
  35. div.style.display= "none";
  36. }
  37. })
  38.  
  39. html.prepend(div);
  40. html.prepend(h1);
  41. html.prepend(a);
  42.  
  43. let moved_threads = []
  44. for (var i=0; i<5; i++){
  45. fetch('https://archive.4plebs.org/_/api/chan/search/?boards=pol&capcode=mod&page=' + i)
  46. .then(response => response.json())
  47. .then(data => {
  48. data["0"]["posts"].forEach(post => {
  49. // Extract id from comment
  50. const id = post["comment"].split(">>>/bant/")[1];
  51. if (id === undefined) return;
  52. const moved_thread = {
  53. pol_id: post["thread_num"],
  54. bant_id: id
  55. };
  56. moved_threads.push(moved_thread);
  57. });
  58. })
  59. .then(() => {
  60. console.log(moved_threads);
  61. for(var i=0; i<moved_threads.length; i++) {
  62. try {
  63. let tn = document.getElementById(`thread-${moved_threads[i]["bant_id"]}`);
  64. let ref = document.createElement("a");
  65. ref.text = "⏩";
  66. ref.target="_blank"
  67. ref.style.position = "absolute";
  68. ref.style.fontSize = "30px";
  69. ref.href = `https://archive.4plebs.org/pol/thread/${moved_threads[i]["pol_id"]}`;
  70. tn.prepend(ref);
  71. div.appendChild(tn);
  72. }
  73. catch {
  74. console.log(`Failed to append thread-${moved_threads[i]["bant_id"]} to polbant section - Probably thread is deleted from /bant/`)
  75. }
  76. }
  77. })
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement