Code Injector - Starblast.io

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

当前为 2022-06-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Code Injector - Starblast.io
  3. // @version 1.0.7
  4. // @description Allows different userscripts to define functions that modify the game's code
  5. // @author Pixelmelt & Excigma & kklkkj
  6. // @namespace https://gf.qytechs.cn/en/users/226344
  7. // @license GPL-3.0
  8. // @match https://starblast.io/
  9. // @run-at document-end
  10. // @grant none
  11. // ==/UserScript==
  12. /* Create a logger */
  13. const log = (msg) => console.log(`%c[Mod injector] ${msg}`, "color: #06c26d");
  14.  
  15. console.clear()
  16.  
  17. /* Stop non modified scripts from executing */
  18. document.open();
  19. /* little message telling the user to wait for mods to load */
  20. 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>`);
  21. document.close();
  22. log(`Started`)
  23. function injectLoader(){
  24. /* dont inject into anything but the main page */
  25. if (window.location.pathname != "/"){log(`Injection not needed`); return}
  26. /*
  27. Set to a specific vesion of sb because of rotating var names.
  28. If you want to use the most recent version of sb for your mod-
  29. BE WARNED your mod could break at any time due to rotating variable names
  30.  
  31. Changing this URL could lead to your ECP being stolen, be careful!
  32. */
  33. var url = "https://pixelmelt.github.io/starblast/src/starblastStandard.html";
  34. /* Grab the contents of the link*/
  35. var xhr = new XMLHttpRequest();
  36. log("Fetching starblast src...");
  37. xhr.open("GET", url);
  38. /* When the request finishes... */
  39. xhr.onreadystatechange = function () {
  40. if (xhr.readyState === 4) {
  41. var starSRC = xhr.responseText;
  42. if(starSRC != undefined){
  43. log(`Src fetched successfully`)
  44. }else{
  45. log(`Src fetch failed`)
  46. alert("An error occurred whilst fetching game code");
  47. }
  48. const start_time = performance.now();
  49. log("Patching src...");
  50. if (!window.sbCodeInjectors) {
  51. log("Did not find any Starblast.io userscripts to load. This may be an error, make sure you have scripts installed.");
  52. log(`Proceeded to load normally.`)
  53. } else {
  54. /* Loop through `sbCodeInjectors` and pass src code in for them to modify */
  55. let error_notified = false;
  56. for (const injector of window.sbCodeInjectors) {
  57. try {
  58. /* Run injector from other userscripts */
  59. if (typeof injector === "function") starSRC = injector(starSRC);
  60. else {
  61. log("Injector was not a function");
  62. console.log(injector);
  63. }
  64. } catch (error) {
  65. /* Only notify the user once if any userscript fails to load
  66. helpful to prevent spamming alerts() */
  67. if (!error_notified) {
  68. /* An injector from one of the other userscripts failed to load */
  69. alert("One of your Starblast.io userscripts was unable to be loaded");
  70. error_notified = true;
  71. }
  72. console.error(error);
  73. }
  74. }
  75. }
  76. const end_time = performance.now();
  77. log(`Patched src successfully (${(end_time - start_time).toFixed(0)}ms)`);
  78. /* Finish up and write the modified code to the docuent */
  79. document.open();
  80. document.write(starSRC);
  81. document.close();
  82.  
  83. // run function once docuemnt is loaded
  84. document.addEventListener("DOMContentLoaded", function() {
  85. log("Document loaded");
  86. setTimeout(() => {
  87. if (!window.sbCodeRunners) {
  88. log("No CodeRunners found")
  89. }else{
  90. log("CodeRunners found")
  91. for(const runner of window.sbCodeRunners){
  92. try{
  93. if(typeof runner === "function"){
  94. runner();
  95. }else{
  96. log("CodeRunner was not a function");
  97. console.log(runner);
  98. }
  99. }catch(err){
  100. console.error(err);
  101. }
  102. }
  103. };
  104. }, 30);
  105. });
  106.  
  107. }};
  108. /* Send the request */
  109. xhr.send();
  110. }
  111. /* ms before trying to inject mods */
  112. setTimeout(injectLoader, 1);

QingJ © 2025

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