Stylem
Stylem
Stylem
// @name Hackstyle.js
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Hamahapeha
// @author MrTarnegol
// @match https://*.haxball.com/*
// @grant none
// ==/UserScript==
style.defaultAvatar = "~~";
style.avatarIndex = 0;
class Timer {
constructor(callback, delay) {
this.delay = delay;
this.callback = callback;
this.id = -1;
}
start() {
if (this.id == -1) {
this.id = setInterval(this.callback, this.delay);
}
}
stop() {
if (this.id !== -1) {
clearInterval(this.id);
this.id = -1;
}
}
setDelay(delay) {
this.delay = delay;
if (this.id !== -1) {
this.stop();
this.start();
}
}
isRunning() {
return this.id !== -1
}
addCallback(callback) {
this.callback = () => {this.callback(); callback();}
}
}
var gameDocument;
const initGameDocument = () => {
gameDocument = window.gameDocument =
document.getElementsByClassName('gameframe')[0].contentWindow.document;
}
const hebrewRegexes = {
"a$": ""ה,
"m$": ""ם,
"n$": ""ן,
"ll": ""ל,
"a": "",
"b": ""ב,
"c": ""צ,
"d": ""ד,
"e": "",
"f": ""פ,
"g": ""ג,
"h": "",
"i": ""י,
"j": ""'ג,
"k": ""ק,
"l": ""ל,
"m": ""מ,
"n": ""נ,
"o": ""ו,
"p": ""פ,
"q": ""ק,
"r": ""ר,
"s": ""ס,
"t": ""ט,
"u": ""ו,
"v": ""ב,
"w": ""וו,
"x": ""קס,
"y": ""יי,
"z": ""ז,
}
style.toHebrew = (word) => {
if (/^[aeiou]/gi.test(word)) word = " "א+ word;
for (let [regex, replacement] of Object.entries(hebrewRegexes)) {
word = word.replace(new RegExp(regex, "gi"), replacement);
}
return word;
}
style.nickname = () => {
return localStorage.player_name;
}
style.nicknames = () => {
return [style.nickname(),
style.nickname().toUpperCase(),
style.nickname().toLowerCase(),
style.toHebrew(style.nickname())];
}
style.chatBox = () => {
return gameDocument.getElementsByTagName("input")[0];
}
style.sendButton = () => {
const input = gameDocument.getElementsByClassName("input")[0];
return input ? input.getElementsByTagName("button")[0] : null;
}
style.chatHistory = () => {
return gameDocument.getElementsByClassName("log ps")[0];
}
style.send = () => {
style.sendButton().click();
}
style.getMessage = () => {
return style.chatBox().value;
}
style.setNextAvatarIndex = () => {
style.setAvatar(style.avatars[style.avatarIndex]);
style.avatarIndex = (style.avatarIndex + 1) % style.avatars.length;
}
style.setDefaultIndex = () => {
style.setAvatar(style.defaultAvatar);
style.avatarIndex = 0;
}
style.startAvatarChanger = () => {
style.avatarTimer.start();
}
style.stopAvatarChanger = () => {
style.avatarTimer.stop();
style.setAvatar(style.defaultAvatar);
style.avatarIndex = 0;
}
const nameRegexes = [
...[...Array(26)].map((_, i) => ({ from: String.fromCharCode(55349, 56788 + i),
to: String.fromCharCode(65 + i) })),
...[...Array(26)].map((_, i) => ({ from: String.fromCharCode(55349, 56814 + i),
to: String.fromCharCode(97 + i) })),
];
const decodeSendName = (word) => {
if (/^[aeiou]/gi.test(word)) word = " "א+ word;
for (let { from, to } of nameRegexes) {
word = word.replace(new RegExp(from, "gi"), to);
}
return word;
}
initGameDocument();
setTimeout(start, 3000);