MSPA link fixerer

Replaces MSPA indexed links to Homestuck with links to Homestuck.com.

当前为 2022-05-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MSPA link fixerer
  3. // @version 0.1
  4. // @description Replaces MSPA indexed links to Homestuck with links to Homestuck.com.
  5. // @author EtchJetty
  6. // @license MIT
  7. // @match http://*/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @namespace https://greasyfork.org/users/909980
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. //document.addEventListener("DOMContentLoaded", replaceLinks, false );
  17.  
  18. //if( document.readyState === "complete" ) {
  19. replaceLinks();
  20. //}
  21.  
  22. function replaceLinks() {
  23. Array.from(document.getElementsByTagName("a")).forEach(function (a) {
  24. // console.log(a.href);
  25. const regex = /http:\/\/www\.mspaintadventures\.com\/.*s=6.*p=(\d{1,6})/g;
  26. const subst = `https://www.homestuck.com/story/`;
  27.  
  28. // The substituted value will be contained in the result variable
  29.  
  30. let m;
  31.  
  32. while ((m = regex.exec(a.href.toString())) !== null) {
  33. // This is necessary to avoid infinite loops with zero-width matches
  34. if (m.index === regex.lastIndex) {
  35. regex.lastIndex++;
  36. }
  37.  
  38. // The result can be accessed through the `m`-variable.
  39. m.forEach((match, groupIndex) => {
  40. //console.log(`${match}`);
  41. if (match > 1900) {
  42. match = match - 1900;
  43. }
  44. //console.log("fixed:", match);
  45. a.href = "https://www.homestuck.com/story/" + match;
  46. });
  47. }
  48. });
  49. }
  50. })();