Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("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
- $("b:contains('Guides available:')")[0].innerText = ''; //Remove the default "Guides available" text
- var ChiakiIDSArray = [] //Creates a new blank global array
- var GuideIndexIDS = []; //Creates a new blank global array
- document.querySelector("#CheckForMissingLinksStep1").onclick = function() { //Detects the mouse click on the Step 1 text and starts the function to Check For Missing Links
- 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
- var GuideIndexIDS = []; //Creates a new blank array
- var match; //Creates a new blank variable
- for (match in GuideIndexIDSmatches) //For every anime id existent on the GuideIndexIDSmatches text content
- { //Starts the for condition
- GuideIndexIDS.push(GuideIndexIDSmatches[match].replace(/(?:\|)/gi, '')); //Remove the first | symbol in front of the anime id numbers
- } //Finishes the for condition
- 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
- }; //Finishes the Step 1 onclick function
- document.querySelector("#CheckForMissingLinksStep2").onclick = function() { //Detects the mouse click on the Step 2 text and starts the function to Check For Missing Links
- var ChiakiDocument; //Makes the variable global
- async function GetChiakiIDS() { //Creates a new function
- while (true) { //While the if condition returns true
- var match; //Creates a new blank variable
- var matches = document.querySelector("div.clearfix.word-break").firstChild.innerText.match(/(?:\|\b\d+)/gi); //Get all the anime ids on the MAL page
- for (match in matches) //For all anime ids on the MAL page
- { //Starts the for condition
- 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
- const html = await (await fetch(FetchChiaki)).text(); //Gets the fetch response
- ChiakiDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
- for (const ChiakiAnimeIDS of ChiakiDocument.querySelectorAll('span.uk-text-muted.uk-text-small > a')) { //For every anime entry links existent on the chiaki.site
- ChiakiIDSArray.push(ChiakiAnimeIDS.href.match(/\d+/)[0]); //Get only the anime id of every anime entry links existent on the chiaki.site
- } //Finishes the for condition
- } //Finishes the for condition
- if (ChiakiDocument.body.innerText.search('Watch') > -1) { //If the text Watch was found on the chiaki.site document
- 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
- return; //Return true
- } //Finishes the if condition
- await new Promise(resolve => setTimeout(resolve, 1000)); //Wait 1 sec before fetching chiaki.site again
- } //Finishes the while condition
- } //Finishes the async GetChiakiIDS function
- GetChiakiIDS(); //Starts the async GetChiakiIDS function
- }; //Finishes the Step 2 onclick function
- document.querySelector("#CheckForMissingLinksStep3").onclick = function() { //Detects the mouse click on the Step 3 text and starts the function to Check For Missing Links
- var FinalArray = ChiakiIDSArray.filter(d => !GuideIndexIDS.includes(d)); //Get the ids that chiaki.site has and the Guide is missing
- var GuideMissingIds = document.createElement("div"); //Creates a div element
- /*FinalArray.forEach(function(AnimeID) { //For every anime id that the guide index is missing
- GuideMissingIds.innerHTML += GuideMissingIds.innerHTML = '
- 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
- }); //Finishes the foreach condition
- */
- alert(FinalArray.length) //Should be equal 3 ["16", "644", "1142"]
- document.querySelector("#CheckForMissingLinksStep3").appendChild(GuideMissingIds); //Show the links that the Tampermonkey Guide Index is missing
- }; //Finishes the Step 3 onclick function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement