TP Maptest U-M button

Adds a button to the tagpro-test map test page to test a map from a U-M ID.

当前为 2021-04-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TP Maptest U-M button
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Adds a button to the tagpro-test map test page to test a map from a U-M ID.
// @author       E. Lek-Tro
// @match        http://tagpro-maptest.koalabeast.com/testmap
// @match        http://tagpro-maptest.koalabeast.com/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    $(".form").parent().append("<button id='umIDBtn' class='btn btn-primary'>U-M ID</button>")

    $("#umIDBtn").click(e => {
        changeMapFromID(prompt("Map ID:")).then(() => {
            $(".form .form-group:last-child button[type='submit']").click();
        });
    });

    $("#play-now").attr("href", "http://tagpro-maptest.koalabeast.com/testmap");

    function changeMapFromID(id){
        return new Promise(async (resolve, reject) => {
            console.log("id:", id);
            if(isNaN(Number(id)) || id === "") id = Math.floor(Math.random() * 60000);
            let pngBlob = await fetch(`https://parretlabs.xyz:8006/proxy?isBlob=1&type=image/png&link=http://unfortunate-maps.jukejuice.com/static/maps/${id}.png`)
            .then(res => res.blob());
            let jsonBlob = await fetch(`https://parretlabs.xyz:8006/proxy?type=application/json&link=http://unfortunate-maps.jukejuice.com/static/maps/${id}.json`)
            .then(res => res.blob());

            const pngTransfer = new ClipboardEvent('').clipboardData || new DataTransfer();
            const jsonTransfer = new ClipboardEvent('').clipboardData || new DataTransfer();
            pngTransfer.items.add(new File([pngBlob], 'map.png', {type: "image/png"}));
            jsonTransfer.items.add(new File([jsonBlob], 'map.json', {type: "application/json"}));

            document.querySelector("input[name='layout']").files = pngTransfer.files;
            document.querySelector("input[name='logic']").files = jsonTransfer.files;

            console.log(pngBlob, jsonBlob)

            setTimeout(function(){
                resolve();
            }, 100);
        });
    }

    // Your code here...
})();