Amazon CPU Tamer

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

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

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