Amazon CPU Tamer

减少Amazon购物页面上的CPU利用率。顺利地享受买东西吧。

当前为 2020-11-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Amazon CPU Tamer
  3. // @name:ja Amazon CPU Tamer
  4. // @name:zh-CN Amazon CPU Tamer
  5. // @namespace knoa.jp
  6. // @contributionURL https://paypal.me/kantankikaku
  7. // @description It reduces CPU usage on Amazon shopping pages. Enjoy your snappy shopping.
  8. // @description:ja AmazonのショッピングページでのCPU使用率を削減します。お買いものをサクサク楽しみましょう。
  9. // @description:zh-CN 减少Amazon购物页面上的CPU利用率。顺利地享受买东西吧。
  10. // @include https://www.amazon.com/*
  11. // @include https://www.amazon.co.jp/*
  12. // @include https://www.amazon.*
  13. // @exclude */cart/*
  14. // @exclude */buy/*
  15. // @version 1.2.0
  16. // @grant none
  17. // @run-at document-start
  18. // ==/UserScript==
  19.  
  20. /*
  21. [update] 1.2.0
  22. Fix for Amazon associate.
  23.  
  24. */
  25. (function(){
  26. const SCRIPTNAME = 'Amazon Cpu Tamer';
  27. console.log(SCRIPTNAME);
  28. const TAMEDINTERVAL = 60*1000;
  29. /* tame quick intervals */
  30. window.originalSetInterval = window.setInterval;
  31. window.setInterval = function(f, interval, ...args){
  32. if(interval < TAMEDINTERVAL){
  33. console.log(SCRIPTNAME, 'interval:', interval, 'to', TAMEDINTERVAL);
  34. interval = TAMEDINTERVAL;
  35. }
  36. return window.originalSetInterval(f, interval, ...args);
  37. };
  38. /* add an associate tag */
  39. switch(location.host){
  40. case('www.amazon.com'):
  41. addTag('knoa-20');
  42. break;
  43. case('www.amazon.co.jp'):
  44. addTag('knoa-22');
  45. break;
  46. }
  47. function addTag(tag){
  48. const url = new URL(location.href);
  49. if(url.searchParams.get('tag') !== null) return;/* do not overwrite */
  50. console.log(SCRIPTNAME, 'associate tag:', tag);
  51. document.documentElement.addEventListener('mousedown', function(e){
  52. for(let target = e.target; target; target = target.parentNode){
  53. if(target.href && target.href.startsWith(location.origin)){
  54. const separator = (target.href.includes('?')) ? '&' : '?';
  55. target.href = target.href + separator + 'tag=' + tag;
  56. }
  57. }
  58. });
  59. const separator = (url.search === '') ? '?' : '&';
  60. history.replaceState(null, document.title, location.href + separator + 'tag=' + tag);
  61. }
  62. })();