multiOpenCloseTabs

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

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greasyfork.org/scripts/425790/926935/multiOpenCloseTabs.js.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name          multiOpenCloseTabs
// @namespace     https://greasyfork.org
// @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;
    }
  }
};