Greasy Fork镜像 支持简体中文。

清洗url

移除url中冗余的查询参数

  1. // ==UserScript==
  2. // @name 清洗url
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description 移除url中冗余的查询参数
  6. // @author 微笑
  7. // @run-at document-idle
  8. // @match https://mp.weixin.qq.com/*
  9. // @match https://www.zhihu.com/*
  10. // @match https://*.bilibili.com/*
  11. // @match https://github.com/*
  12. // @match https://*.aliyun.com/*
  13. // @icon https://www.google.com/s2/favicons?sz=64&domain=qq.com
  14. // @grant none
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. (function () {
  19. 'use strict';
  20.  
  21. const domainConfig = {
  22. 'mp.weixin.qq.com': {
  23. removeKeys: ['chksm', 'source'],
  24. removeHash: true,
  25. },
  26. 'www.zhihu.com': {
  27. removeKeys: ['utm_medium', 'utm_oi', 'utm_source'],
  28. removeHash: false,
  29. },
  30. 'search.bilibili.com': {
  31. removeKeys: ['spm_id_from', 'from_source', 'search_source', 'vt'],
  32. removeHash: false,
  33. },
  34. 'space.bilibili.com': {
  35. removeKeys: ['spm_id_from', 'from_source', 'search_source'],
  36. removeHash: false,
  37. },
  38. 'www.bilibili.com': {
  39. removeKeys: [
  40. 'buvid',
  41. 'is_story_h5',
  42. 'mid',
  43. 'p',
  44. 'plat_id',
  45. 'share_from',
  46. 'share_medium',
  47. 'share_plat',
  48. 'share_session_id',
  49. 'share_source',
  50. 'share_tag',
  51. 'timestamp',
  52. 'unique_k',
  53. 'up_id',
  54. 'vd_source',
  55. 'spm_id_from',
  56. ],
  57. },
  58. 'github.com': {
  59. removeKeys: ['ref'],
  60. },
  61. };
  62.  
  63. const defaultRemoveKeys = ['spm'];
  64.  
  65. const { href, host } = location;
  66. const newUrl = new URL(href);
  67.  
  68. const removeParams = (keys) => {
  69. keys.forEach((key) => {
  70. newUrl.searchParams.delete(key);
  71. });
  72. };
  73.  
  74. const configForCurrentDomain = domainConfig[host];
  75. removeParams(configForCurrentDomain?.removeKeys || defaultRemoveKeys);
  76.  
  77. if (configForCurrentDomain) {
  78. if (configForCurrentDomain.removeHash) {
  79. newUrl.hash = '';
  80. }
  81. }
  82.  
  83. const newHref = newUrl.toString();
  84. if (newHref !== href) {
  85. setTimeout(() => {
  86. history.replaceState(null, '', newHref);
  87. }, 3000);
  88. }
  89.  
  90. if (host === 'www.bilibili.com') {
  91. const adDom = document.querySelector('.adblock-tips');
  92. if (adDom) {
  93. adDom.remove();
  94. }
  95. }
  96. })();

QingJ © 2025

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