HaxBall Map Picker

Search for maps in game

目前為 2019-03-04 提交的版本,檢視 最新版本

// ==UserScript==
// @name         HaxBall Map Picker
// @namespace    http://tampermonkey.net/
// @version      1.0
// @icon         https://www.haxball.com/favicon.ico
// @description  Search for maps in game
// @author       -Electron-
// @include        https://www.haxball.com/FFuuq69i/__cache_static__/g/game.html
// @supportURL   https://www.reddit.com/message/compose/?to=-Electron-
// @website      https://redd.it/no-post-yet
// @require      https://code.jquery.com/jquery-latest.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    let pickerPopupIsShown = false;

    setInterval(function(){
        if($(".dialog.pick-stadium-view").length){
            if(!pickerPopupIsShown) showPicker();
            pickerPopupIsShown = true;
        } else {
            if(pickerPopupIsShown) hidePicker();
            pickerPopupIsShown = false;
        }
    }, 500);

    function showPicker(){
        $(`<button data-hook="searchmaps">HaxMaps</button>`).insertAfter(".dialog.pick-stadium-view .buttons .file-btn");
        $("button[data-hook='searchmaps']").click(function(){
            let mapSearch = prompt("Map ID:");

            getHaxBallMapText(mapSearch).then(text => {
                const dT = new ClipboardEvent('').clipboardData || // Firefox < 62 workaround exploiting https://bugzilla.mozilla.org/show_bug.cgi?id=1422655
                      new DataTransfer(); // specs compliant (as of March 2018 only Chrome)
                dT.items.add(new File([text], 'programmatically_created.hbs'));
                console.log(text);
                document.getElementById("stadfile").files = dT.files;
            });
        });
    }

    function hidePicker(){

    }

    function searchForMaps(query){
        fetch("https://streamlyne.stream:88/proxy?link=http://haxmaps.com/hb/rpc").then(a => a.text()).then(text => {
            let listElems = $(text);

            console.log(Array.from(listElems))
        });
    }

    function linkToBlob(link){
        return new Promise(function(resolve, reject) {
            let xhr = new XMLHttpRequest();
            xhr.open("GET", link);
            xhr.responseType = "blob";//force the HTTP response, response-type header to be blob
            xhr.onload = function(){
                resolve(xhr.response);
            }
            xhr.send();
        });
    }

    function getHaxBallMapText(id){
        return new Promise(function(resolve, reject) {
            linkToBlob("https://streamlyne.stream:88/proxy?link=http://haxmaps.com/dl/" + id).then(function(blob){
                var myReader = new FileReader();
                myReader.addEventListener("loadend", function(e){
                    resolve(e.srcElement.result);
                });
                myReader.readAsText(blob);
                // resolve(blob);
            });
        });
    }

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址