MSPA link fixerer

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

目前为 2022-05-05 提交的版本。查看 最新版本

  1. /* jshint esversion: 6 */
  2. // ==UserScript==
  3. // @name MSPA link fixerer
  4. // @version 1
  5. // @description Replaces MSPA indexed links to Homestuck with links to Homestuck.com.
  6. // @author EtchJetty
  7. // @license MIT
  8. // @match http://*/*
  9. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/909980
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16.  
  17. replaceLinks();
  18.  
  19. // story6: 1900 (hs)
  20. // story5: 1892 (hs-beta)
  21. // story4: 218 (ps)
  22. // story3: n/a (midnight crew)
  23. // story2: 135 (bardquest)
  24. // story1: 1 (jb)
  25.  
  26. function replaceLinks() {
  27. Array.from(document.getElementsByTagName("a")).forEach(function (a) {
  28. // console.log(a.href);
  29. const regex = /(?:http.*mspaintadventures\.com\/.*|\?)s=\d.*p=(\d{1,6})/gm;
  30. const baseurl = `https://www.homestuck.com/`;
  31. const hssubst = baseurl + `story`;
  32. const hsbetasubst = baseurl + `beta`;
  33. const pssubst = baseurl + `problem-sleuth`;
  34. // const mcsubst = baseurl + `404`;
  35. const bqsubst = baseurl + `bard-quest`;
  36. const jbsubst = baseurl + `jailbreak`;
  37.  
  38. // The substituted value will be contained in the result variable
  39.  
  40. let m;
  41.  
  42. const hrefex = a.href.toString().slice(a.href.toString().length - 4);
  43. if (hrefex.slice(0, -1) == "?s=") {
  44. //if this is just a story link, no page
  45. switch (parseInt(hrefex[hrefex.length - 1])) {
  46. case 6:
  47. a.href = hssubst;
  48. break;
  49. case 5:
  50. a.href = hsbetasubst;
  51. break;
  52. case 4:
  53. a.href = pssubst;
  54. break;
  55. case 3:
  56. a.href = "http://www.mspaintadventures.com/test_index.php?s=3"; // mc doesn't exist on homestuck.com as far as i know
  57. break;
  58. case 2:
  59. a.href = bqsubst;
  60. break;
  61. case 1:
  62. a.href = jbsubst;
  63. break;
  64. }
  65. } else {
  66. while ((m = regex.exec(a.href.toString())) !== null) {
  67. // This is necessary to avoid infinite loops with zero-width matches
  68. if (m.index === regex.lastIndex) {
  69. regex.lastIndex++;
  70. }
  71.  
  72. var match = parseInt(m[1]); // get just the matched value
  73. switch (true) {
  74. case match > 1900:
  75. match = match - 1900;
  76. a.href = hssubst + "/" + match;
  77. break;
  78.  
  79. case 1892 < match && match < 1900:
  80. match = match - 1892;
  81. a.href = hsbetasubst + "/" + match;
  82. break;
  83.  
  84. case 218 < match && match < 1892:
  85. match = match - 218;
  86. a.href = pssubst + "/" + match;
  87. break;
  88.  
  89. case 135 < match && match < 218:
  90. match = match - 135;
  91. a.href = bqsubst + "/" + match;
  92. break;
  93.  
  94. case 1 < match && match < 135:
  95. match = match - 1;
  96. a.href = jbsubst + "/" + match;
  97. break;
  98. }
  99. }
  100. }
  101. });
  102. }
  103. })();