Advertisement
Guest User

Untitled

a guest
Feb 5th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.       $("b:contains('Guides available:')")[0].insertAdjacentHTML('afterEnd', '<div style="cursor: pointer;"><b>Guides available:</b><br><b id="CheckForMissingLinksStep1"> Step 1: Click here to check for anime entries that the tampermonkey guide index is missing</b><br><b id="CheckForMissingLinksStep2">Step 2: Click here</b><br><b id="CheckForMissingLinksStep3">Step 3: Click here</b>'); //Add 3 clickable texts below the Tampermonkey Guide Index "Guides available" text
  2.  
  3.       $("b:contains('Guides available:')")[0].innerText = ''; //Remove the default "Guides available" text
  4.  
  5.       var ChiakiIDSArray = [] //Creates a new blank global array
  6.       var GuideIndexIDS = []; //Creates a new blank global array
  7.  
  8.       document.querySelector("#CheckForMissingLinksStep1").onclick = function() { //Detects the mouse click on the Step 1 text and starts the function to Check For Missing Links
  9.  
  10.         var GuideIndexIDSmatches = document.querySelector("div.clearfix.word-break").firstChild.innerText.match(/(?:\|\b\d+)/gi); //Creates a new variable to hold the whole text of the first post on the topic
  11.         var GuideIndexIDS = []; //Creates a new blank array
  12.         var match; //Creates a new blank variable
  13.         for (match in GuideIndexIDSmatches) //For every anime id existent on the GuideIndexIDSmatches text content
  14.         { //Starts the for condition
  15.           GuideIndexIDS.push(GuideIndexIDSmatches[match].replace(/(?:\|)/gi, '')); //Remove the first | symbol in front of the anime id numbers
  16.         } //Finishes the for condition
  17.         document.querySelector("#CheckForMissingLinksStep1").innerText = document.querySelector("#CheckForMissingLinksStep1").innerText + '  Done!\nPlease Click on the Step 2 Now.'; //Add a text to the end of the Step 1 text when the process is finished
  18.       }; //Finishes the Step 1 onclick function
  19.  
  20.       document.querySelector("#CheckForMissingLinksStep2").onclick = function() { //Detects the mouse click on the Step 2 text and starts the function to Check For Missing Links
  21.  
  22.         var ChiakiDocument; //Makes the variable global
  23.         async function GetChiakiIDS() { //Creates a new function
  24.           while (true) { //While the if condition returns true
  25.             var match; //Creates a new blank variable
  26.             var matches = document.querySelector("div.clearfix.word-break").firstChild.innerText.match(/(?:\|\b\d+)/gi); //Get all the anime ids on the MAL page
  27.             for (match in matches) //For all anime ids on the MAL page
  28.             { //Starts the for condition
  29.               var FetchChiaki = matches[match].replace(/(?:\|)/gi, ' https://api.allorigins.win/raw?url=https://chiaki.site/?/tools/watch_order/id/'); //Creates a variable to fetch chiaki.site
  30.               const html = await (await fetch(FetchChiaki)).text(); //Gets the fetch response
  31.               ChiakiDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
  32.  
  33.               for (const ChiakiAnimeIDS of ChiakiDocument.querySelectorAll('span.uk-text-muted.uk-text-small > a')) { //For every anime entry links existent on the chiaki.site
  34.                 ChiakiIDSArray.push(ChiakiAnimeIDS.href.match(/\d+/)[0]); //Get only the anime id of every anime entry links existent on the chiaki.site
  35.               } //Finishes the for condition
  36.             } //Finishes the for condition
  37.             if (ChiakiDocument.body.innerText.search('Watch') > -1) { //If the text Watch was found on the chiaki.site document
  38.                document.querySelector("#CheckForMissingLinksStep2").innerText = document.querySelector("#CheckForMissingLinksStep2").innerText + '  Done!\nPlease Click on the Step 3 Now.'; //Add a text to the end of the Step 1 text when the process is finished
  39.               return; //Return true
  40.             } //Finishes the if condition
  41.             await new Promise(resolve => setTimeout(resolve, 1000)); //Wait 1 sec before fetching chiaki.site again
  42.           } //Finishes the while condition
  43.         } //Finishes the async GetChiakiIDS function
  44.         GetChiakiIDS(); //Starts the async GetChiakiIDS function
  45.       }; //Finishes the Step 2 onclick function
  46.  
  47.       document.querySelector("#CheckForMissingLinksStep3").onclick = function() { //Detects the mouse click on the Step 3 text and starts the function to Check For Missing Links
  48.  
  49.         var FinalArray = ChiakiIDSArray.filter(d => !GuideIndexIDS.includes(d)); //Get the ids that chiaki.site has and the Guide is missing
  50.         var GuideMissingIds = document.createElement("div"); //Creates a div element
  51.         /*FinalArray.forEach(function(AnimeID) { //For every anime id that the guide index is missing
  52.           GuideMissingIds.innerHTML += GuideMissingIds.innerHTML = '
  53. https://myanimelist.net/anime/${AnimeID}` + '">' + `https://myanimelist.net/anime/${AnimeID}` + ''; //Add to the GuideMissingIds div a line break + the anime link with the link as text too
  54.         }); //Finishes the foreach condition
  55.       */
  56. alert(FinalArray.length) //Should be equal 3 ["16", "644", "1142"]
  57.         document.querySelector("#CheckForMissingLinksStep3").appendChild(GuideMissingIds); //Show the links that the Tampermonkey Guide Index is missing
  58.       }; //Finishes the Step 3 onclick function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement