Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name BritPolNews
- // @namespace britpolnews
- // @description Automatically includes recent relevant news in the OP of Brit/pol/.
- // @include https://boards.4chan.org/pol/thread/*
- // @version 1
- // @grant GM_xmlhttpRequest
- //
- // Save in file with extension ".user.js" then drag the file in to your open browser to install.
- //
- // ==/UserScript==
- // Ensure it only runs once.
- if (window.top != window.self)
- return;
- var visible = false;
- var bits;
- GM_xmlhttpRequest({
- method: "GET",
- url: "https://farage.neocities.org/",
- onload: function(response) {
- var parser, doc, headlines, links, time, oppost, showhidediv, showhidebutton, spacer;
- // Setup
- parser = new DOMParser();
- doc = parser.parseFromString(response.responseText, "text/html");
- headlines = doc.getElementsByClassName("quote");
- links = doc.getElementsByTagName("a");
- oppost = document.getElementsByClassName("postMessage")[0];
- // Create button
- showhidediv = document.createElement("div");
- showhidediv.style.textAlign = "center";
- showhidediv.style.marginTop = "10px";
- showhidediv.innerHTML = "[<a id='showhide' style='cursor: pointer;'>Show Live Headlines</a>]";
- oppost.appendChild(showhidediv);
- showhidebutton = document.getElementById("showhide");
- // Add event listener
- showhidebutton.addEventListener("click", function() {
- visible = !visible;
- if (visible) {
- this.innerHTML = "Hide Live Headlines";
- for (var i = 0; i < bits.length; i++)
- bits[i].style.display = "inline";
- } else {
- this.innerHTML = "Show Live Headlines";
- for (var i = 0; i < bits.length; i++)
- bits[i].style.display = "none";
- }
- });
- // Add top spacer
- spacer = document.createElement("hr");
- oppost.appendChild(spacer);
- // Create timestamp bit
- time = document.createElement("span");
- time.innerHTML = doc.getElementsByTagName("small")[0].innerHTML;
- time.innerHTML = "Headlines " + time.innerHTML.substring(4, time.innerHTML.length);
- time.style.fontStyle = "italic";
- time.className += " showhidebit";
- // Append bits
- for (var i = 0; i < headlines.length; i++) {
- headlines[i].className += " showhidebit";
- links[i].className += " showhidebit";
- oppost.appendChild(headlines[i]).appendChild(document.createElement("br")).className += " showhidebit";
- oppost.appendChild(links[i]).appendChild(document.createElement("br")).className += " showhidebit";
- oppost.appendChild(document.createElement("br")).className += " showhidebit";
- oppost.appendChild(time);
- }
- // Get all elements with class "showhidebit". Kind of a work-around because I'm shit and JS is for gayers.
- bits = document.getElementsByClassName("showhidebit");
- // Hide all bits by default
- for (var i = 0; i < bits.length; i++)
- bits[i].style.display = "none";
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement