gf.qytechs.cn - remove lang from url

To remove lang from Greasy Fork镜像's url

  1. // ==UserScript==
  2. // @name gf.qytechs.cn - remove lang from url
  3. // @namespace UserScript
  4. // @match https://gf.qytechs.cn/*
  5. // @grant none
  6. // @version 1.2
  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. const delayTime = -1; // ms, -1 disable
  16.  
  17. let pathnames = {before: '', after:''};
  18.  
  19. function main(){
  20.  
  21.  
  22.  
  23. const { setInterval, clearInterval, Promise } = __CONTEXT__;
  24.  
  25. let lastURL = null;
  26.  
  27. const langs = [
  28. "ar",
  29. "bg",
  30. "cs",
  31. "da",
  32. "de",
  33. "el",
  34. "en",
  35. "eo",
  36. "es",
  37. "fi",
  38. "fr",
  39. "fr-CA",
  40. "he",
  41. "hu",
  42. "id",
  43. "it",
  44. "ja",
  45. "ka",
  46. "ko",
  47. "nb",
  48. "nl",
  49. "pl",
  50. "pt-BR",
  51. "ro",
  52. "ru",
  53. "sk",
  54. "sr",
  55. "sv",
  56. "th",
  57. "tr",
  58. "uk",
  59. "ug",
  60. "vi",
  61. "zh-CN",
  62. "zh-TW"
  63. ];
  64.  
  65. const regex = new RegExp("\/(" + langs.join('|') + ")\/");
  66.  
  67. function tim() {
  68.  
  69. const url = location.pathname;
  70.  
  71. if (url === lastURL) return;
  72. lastURL = url;
  73.  
  74.  
  75. const m = regex.exec(url);
  76. if (m) {
  77. pathnames.before = url;
  78. pathnames.after = url.replace(`${m[0]}`, '\/');
  79. // history.replaceState(history.state, '', pathnames.after + location.search);
  80. }
  81.  
  82.  
  83.  
  84. }
  85. let cid = setInterval(tim, 1);
  86.  
  87.  
  88.  
  89. function onReady() {
  90. clearInterval(cid);
  91. cid = 0;
  92. let mza=false;
  93. Promise.resolve().then(tim).then(()=>{
  94.  
  95.  
  96. document.addEventListener('mousemove', function(evt){
  97. if(!mza && evt.target.id==='script-info' && pathnames.before && pathnames.after){
  98. mza= true;
  99. history.replaceState(history.state, '', pathnames.before + location.search);
  100. }
  101. },true);
  102.  
  103.  
  104. document.addEventListener('mouseenter', function(evt){
  105. if(evt.target.id==='script-info' && pathnames.before && pathnames.after){
  106. mza= true;
  107. history.replaceState(history.state, '', pathnames.before + location.search);
  108. }
  109. },true);
  110.  
  111.  
  112. document.addEventListener('mouseleave', function(evt){
  113. if(evt.target.id==='script-info' && pathnames.before && pathnames.after){
  114. mza=false;
  115. history.replaceState(history.state, '', pathnames.after + location.search);
  116. }
  117. },true);
  118.  
  119.  
  120.  
  121.  
  122. window.addEventListener('focus', function(evt){
  123. console.log(123, evt.target);
  124. if( pathnames.before && pathnames.after && !mza){
  125. mza= true;
  126. history.replaceState(history.state, '', pathnames.before + location.search);
  127. }
  128. },false);
  129.  
  130.  
  131. window.addEventListener('blur', function(evt){
  132. console.log(124, evt.target);
  133. if( pathnames.before && pathnames.after && mza){
  134. mza=false;
  135. history.replaceState(history.state, '', pathnames.after + location.search);
  136. }
  137. },false);
  138.  
  139. });
  140. }
  141.  
  142. Promise.resolve().then(() => {
  143. if (document.readyState !== 'loading') {
  144. onReady();
  145. } else {
  146. window.addEventListener("DOMContentLoaded", onReady, false);
  147. }
  148. });
  149.  
  150. }
  151.  
  152. if(delayTime>=0){
  153.  
  154. setTimeout(main, delayTime);
  155. }else{
  156. main();
  157. }
  158.  
  159.  
  160.  
  161.  
  162.  
  163. })({ setInterval, clearInterval, Promise });
  164.  
  165.  
  166.  
  167. // No more language tag

QingJ © 2025

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