IndieGala Keys to TextArea

Displays a text area with game titles and keys.

当前为 2020-05-13 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         IndieGala Keys to TextArea
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  Displays a text area with game titles and keys.
// @author       Lex
// @match        https://www.indiegala.com/library*
// @match        https://www.indiegala.com/gift*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function getGames() {
        const active = document.querySelector("ul.profile-private-page-library-sublist-active");
        const es = active.querySelectorAll(".profile-private-page-library-key-cont");
        return Array.prototype.map.call(es, e => {
            const title = e.querySelector(".profile-private-page-library-title div").textContent.trim();
            const inps = e.getElementsByTagName("input");
            const key = (inps.length > 0) ? inps[0].value : "";
            return [title, key];
        });
    }

    function injectTextbox() {
        console.log("Dumping keys");
        const active = document.querySelector("ul.profile-private-page-library-sublist-active");
        let area = active.querySelector("textarea.igktt");
        if (!area) {
            area = document.createElement("textarea");
            area.className = "igktt";
            active.append(area);
        }
        // Ignore games which do not have keys revealed
        let games = getGames().filter(e => e[1]);
        area.value = games.map(e => e[0]+","+e[1]).join("\n");
        area.style.width = "100%";
        area.style.height = "";
        area.style.height = area.scrollHeight + 20 + "px";
    }

    function waitForBundleLoaded() {
        const loader = document.querySelector("ul.profile-private-page-library-sublist-active .profile-private-page-library-subitem-loading");
        if (loader && loader.style.display == "none") {
            injectTextbox();
        } else {
            setTimeout(waitForBundleLoaded, 100);
        }
    }

    function injectLoaders() {
        const as = document.querySelectorAll(".profile-private-page-library-list .fit-click");
        as.forEach(a => {a.addEventListener("click", waitForBundleLoaded)});
    }

    injectLoaders();
    injectTextbox();
})();