Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name /b/ 404 suite
- // @author team!kittensORw
- // @namespace 2-hi.me
- // @description Detects 4chan 404s (even API-silent ones), stitches 404'd thread onto new thread.
- // @include http*://*4chan.org/b/res/*
- // @version 1
- // ==/UserScript==
- //Gets query strings from the URL
- function getUrlVars() {
- var vars = {};
- var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
- vars[key] = value;});
- return vars;}
- //gets the old thread ID from the query string, if any
- var oldhorse = getUrlVars()["oldt"];
- //Works out the board and the thread ID. we don't use the board yet, so far /b/ only.
- var boardS = window.location.pathname.split( '/res/' );
- var board1 = boardS[0].split( '/' );
- var board2 = boardS[1].split( '.' );
- var board = board1[1];
- var thread = board2[0];
- //Makes the 404 alert, with the textbox and such.
- var deadWin = document.createElement("div");
- deadWin.id = "deadWin";
- deadWin.setAttribute("align", "left");
- deadWin.style.top = "50px";
- deadWin.style.title = "close";
- deadWin.style.width = "200px";
- deadWin.style.left = "50%";
- deadWin.style.marginLeft = "-100px";
- deadWin.style.position = "fixed";
- deadWin.style.border = "1px solid";
- deadWin.style.borderRadius = "15px";
- deadWin.style.opacity = "0.6";
- deadWin.style.display = "none";
- deadWin.style.background = "#980000";
- deadWin.innerHTML = '<div id="clsNt" style="position:relative;top:5px;right:-5px;color:#ffffff;cursor:pointer;width:10px;"><b>X</b></div><center><h1 style="color:#ffffff">404</h1><input name="newtr" id="newtr" placeholder="new thread no."><input id="gostitch" type="submit" value="go"><br><br></center>';
- document.body.appendChild(deadWin);
- //Starts the 404 scan
- var timerVar=setInterval(function(){checkTimer()},20000);
- function checkTimer(){
- GM_xmlhttpRequest({
- method: "GET",
- url: document.URL,
- onload: function(response) {
- //What happens when it finds 404
- if (response.status == 404){
- deadWin.style.display = "";
- clearInterval(timerVar);
- //Starts the batte with 4chan X for the right to set the page title. It sets every 5 secs.
- var xbattleVar=setInterval(function(){battleX()},5000);
- function battleX(){
- document.title = "404 :c";
- }}}});}
- //hides the window when you click the x
- function hideLisn(){
- deadWin.style.display = "none";}
- document.getElementById("clsNt").addEventListener('click',hideLisn,false);
- //What happens when you give it the new thread to load, starts all the stitching and stuff
- var ntrgo = document.getElementById('gostitch');
- ntrgo.addEventListener("click", function() {var ntrinp = document.getElementById('t' + thread).innerHTML; GM_setValue("old" + thread, ntrinp); window.location.href = 'http://boards.4chan.org/b/res/' + document.getElementById("newtr").value + '?oldt=' + thread;});
- //What to do if it finds and old thread requester in the URL query strings
- if (oldhorse){
- //Makes it safe to click quotes in the old thread
- var regexOld1 = new RegExp(oldhorse + "#p", "g");
- var inOldhorse = GM_getValue("old" + oldhorse).replace(regexOld1,"#p");
- //works out where to stitch the thread on the new page, make the target div
- var stitchneT1 = document.getElementById('t' + thread);
- var stitcholT1 = document.createElement("div");
- stitcholT1.id = "t" + oldhorse;
- //gives the old thread the thread class. makes some stuff work, breaks some other stuff. i don't like it, so it's commented.
- //stitcholT1.className = "thread";
- //Stitches in the old thread
- stitchneT1.parentNode.insertBefore(stitcholT1, stitchneT1);
- stitcholT1.innerHTML += inOldhorse;
- //and clears the saved old thread to preven loads of permenantly stored dead threads.
- GM_deleteValue("old" + oldhorse);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement