Code Injector - Starblast.io

Allows different userscripts to define functions that modify the game's code

当前为 2022-05-28 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Code Injector - Starblast.io
// @version      1.0.6
// @description  Allows different userscripts to define functions that modify the game's code
// @author       Pixelmelt & Excigma & kklkkj
// @namespace    https://greasyfork.org/en/users/226344
// @license      GPL-3.0
// @match        https://starblast.io/
// @run-at       document-end
// @grant        none
// ==/UserScript==
 
/* Create a logger */
const log = (msg) => console.log(`%c[Mod injector] ${msg}`, "color: #06c26d");

console.clear()

/* Stop non modified scripts from executing */
document.open();
/* little message telling the user to wait for mods to load */
document.write(`<html><head><title>Loading...</title></head><body style="background-color:#293449;"><div style="margin: auto; width: 50%;"><h1 style="text-align: center;padding: 170px 0;">Loading mods</h1><h1 style="text-align: center;">Please wait</h1></div></body></html>`);
document.close();
log(`Started`)
function injectLoader(){
    /* dont inject into anything but the main page */
    if (window.location.pathname != "/"){log(`Injection not needed`); return}
    /*
    Set to a specific vesion of sb because of rotating var names.
    If you want to use the most recent version of sb for your mod-
    BE WARNED your mod could break at any time due to rotating variable names

    Changing this URL could lead to your ECP being stolen, be careful!
    */
    var url = "https://pixelmelt.github.io/starblast/src/starblastStandard.html";
    
    /* Grab the contents of the link*/
    var xhr = new XMLHttpRequest();
    log("Fetching starblast src...");
    xhr.open("GET", url);
    
    /* When the request finishes... */
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            var starSRC = xhr.responseText;
            if(starSRC != undefined){
                log(`Src fetched successfully`)
            }else{
                log(`Src fetch failed`)
                alert("An error occurred whilst fetching game code");
            }
    
            const start_time = performance.now();
            
            log("Patching src...");
            
            if (!window.sbCodeInjectors) {
                log("Did not find any Starblast.io userscripts to load. This may be an error, make sure you have scripts installed.");
                log(`Proceeded to load normally.`)
            } else {
                /* Loop through `sbCodeInjectors` and pass src code in for them to modify */
                let error_notified = false;
                for (const injector of window.sbCodeInjectors) {
                    try {
                        /* Run injector from other userscripts */
                        if (typeof injector === "function") starSRC = injector(starSRC);
                        else {
                            log("Injector was not a function");
                            console.log(injector);
                        }
                    } catch (error) {
                        /* Only notify the user once if any userscript fails to load
                        helpful to prevent spamming alerts() */
                        
                        if (!error_notified) {
                            /* An injector from one of the other userscripts failed to load */
                            alert("One of your Starblast.io userscripts was unable to be loaded");
                            error_notified = true;
                        }
    
                        console.error(error);
                    }
                }
                const end_time = performance.now();
                log(`Patched src successfully (${(end_time - start_time).toFixed(0)}ms)`);
            }
            /* Finish up and write the modified code to the docuent */
            document.open();
            document.write(starSRC);
            document.close();
        }};
    /* Send the request */
    xhr.send();
}
/* ms before trying to inject mods */
setTimeout(injectLoader, 1)