Tournament Inviter

Provides context menu commands for inviting players (from a clan) to a tournament

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         Tournament Inviter
// @namespace    http://tampermonkey.net/
// @version      2025-12-14
// @description  Provides context menu commands for inviting players (from a clan) to a tournament
// @author       JK_3
// @match        https://www.warzone.com/MultiPlayer/Tournaments/Forward?ID=*
// @icon         https://icons.duckduckgo.com/ip2/warzone.com.ico
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    function getNextButton() {
        let iterator = document.querySelector("div[id^='ujs_PagingContainer']")?.querySelectorAll(".ujsBtn")
        if (iterator)
        {
            for (let btn of iterator) {
                if (btn.textContent.includes("Next")) {
                    return btn.querySelector("[id$='_btn']")
                }
            }
        }

        return null
    }

    function inviteAllPlayers() {
        for (let btn of document.querySelectorAll("[id^='ujs_InviteBtn_'][id$='_btn']")) {
            btn.click()
        }

        let nextBtn = getNextButton()
        if (nextBtn) {
            nextBtn.click()
            inviteAllPlayers()
        }
    }

    function inviteActivePlayers() {
        for (let img of document.querySelectorAll("[id^='ujs_OnlineImage'][id$='img']")) {
            if (img.checkVisibility()) {
                img.parentElement?.parentElement?.parentElement?.querySelector("[id^='ujs_InviteBtn_'][id$='_btn']")?.click()
            }
        }

        let nextBtn = getNextButton()
        if (nextBtn) {
            nextBtn.click()
            inviteActivePlayers()
        }
    }

    GM_registerMenuCommand("Invite all", inviteAllPlayers)
    GM_registerMenuCommand("Invite active players only", inviteActivePlayers)
})();