Remove Redundant URL Search Parameters

Remove Redundant URL Search Parameters like fbclid

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

  1. // ==UserScript==
  2. // @name Remove Redundant URL Search Parameters
  3. // @namespace https://github.com/livinginpurple
  4. // @version 2019.08.03.14
  5. // @description Remove Redundant URL Search Parameters like fbclid
  6. // @author livinginpurple
  7. // @license WTFPL
  8. // @exclude https://*.google.com/*
  9. // @exclude https://*.facebook.com/*
  10. // @exclude https://www.plurk.com/*
  11. // @include *
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18. console.log(GM_info.script.name + " is loading.");;
  19. let TotalReplaceUri = location.href.split("?")[0];
  20. let FirstSearchParameter = location.search.split('&')[0];
  21. let PartialReplaceUri = TotalReplaceUri + FirstSearchParameter;
  22. let keywords = ["fbclid", "jobsource", "from=fb", "f=cs", "gclid", "utm_", "from=udn"];
  23.  
  24. keywords.forEach(element => {
  25. if (location.href.includes(element)) {
  26. ModifyUrl(TotalReplaceUri);
  27. }
  28. });
  29.  
  30. if (PartialReplaceUri.includes("fbclid") && !FirstSearchParameter.includes("fbclid")) {
  31. ModifyUrl(PartialReplaceUri);
  32. }
  33.  
  34. function ModifyUrl(replaceUri) {
  35. // 修改網址,且不留下歷史紀錄
  36. window.history.replaceState({},
  37. window.title,
  38. replaceUri
  39. );
  40. }
  41. console.log(GM_info.script.name + " is running.");
  42. })(document);