Who Defriended ME!? - MAL

Now you can easily and quickly know who DeFriended you on MAL!

Asenna tämä skripti?
Author's suggested script

Saatat myös pitää

Asenna tämä skripti
  1. // ==UserScript==
  2. // @name Who Defriended ME!? - MAL
  3. // @namespace MALDeFriendStalker
  4. // @version 10
  5. // @description Now you can easily and quickly know who DeFriended you on MAL!
  6. // @author hacker09
  7. // @include https://myanimelist.net/profile/*/friends
  8. // @include https://myanimelist.net/myfriends.php?go=remove&id=*
  9. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
  10. // @grant GM_deleteValue
  11. // @grant GM_listValues
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @run-at document-end
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. if (location.href.match('https://myanimelist.net/profile/' + document.querySelector("a.header-profile-link").innerText + '/friends')) //Make the script work only on the script user friend list
  20. { //Starts the if condition
  21. var nextpagenum = 0; //Creates a new variable
  22. const increaseby = 1; //Creates a new variable
  23. var PastFriends = []; //Creates a new global array
  24. var ActualFriendsArray = []; //Creates a new global array
  25.  
  26. const WhoDeFriendedMEBTN = document.createElement("a"); //Creates a button element
  27. WhoDeFriendedMEBTN.innerHTML = "Check Who DeFriended ME!"; //Adds a text to the button
  28. WhoDeFriendedMEBTN.setAttribute("id", "WhoDeFriendedMEBTN"); //Set an id to the button
  29. WhoDeFriendedMEBTN.setAttribute("style", "cursor: pointer;margin-left: 15px;font-size: 10px;"); //Set the button css style
  30. document.querySelector("a.header-right.mt4.mr0").parentElement.appendChild(WhoDeFriendedMEBTN); //Add the button to the page
  31. document.querySelector("#WhoDeFriendedMEBTN").addEventListener("click", GetNewAndActualFriendsAndShowWhoDeFriendedME, false); //Add a click advent listener to the button
  32.  
  33. for (var i = GM_listValues().length; i--;) { //For every single MAL friend saved on tampermonkey
  34. PastFriends.push(GM_listValues()[i]); //Add all Past MAL Friends saved on tampermonkey to an array
  35. } //Finishes the for condition
  36.  
  37. async function GetNewAndActualFriendsAndShowWhoDeFriendedME() { //Creates an async function
  38. while (true) { //While the fetched page constains 100 friends
  39. nextpagenum += increaseby; //Increase the page number
  40. var JsonResponse = await (await fetch('https://api.jikan.moe/v4/users/' + document.querySelector("a.header-profile-link").innerText + '/friends?page=' + nextpagenum)).json(); //Fetches the friend list and the next pages and converts the fetched pages to json
  41.  
  42. for (var i = JsonResponse.data.length; i--;) { //For every single MAL friend
  43. GM_setValue(JsonResponse.data[i].user.username, 'Actual MAL Friend'); //Get and save the actual mal friend and store the username
  44. ActualFriendsArray.push(JsonResponse.data[i].user.username); //Add all Actual MAL Friends to an array
  45. } //Finishes the for loop
  46.  
  47. if (JsonResponse.data.length !== 100) { //If the fetched page doesn't have 100 friends on it
  48. var WhoDefriendedME = PastFriends.filter(d => !ActualFriendsArray.includes(d)); //Creates a variable to get the Past Friend User Names that tampermonkey had and check which Past Friends User Names are currently Missing
  49. if (WhoDefriendedME.length > 0) //If someone defriended you
  50. { //Starts the if condition
  51. alert('You was DeFriended by:\n' + WhoDefriendedME); //Shows who DeFriended you!
  52. for (var j = WhoDefriendedME.length; j--;) { //For every single MAL friend that defriended you and is saved on tampermonkey
  53. GM_deleteValue(WhoDefriendedME[j]); //Remove the defriended user name of the script storage
  54. } //Finishes the for loop
  55. } //Finishes the if condition
  56. else //If nobody defriended you
  57. { //Starts the else condition
  58. alert('Your current Friends list was updated and saved!\n Nobody Has DeFriended you!'); //Shows a message
  59. } //Finishes the else condition
  60. return;
  61. } //Finishes the if condition
  62. await new Promise(resolve => setTimeout(resolve, 600)); //Timeout to start the next fetch request
  63. } //Finishes the while condition
  64. } //Finishes the async function
  65. } //Finishes the if condition
  66. else //If the user is defriending a friend on https://myanimelist.net/myfriends.php?go=remove&id=
  67. { //Starts the else condition
  68. document.querySelector("input.inputButton").onclick = function() { //Detects the mouse click on the 'Remove Friend' button
  69. GM_deleteValue(document.querySelector("td.dialog-text > strong").innerText); //Remove the defriended user name of the script storage
  70. }; //Finishes the onclick advent listener
  71. } //Finishes the else condition
  72. })();