Advertisement
Kinu-chan

Untitled

Jul 21st, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. // ==UserScript==
  2. // @name /b/ 404 suite
  3. // @author team!kittensORw
  4. // @namespace 2-hi.me
  5. // @description Detects 4chan 404s (even API-silent ones), stitches 404'd thread onto new thread.
  6. // @include http*://*4chan.org/b/res/*
  7. // @version 1
  8. // ==/UserScript==
  9.  
  10. //Gets query strings from the URL
  11. function getUrlVars() {
  12. var vars = {};
  13. var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  14. vars[key] = value;});
  15. return vars;}
  16. //gets the old thread ID from the query string, if any
  17. var oldhorse = getUrlVars()["oldt"];
  18. //Works out the board and the thread ID. we don't use the board yet, so far /b/ only.
  19. var boardS = window.location.pathname.split( '/res/' );
  20. var board1 = boardS[0].split( '/' );
  21. var board2 = boardS[1].split( '.' );
  22. var board = board1[1];
  23. var thread = board2[0];
  24. //Makes the 404 alert, with the textbox and such.
  25. var deadWin = document.createElement("div");
  26. deadWin.id = "deadWin";
  27. deadWin.setAttribute("align", "left");
  28. deadWin.style.top = "50px";
  29. deadWin.style.title = "close";
  30. deadWin.style.width = "200px";
  31. deadWin.style.left = "50%";
  32. deadWin.style.marginLeft = "-100px";
  33. deadWin.style.position = "fixed";
  34. deadWin.style.border = "1px solid";
  35. deadWin.style.borderRadius = "15px";
  36. deadWin.style.opacity = "0.6";
  37. deadWin.style.display = "none";
  38. deadWin.style.background = "#980000";
  39. 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>';
  40. document.body.appendChild(deadWin);
  41. //Starts the 404 scan
  42. var timerVar=setInterval(function(){checkTimer()},20000);
  43. function checkTimer(){
  44. GM_xmlhttpRequest({
  45. method: "GET",
  46. url: document.URL,
  47. onload: function(response) {
  48. //What happens when it finds 404
  49. if (response.status == 404){
  50. deadWin.style.display = "";
  51. clearInterval(timerVar);
  52. //Starts the batte with 4chan X for the right to set the page title. It sets every 5 secs.
  53. var xbattleVar=setInterval(function(){battleX()},5000);
  54. function battleX(){
  55. document.title = "404 :c";
  56. }}}});}
  57. //hides the window when you click the x
  58. function hideLisn(){
  59. deadWin.style.display = "none";}
  60. document.getElementById("clsNt").addEventListener('click',hideLisn,false);
  61. //What happens when you give it the new thread to load, starts all the stitching and stuff
  62. var ntrgo = document.getElementById('gostitch');
  63. 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;});
  64. //What to do if it finds and old thread requester in the URL query strings
  65. if (oldhorse){
  66. //Makes it safe to click quotes in the old thread
  67. var regexOld1 = new RegExp(oldhorse + "#p", "g");
  68. var inOldhorse = GM_getValue("old" + oldhorse).replace(regexOld1,"#p");
  69. //works out where to stitch the thread on the new page, make the target div
  70. var stitchneT1 = document.getElementById('t' + thread);
  71. var stitcholT1 = document.createElement("div");
  72. stitcholT1.id = "t" + oldhorse;
  73. //gives the old thread the thread class. makes some stuff work, breaks some other stuff. i don't like it, so it's commented.
  74. //stitcholT1.className = "thread";
  75. //Stitches in the old thread
  76. stitchneT1.parentNode.insertBefore(stitcholT1, stitchneT1);
  77. stitcholT1.innerHTML += inOldhorse;
  78. //and clears the saved old thread to preven loads of permenantly stored dead threads.
  79. GM_deleteValue("old" + oldhorse);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement