Greasyfork.org - remove lang from url

To remove lang from Greasy Fork's url

目前为 2023-08-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Greasyfork.org - remove lang from url
  3. // @namespace UserScript
  4. // @match https://greasyfork.org/*
  5. // @grant none
  6. // @version 1.0
  7. // @author CY Fung
  8. // @description To remove lang from Greasy Fork's url
  9. // @run-at document-start
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function (__CONTEXT__) {
  14.  
  15.  
  16.  
  17. const { setInterval, clearInterval, Promise } = __CONTEXT__;
  18.  
  19. let lastURL = null;
  20.  
  21. const langs = [
  22. "ar",
  23. "bg",
  24. "cs",
  25. "da",
  26. "de",
  27. "el",
  28. "en",
  29. "eo",
  30. "es",
  31. "fi",
  32. "fr",
  33. "fr-CA",
  34. "he",
  35. "hu",
  36. "id",
  37. "it",
  38. "ja",
  39. "ka",
  40. "ko",
  41. "nb",
  42. "nl",
  43. "pl",
  44. "pt-BR",
  45. "ro",
  46. "ru",
  47. "sk",
  48. "sr",
  49. "sv",
  50. "th",
  51. "tr",
  52. "uk",
  53. "ug",
  54. "vi",
  55. "zh-CN",
  56. "zh-TW"
  57. ];
  58.  
  59. const regex = new RegExp("\/(" + langs.join('|') + ")\/");
  60.  
  61. function tim() {
  62.  
  63. const url = location.pathname;
  64.  
  65. if (url === lastURL) return;
  66. lastURL = url;
  67.  
  68.  
  69. const m = regex.exec(url);
  70. if (m) {
  71. history.replaceState(history.state, '', url.replace(`${m[0]}`, '\/') + location.search);
  72. }
  73.  
  74.  
  75.  
  76. }
  77. let cid = setInterval(tim, 1);
  78.  
  79.  
  80.  
  81. function onReady() {
  82. clearInterval(cid);
  83. cid = 0;
  84. Promise.resolve().then(tim);
  85. }
  86.  
  87. Promise.resolve().then(() => {
  88. if (document.readyState !== 'loading') {
  89. onReady();
  90. } else {
  91. window.addEventListener("DOMContentLoaded", onReady, false);
  92. }
  93. });
  94.  
  95.  
  96.  
  97. })({ setInterval, clearInterval, Promise });
  98.  
  99.  
  100.  
  101. // No more language tag