您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Script for Haxball that allows you to use the commands in the SuperSlowball room by pressing "<".
当前为
// ==UserScript== // @name SuperSlowball Script // @version 0.1 // @author Wepro // @match https://www.haxball.com/play* // @description:en Script for Haxball that allows you to use the commands in the SuperSlowball room by pressing "<". // @namespace https://greasyforks.org/users/684435 // @description Script for Haxball that allows you to use the commands in the SuperSlowball room by pressing "<". // ==/UserScript==//// var el = document.getElementsByClassName("gameframe")[0]; var iframe; var key; var yourkey = "<"; //choose your activation command key var powercheck; var powerselect; setTimeout(function setup() { iframe = document.querySelector("iframe").contentWindow.document; iframe.body.addEventListener("keydown", keypressed, true); }, 1000); var keypressed = function(event) { if (iframe.activeElement != iframe.querySelectorAll("[data-hook='input']")[0]) { key = event.key; typePower(); } } function typePower() { if (key == yourkey && powercheck.checked == true) { switch (powerselect.value) { case "Fat": iframe.body.querySelectorAll("[data-hook='input']")[0].value = "!fat"; iframe.body.querySelectorAll("[data-hook='send']")[0].click(); break; case "Ghost": iframe.body.querySelectorAll("[data-hook='input']")[0].value = "!ghost"; iframe.body.querySelectorAll("[data-hook='send']")[0].click(); break; case "Sprint": iframe.body.querySelectorAll("[data-hook='input']")[0].value = "!sprint"; iframe.body.querySelectorAll("[data-hook='send']")[0].click(); break; case "Slime": iframe.body.querySelectorAll("[data-hook='input']")[0].value = "!slime"; iframe.body.querySelectorAll("[data-hook='send']")[0].click(); break; case "Power": iframe.body.querySelectorAll("[data-hook='input']")[0].value = "!power"; iframe.body.querySelectorAll("[data-hook='send']")[0].click(); break; } } } function waitForElement(selector) { return new Promise(function(resolve, reject) { var element = document.getElementsByClassName("gameframe")[0].contentWindow.document.querySelector(selector); if (element) { resolve(element); return; } var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { var nodes = Array.from(mutation.addedNodes); for (var node of nodes) { if (node.matches && node.matches(selector)) { resolve(node); return; } }; }); }); observer.observe(document.getElementsByClassName("gameframe")[0].contentWindow.document, { childList: true, subtree: true }); }); } moduleObserver = new MutationObserver(function(mutations) { candidates = mutations.flatMap(x => Array.from(x.addedNodes)).filter(x => x.className); if (candidates.length == 1) { var tempView = candidates[0].className; console.log(tempView); switch (true) { case tempView == "game-view": var gameframe = document.documentElement.getElementsByClassName("gameframe")[0]; var statSec = gameframe.contentWindow.document.getElementsByClassName('stats-view')[0]; var checkbox = document.createElement('input'); checkbox.type = "checkbox"; checkbox.name = "name"; checkbox.value = "value"; checkbox.id = "powercheck"; checkbox.style.position = "absolute"; checkbox.style.left = 120 + 'px'; checkbox.style.top = 525 + 'px'; var label = document.createElement('label'); label.style.position = "absolute"; label.style.left = 135 + 'px'; label.style.top = 520 + 'px'; label.htmlFor = "powercheck"; label.appendChild(document.createTextNode(' Enable')); statSec.appendChild(checkbox); statSec.appendChild(label); var powers = ["Fat", "Ghost", "Power", "Sprint", "Slime"]; var selectList = document.createElement("select"); selectList.id = "powerselect"; selectList.style.position = "absolute"; selectList.style.left = 120 + 'px'; selectList.style.top = 545 + 'px'; statSec.appendChild(selectList); for (var i = 0; i < powers.length; i++) { var option = document.createElement("option"); option.value = powers[i]; option.text = powers[i]; selectList.appendChild(option); } powercheck = gameframe.contentWindow.document.getElementById('powercheck'); powerselect = gameframe.contentWindow.document.getElementById('powerselect'); } } }); init = waitForElement("div[class$='view']"); init.then(function(value) { currentView = value.parentNode; moduleObserver.observe(currentView, { childList: true, subtree: true }); });