GEM PurpleFox Hero Extraction

Extract information about heroes in the current GEM event, and export it for PurpleFox

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         GEM PurpleFox Hero Extraction
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Extract information about heroes in the current GEM event, and export it for PurpleFox
// @author       Dan Collins <[email protected]>
// @author       Aurélie Violette
// @website      https://github.com/dcollinsn/gem-tampermonkey
// @match        https://gem.fabtcg.com/gem/*/run/
// @icon         https://eor-us.purple-fox.fr/favicon.ico
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard
// ==/UserScript==

function extractResult() {
    const PLAYER_REGEXP = /^\s+(.+?) \((\d+)\)/
    const HERO_REGEXP = /^\s+(.+)\n/
    const result = [];
    document.querySelectorAll("ol li div.row").forEach((player) => {
        const cells = player.querySelectorAll("div");
        const [,playerName = null, playerGameId = null] = cells[0].children[0].innerHTML.match(PLAYER_REGEXP) || []
        const [,hero = null] = cells[1].innerHTML.match(HERO_REGEXP) || []
        result.push({
            name: playerName,
            gameId: playerGameId,
            hero: hero
        });
    });
    return result;
}

function doMenuCommand(event) {
    const result = extractResult();
    GM_setClipboard(JSON.stringify(result));
}

(function() {
    'use strict';
    const menu_command_id = GM_registerMenuCommand("Hero Export", doMenuCommand, "e");
})();