Bing URL Shorten

Mark Bing URL Shortest.

  1. // ==UserScript==
  2. // @name Bing URL Shorten
  3. // @namespace https://github.com/wzshiming/userscripts
  4. // @version 0.1.2
  5. // @description Mark Bing URL Shortest.
  6. // @author wzshiming
  7. // @match *://*.bing.com/*
  8. // @grant none
  9. // @icon https://www.bing.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. 'form', 'sp', 'lq', 'pq', 'sc', 'qs', 'sk', 'cvid', 'ghsh', 'ghacc', 'ghpl',
  27. 'FPIG', 'FORM', 'mkt',
  28. 'asbe', 'filters',
  29. ];
  30. nurl = rmqs(nurl, qs);
  31.  
  32. var qseq = [['first', '1']];
  33. nurl = rmqseq(nurl, qseq);
  34.  
  35. if (url == nurl) {
  36. return false;
  37. }
  38.  
  39. window.history.replaceState(null, null, nurl);
  40. }
  41.  
  42. function rmqs(url, qs) {
  43. url = new URL(url);
  44. qs.forEach(function (i) {
  45. url.searchParams.delete(i);
  46. });
  47. return url.toString();
  48. }
  49.  
  50. function rmqseq(url, qseq) {
  51. url = new URL(url);
  52. qseq.forEach(function (i) {
  53. if (url.searchParams.get(i[0]) == i[1]) {
  54. url.searchParams.delete(i[0]);
  55. }
  56. });
  57. return url.toString();
  58. }
  59.  
  60. /*----force listen to locationchange work start----*/
  61. history.pushState = (f => function pushState() {
  62. var ret = f.apply(this, arguments);
  63. window.dispatchEvent(new Event('pushstate'));
  64. window.dispatchEvent(new Event('locationchange'));
  65. return ret;
  66. })(history.pushState);
  67.  
  68. history.replaceState = (f => function replaceState() {
  69. var ret = f.apply(this, arguments);
  70. window.dispatchEvent(new Event('replacestate'));
  71. window.dispatchEvent(new Event('locationchange'));
  72. return ret;
  73. })(history.replaceState);
  74.  
  75. window.addEventListener('popstate', () => {
  76. window.dispatchEvent(new Event('locationchange'))
  77. });
  78. /*----force listen to locationchange work end----*/

QingJ © 2025

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