Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name polremover
- // @namespace
- // @match https://boards.4chan.org/bant/catalog
- // @grant none
- // @version 1.0
- // @run-at document-idle
- // @author Anonymous
- // @description Hide all threads moved from /pol/ on /bant/.
- // @description Warning: It only works if you use the catalog. Warning: You will get timed out if you refresh the catalog too much.
- // @description Technical: Fetch all Mod posts from /pol/ with 4plebs API. Filter /bant/ of moved /pol/ posts.
- // ==/UserScript==
- let html = document.getElementById("threads");
- let h1 = document.createElement("h1")
- h1.style.textAlign = "center";
- h1.appendChild(document.createTextNode("/pol/bant/"))
- let div = document.createElement("div");
- div.id = "polbant";
- div.style.backgroundColor = "rgba(201, 76, 76, 0.3)"
- let a = document.createElement("a");
- a.text = "Show";
- div.style.display= "none";
- a.addEventListener("click", () => {
- if (a.text == "Show") {
- a.text = "Hide"
- div.style.display= "";
- } else {
- a.text = "Show"
- div.style.display= "none";
- }
- })
- html.prepend(div);
- html.prepend(h1);
- html.prepend(a);
- let moved_threads = []
- for (var i=0; i<5; i++){
- fetch('https://archive.4plebs.org/_/api/chan/search/?boards=pol&capcode=mod&page=' + i)
- .then(response => response.json())
- .then(data => {
- data["0"]["posts"].forEach(post => {
- // Extract id from comment
- const id = post["comment"].split(">>>/bant/")[1];
- if (id === undefined) return;
- const moved_thread = {
- pol_id: post["thread_num"],
- bant_id: id
- };
- moved_threads.push(moved_thread);
- });
- })
- .then(() => {
- console.log(moved_threads);
- for(var i=0; i<moved_threads.length; i++) {
- try {
- let tn = document.getElementById(`thread-${moved_threads[i]["bant_id"]}`);
- let ref = document.createElement("a");
- ref.text = "⏩";
- ref.target="_blank"
- ref.style.position = "absolute";
- ref.style.fontSize = "30px";
- ref.href = `https://archive.4plebs.org/pol/thread/${moved_threads[i]["pol_id"]}`;
- tn.prepend(ref);
- div.appendChild(tn);
- }
- catch {
- console.log(`Failed to append thread-${moved_threads[i]["bant_id"]} to polbant section - Probably thread is deleted from /bant/`)
- }
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement