Facebook
From Lee, 2 Weeks ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 182
  1. // ==UserScript==
  2. // @name 4chan GETter
  3. // @description Script to help you get repeating digits. Loosely based on mGET. Requires 4chan X.
  4. // @author Xyl
  5. // @match *://*.4chan.org/*
  6. // @match *://*.4channel.org/*
  7. // @grant GM_xmlhttpRequest
  8. // @connect sys.4chan.org
  9. // @version 1.2.1
  10. // @namespace https://xyllon.com
  11. // ==/UserScript==
  12.  
  13. let latestPostNumber = -1;
  14. const board = location.pathname.match(/\/[^\/]+\//)[0];
  15. let games = (board == "/v/" || board == "/vg/" || board == "/vr/");
  16.  
  17. if (document.getElementById("qr")) inject();
  18. document.addEventListener('QRDialogCreation', (e) => inject());
  19.  
  20. function inject() {
  21.     let dubs = (games) ? "" : "<option value=\"dubs\">Dubs</option>";
  22.     document.querySelector('#qr .move').insertAdjacentHTML("afterend", `
  23.     <div class="getscript"  5px; padding-left: 5px;">Last Post #<span id="postnumber"  hidden"></span>
  24.     <div  right; margin-right: 15px;">
  25.     &lt;input type="number" name="offset" value="1"  -3px; width: 5ch; height: 16px; padding: 0px !important; -moz-appearance:textfield;" id="offset" title="When to post (a value of 1 with a target post of 99 will post at 98, a value of 2 will post at 97, etc.)"&gt;
  26.     <select data-name="digits" id="digits" title="Select the numbers you want">
  27.     <option value="none">Select GET</option>` + dubs + `
  28.     <option value="trips">Trips</option>
  29.     <option value="quads">Quads</option>
  30.     <option value="quints">Quints</option>
  31.     <option value="sexts">Sexts</option>
  32.     <option value="septs">Septs</option>
  33.     <option value="octs">Octs</option>
  34.     <option value="nons">Nons</option>
  35.     <option value="decs">Decs</option>
  36.     </select></div></div>`);
  37.     approxLatestPostNumber();
  38. }
  39.  
  40. function checkForGET () {
  41.     window.target = latestPostNumber + parseInt(document.getElementById('offset').value);
  42.     switch(document.getElementById("digits").value) {
  43.         case "":
  44.             break;
  45.         case "dubs":
  46.             return /(\d)\1{1,}$/.test(target);
  47.             break;
  48.         case "trips":
  49.             return /(\d)\1{2,}$/.test(target);
  50.             break;
  51.         case "quads":
  52.             return /(\d)\1{3,}$/.test(target);
  53.             break;
  54.         case "quints":
  55.             return /(\d)\1{4,}$/.test(target);
  56.             break;
  57.         case "sexts":
  58.             return /(\d)\1{5,}$/.test(target);
  59.             break;
  60.         case "septs":
  61.             return /(\d)\1{6,}$/.test(target);
  62.             break;
  63.         case "octs":
  64.             return /(\d)\1{7,}$/.test(target);
  65.             break;
  66.         case "nons":
  67.             return /(\d)\1{8,}$/.test(target);
  68.             break;
  69.         case "decs":
  70.             return /(\d)\1{9,}$/.test(target);
  71.             break;
  72.     }
  73. }
  74.  
  75. function approxLatestPostNumber() {
  76.     fetch("https://a.4cdn.org" + board + "1.json").then(response => response.json()).then(json => {
  77.         let threadFound = false;
  78.         let thread = 0;
  79.         while (!threadFound) {
  80.             if (json.threads[thread].posts[0].closed == 1 || json.threads[thread].posts[0].sticky == 1) thread++;
  81.             else threadFound = true;
  82.         }
  83.         latestPostNumber = json.threads[thread].posts.slice(-1)[0].no;
  84.         document.getElementById("postnumber").textContent = latestPostNumber;
  85. updatePostNumber();
  86.     });
  87. }
  88.  
  89. function updatePostNumber() {
  90.     GM_xmlhttpRequest({
  91.         url: ("https://sys.4chan.org" + board + "imgboard.php?res=" + (latestPostNumber + 1)),
  92.         method: "HEAD",
  93.         onload: response => {
  94. if (response.status == 200) {
  95. latestPostNumber++;
  96. } else if (games && /(([1-9])\2|[^0]0{2,2})$/.test(latestPostNumber + 1)) {
  97. if (/[^9]99$/.test(latestPostNumber + 1)) latestPostNumber += 2;
  98. else latestPostNumber++;
  99. }
  100. if (checkForGET()) {
  101. document.querySelector("#file-n-submit input:last-child").click();
  102. document.getElementById("digits").value = "none";
  103. }
  104. document.getElementById("postnumber").style.visibility = "visible";
  105. document.getElementById("postnumber").textContent = latestPostNumber;
  106. updatePostNumber();
  107.         }
  108.     });
  109. }