Baidu URL Shorten

Mark Baidu URL Shortest.

目前為 2023-11-06 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Baidu URL Shorten
  3. // @namespace https://github.com/wzshiming/userscripts
  4. // @version 0.1
  5. // @description Mark Baidu URL Shortest.
  6. // @author wzshiming
  7. // @match *://*.baidu.com/*
  8. // @grant none
  9. // @icon https://www.baidu.com/favicon.ico
  10. // @supportURL https://github.com/wzshiming/userscripts/issues
  11. // @license MIT License
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16. sturl();
  17. window.addEventListener('locationchange', function () {
  18. sturl();
  19. })
  20. })();
  21.  
  22. function sturl() {
  23. var url = window.location.href;
  24. var nurl = window.location.href;
  25. var qs = [
  26. 'rsv_spt', 'rsv_iqid', 'issp', 'f', 'rsv_bp', 'rsv_idx', 'ie', 'tn', 'rsv_enter', 'rsv_dl', 'rsv_sug3', 'rsv_sug1', 'rsv_sug7', 'rsv_sug2', 'rsv_btype', 'inputT', 'rsv_sug4', 'rsv_sug',
  27. 'base_query', 'oq', 'usm', 'rsv_pq', 'rsv_t',
  28. ];
  29. nurl = rmqs(nurl, qs);
  30.  
  31. var qseq = [['pn', '0'], ['rn', '50']];
  32. nurl = rmqseq(nurl, qseq);
  33.  
  34. if (url == nurl) {
  35. return false;
  36. }
  37.  
  38. window.history.replaceState(null, null, nurl);
  39. }
  40.  
  41. function rmqs(url, qs) {
  42. url = new URL(url);
  43. qs.forEach(function (i) {
  44. url.searchParams.delete(i);
  45. });
  46. return url.toString();
  47. }
  48.  
  49. function rmqseq(url, qseq) {
  50. url = new URL(url);
  51. qseq.forEach(function (i) {
  52. if (url.searchParams.get(i[0]) == i[1]) {
  53. url.searchParams.delete(i[0]);
  54. }
  55. });
  56. return url.toString();
  57. }
  58.  
  59. /*----force listen to locationchange work start----*/
  60. history.pushState = (f => function pushState() {
  61. var ret = f.apply(this, arguments);
  62. window.dispatchEvent(new Event('pushstate'));
  63. window.dispatchEvent(new Event('locationchange'));
  64. return ret;
  65. })(history.pushState);
  66.  
  67. history.replaceState = (f => function replaceState() {
  68. var ret = f.apply(this, arguments);
  69. window.dispatchEvent(new Event('replacestate'));
  70. window.dispatchEvent(new Event('locationchange'));
  71. return ret;
  72. })(history.replaceState);
  73.  
  74. window.addEventListener('popstate', () => {
  75. window.dispatchEvent(new Event('locationchange'))
  76. });
  77. /*----force listen to locationchange work end----*/

QingJ © 2025

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