Redirect_FFXI_In_Wings_Era

Auto Redirect the FFXI Wikia to an in era edit for Wings of the Goddess

  1. // ==UserScript==
  2. // @name Redirect_FFXI_In_Wings_Era
  3. // @author Kyruski
  4. // @version 2021.05.13
  5. // @match https://ffxiclopedia.fandom.com/*
  6. // @description Auto Redirect the FFXI Wikia to an in era edit for Wings of the Goddess
  7. // @run-at document-end
  8. // @namespace https://gf.qytechs.cn/users/771886
  9. // ==/UserScript==
  10. (async function () {
  11. const historyLinkClass = "mw-changeslist-date";
  12. const cutOffDate = new Date(2010, 02, 23);
  13.  
  14. const months = {
  15. 'January': 00,
  16. 'February': 01,
  17. 'March': 02,
  18. 'April': 03,
  19. "May,": 04,
  20. 'June': 05,
  21. 'July': 06,
  22. 'August': 07,
  23. 'September': 08,
  24. 'October': 09,
  25. 'November': 10,
  26. 'December': 11,
  27. }
  28.  
  29. //grabs the DOM for the desired page
  30. const grabDOM = async (url) => {
  31. const response = await fetch(url);
  32. const text = await response.text();
  33. return await new DOMParser().parseFromString(text, 'text/html');
  34. }
  35.  
  36. const currentURL = window.location.href //define current URL
  37. if (!currentURL.includes('oldid=') && !currentURL.includes('action=history') && !currentURL.includes('Main_Page')) { //only run if the current page isn't old, isn't the history page, or the main page
  38. const pageDom = await grabDOM(currentURL + '?offset=&limit=500&action=history') //grab history w/ 500 results
  39. const historyList = pageDom.getElementsByClassName(historyLinkClass); //select the history links
  40. for (let el of historyList) { //for each link
  41. let pageDate = el.innerHTML.replace(',', '').replace(':', ' ').split(' '); //take the date and split it into [Hour, Minute, Day, Month, Year]
  42. let compareDate = new Date(pageDate[4], months[pageDate[3]], pageDate[2], pageDate[0], pageDate[1]); //parse into javascript Date object
  43. if (cutOffDate > compareDate) { //compare if date is older than cut off date
  44. window.location.href = el.href; //if older, set window to that url
  45. break; //stop the function running
  46. }
  47. }
  48. }
  49. //redirect URL if the current page is the ffxi Wikia and it has an in-era page
  50. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址