multiOpenCloseTabs

Multi open tabs by GM_openInTab then close them to do something.

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/425790/926935/multiOpenCloseTabs.js

  1. // ==UserScript==
  2. // @name multiOpenCloseTabs
  3. // @namespace https://greasyfork.org
  4. // @version 0.1
  5. // @description Multi open tabs by GM_openInTab then close them to do something.
  6. // @match *://*/*
  7. // @grant GM_openInTab
  8. // ==/UserScript==
  9.  
  10. /**
  11. * Multi open tabs by GM_openInTab then close them to do something.
  12. * @param {*} iterative
  13. * @param {Function} getUrlFunc
  14. * @param {Boolean} openInBackground
  15. * @param {Number} closeTimeout
  16. * @param {Function} parentTabFunc
  17. * @param {Number} maxTimes
  18. * @returns
  19. */
  20. const multiOpenCloseTabs = (
  21. iterative,
  22. getUrlFunc,
  23. openInBackground,
  24. closeTimeout,
  25. parentTabFunc,
  26. maxTimes = 0
  27. ) => {
  28. let x = 0;
  29. let y = 0;
  30. for (let i of iterative) {
  31. const Url = getUrlFunc(i);
  32. if (!Url) continue;
  33. const autoOpenUrl = GM_openInTab(Url, openInBackground);
  34. x++;
  35. setTimeout(autoOpenUrl.close, closeTimeout);
  36. autoOpenUrl.onclose = () => {
  37. y++;
  38. if (x === y) {
  39. parentTabFunc();
  40. }
  41. };
  42. if (maxTimes === 0) {
  43. continue;
  44. } else if (x >= maxTimes) {
  45. return;
  46. }
  47. }
  48. };