Greasy Fork is available in English.
Multi open tabs by GM_openInTab then close them to do something.
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/425790/926935/multiOpenCloseTabs.js
// ==UserScript==
// @name multiOpenCloseTabs
// @namespace http://greasyfork.icu
// @version 0.1
// @description Multi open tabs by GM_openInTab then close them to do something.
// @match *://*/*
// @grant GM_openInTab
// ==/UserScript==
/**
* Multi open tabs by GM_openInTab then close them to do something.
* @param {*} iterative
* @param {Function} getUrlFunc
* @param {Boolean} openInBackground
* @param {Number} closeTimeout
* @param {Function} parentTabFunc
* @param {Number} maxTimes
* @returns
*/
const multiOpenCloseTabs = (
iterative,
getUrlFunc,
openInBackground,
closeTimeout,
parentTabFunc,
maxTimes = 0
) => {
let x = 0;
let y = 0;
for (let i of iterative) {
const Url = getUrlFunc(i);
if (!Url) continue;
const autoOpenUrl = GM_openInTab(Url, openInBackground);
x++;
setTimeout(autoOpenUrl.close, closeTimeout);
autoOpenUrl.onclose = () => {
y++;
if (x === y) {
parentTabFunc();
}
};
if (maxTimes === 0) {
continue;
} else if (x >= maxTimes) {
return;
}
}
};