Clean URL Query

Trim tracking query params from URL

当前为 2018-10-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Clean URL Query
  3. // @namespace https://github.com/leesei/userscripts
  4. // @version 1.1
  5. // @description Trim tracking query params from URL
  6. // @author leesei@gmail.com
  7. // @supportURL https://github.com/leesei/userscripts/issues
  8. // @match http*://detail.tmall.com/item.htm*
  9. // @match http*://*.tmall.com/shop/view_shop.htm
  10. // @match http*://item.taobao.com/item.htm*
  11. // @match http*://*.taobao.com/shop/view_shop.htm
  12. // @match http*://*.computerworld.com/*
  13. // @match http*://*.infoworld.com/*
  14. // @run-at document-start
  15. // @grant GM_log
  16. // @grant GM_info
  17. // @noframes
  18. // ==/UserScript==
  19.  
  20. function log(level, text) {
  21. GM_log(level + ": " + text);
  22. }
  23.  
  24. function query2json(querystring) {
  25. // remove any preceding url and split
  26. var queries = querystring.substring(querystring.indexOf("?") + 1).split("&");
  27. var params = {},
  28. pair,
  29. d = decodeURIComponent;
  30. // march and parse
  31. for (var i = queries.length - 1; i >= 0; i--) {
  32. pair = queries[i].split("=");
  33. params[d(pair[0])] = d(pair[1]);
  34. }
  35.  
  36. return params;
  37. }
  38.  
  39. (function() {
  40. "use strict";
  41.  
  42. log(
  43. "info",
  44. ">>> [" + GM_info.script.namespace + "] " + GM_info.script.name + " <<<"
  45. );
  46.  
  47. var queries = query2json(location.search);
  48. log("debug", JSON.stringify(queries));
  49. if (Object.keys(queries).length > 1) {
  50. location.replace(
  51. // retain id for Taobao items
  52. location.pathname + (queries.id ? "?id=" + queries.id : "")
  53. );
  54. }
  55. })();