Card_Kingdom_Hotlist_Display

Security through obfuscation is bad, m'kay.

当前为 2021-01-29 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Card_Kingdom_Hotlist_Display
// @namespace    https://*cardkingdom.com/
// @version      0.7
// @description  Security through obfuscation is bad, m'kay.
// @author       Halt_I_m_Reptar (MtG Cabal Cast)
// @match        *://*.cardkingdom.com/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    //write toggle button
    var div = document.createElement('div');
    div.innerHTML = ('<button class="hotListTogle" style="position:fixed;top:0;left:0;z-index:999;width:120px;height:20px;padding:0 5px 0 0;background:#0b0;color:#fff;font-weight:bold;" onclick="toggleHotList()">Toggle Hotlist</button>');
    document.body.prepend(div);
    //write hotlist
    div = document.createElement('div');
    div.innerHTML = ('<div class="hotList" style="position:fixed;bottom:0;left:0;z-index:999;width:auto;height:0px;padding:0 5px 0 0;border:1px solid #d00;background:#fff"></div>');
    document.body.prepend(div);
    //display the hotlist
    beginDisplay();

    async function beginDisplay() {
        await sleep(1000);
        var hotListMap = readableList(mapCards(getSlideContent()));
        var div = document.getElementsByClassName('hotList')[0];
        hotListMap.forEach( itemInfo => {
            div.style.height = adjustHeight(div);
            div.innerHTML += itemInfo;
        });
    }

    window.toggleHotList = function() {
        var display = document.getElementsByClassName('hotList')[0].style.display;
        document.getElementsByClassName('hotList')[0].style.display = display === 'none' ? 'inline' : 'none';
    }

    function sleep (milliseconds) {
        return new Promise(resolve => setTimeout(resolve, milliseconds))
    }

    function getSlideContent() {
        return Array.from(document.getElementsByClassName("sliderDescription"));
    }

    function mapCards(slideArr) {
        return slideArr.map( (elem) => {
            if (elem.innerText.match(/:/g).length > 1) {
                return elem.innerText.replace(/[\n\r]+/g,'--').replace(/:([^:]*):\s/g,'$1--');
            }
            return elem.innerText.replace(/[\n\r]+/g,'--').replace(": ","--")
        });
    }

    function readableList(cardList) {
        return cardList.map(elem => {
            var tempName = elem.split("--");
	    return '<a href="https://cardkingdom.com/purchasing/mtg_singles?filter%5Bsort%5D=price_desc&filter%5Bsearch%5D=mtg_advanced&filter%5Bname%5D=' + tempName[1] + '&filter%5Bcategory_id%5D=0&filter%5Bfoil%5D=1&filter%5Bnonfoil%5D=1&filter%5Bprice_op%5D=&filter%5Bprice%5D=" target="_blank">' + tempName[1] + ' - ' + tempName[0] + ' - ' + tempName[2] + '</a><br />';
        }).sort();
    }

    function adjustHeight(div) {
        return (parseInt(div.style.height.replace(/[a-zA-Z]/g,'')) + 20) + "px";
    }

})();