Last active
August 7, 2022 22:14
-
-
Save 4el0ve4ik/d4cb41f191bad924666a4fa822171d00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Tea Coins Helper | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author DXM & molimawka | |
// @match https://game.qw0.ru/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=qw0.ru | |
// @grant none | |
// @run-at document-idle | |
// ==/UserScript== | |
let localStor = window.localStorage; | |
let needCoins = localStor.getItem("needCoins"); | |
let userName = localStor.getItem("username"); | |
let temperature = localStor.getItem("temperature"); | |
let soundCoins = new Audio('https://zvukipro.com/uploads/files/2019-11/1573486907_50be6a16213ba29.mp3'); | |
let soundHotspot = new Audio('https://zvukipro.com/uploads/files/2018-10/1539765721_3e832599dedd.mp3'); | |
const ignoreKeys = ['tag', 'classList', 'childs', 'listeners'] | |
function parseTree(tree) { | |
const el = document.createElement(tree.tag) | |
const keys = Object.keys(tree).filter((key) => ignoreKeys.indexOf(key) === -1) | |
for (const key of keys) { | |
el[key] = tree[key] | |
} | |
if (Array.isArray(tree.classList)) { | |
el.classList.add(...tree.classList) | |
} | |
if (Array.isArray(tree.listeners)) { | |
for (const listener of tree.listeners) { | |
el.addEventListener(listener.name, listener.func) | |
} | |
} | |
if (tree.childs) { | |
for (const child of tree.childs) { | |
const cel = parseTree(child) | |
el.appendChild(cel) | |
} | |
} | |
return el | |
} | |
function waitForElm(selector) { | |
return new Promise(resolve => { | |
if (document.querySelector(selector)) { | |
return resolve(document.querySelector(selector)); | |
} | |
const observer = new MutationObserver(mutations => { | |
if (document.querySelector(selector)) { | |
resolve(document.querySelector(selector)); | |
observer.disconnect(); | |
} | |
}); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true | |
}); | |
}); | |
} | |
const observer = new MutationObserver(function(mutations) { | |
onTitleChange(mutations[0].target.innerText) | |
}); | |
observer.observe(document.querySelector('title'), { subtree: true, characterData: true, childList: true }); | |
const tree = { | |
tag: "div", | |
classList: ['row', 'pb-2', 'justify-content-center'], | |
childs: [ | |
{ | |
tag: 'div', | |
classList: ['col-12'], | |
childs: [ | |
{ | |
tag: 'form', | |
classList: ['form-inline', 'justify-content-center'], | |
listeners: [ | |
{ | |
name: 'submit', | |
func: onSubForm | |
} | |
], | |
childs: [ | |
{ | |
tag: 'input', | |
classList: ['form-control', 'mb-2', 'mr-sm-2'], | |
type: 'number', | |
placeholder: 'Need coins', | |
id: 'needCoins', | |
name: 'needCoins', | |
required: true, | |
value: localStor.getItem("needCoins") | |
}, | |
{ | |
tag: 'input', | |
classList: ['form-control', 'mb-2', 'mr-sm-2'], | |
type: 'string', | |
placeholder: 'Username', | |
id: 'username', | |
name: 'username', | |
required: true, | |
value: localStor.getItem("username") | |
}, | |
{ | |
tag: 'input', | |
classList: ['form-control', 'mb-2', 'mr-sm-2'], | |
type: 'number', | |
placeholder: 'Temperature', | |
id: 'temperature', | |
name: 'temperature', | |
required: true, | |
value: localStor.getItem("temperature") | |
}, | |
{ | |
tag: 'button', | |
type: 'submit', | |
classList: ['btn', 'btn-primary'], | |
innerText: 'Save', | |
required: true | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
function onSubForm(e) { | |
e.preventDefault() | |
const formData = new FormData(e.target); | |
const formProps = Object.fromEntries(formData); | |
needCoins = formProps.needCoins; | |
temperature = formProps.temperature; | |
userName = formProps.username; | |
localStor.setItem("needCoins", formProps.needCoins); | |
localStor.setItem("temperature", formProps.temperature); | |
localStor.setItem("username", formProps.username); | |
console.log(formProps); | |
} | |
const el = parseTree(tree) | |
function onTitleChange(title) { | |
if (title === "Игроки | TEA COIN") { | |
waitForElm("table").then(() => { | |
const container = document.querySelector(".container") | |
container.insertBefore(el, container.firstChild) | |
}) | |
} | |
} | |
setInterval(() => { | |
let topList = document.getElementsByClassName("table b-table table-striped")[0]; | |
if (topList != null) { | |
let allUsersinfo = topList.getElementsByTagName("tr"); | |
for (let index = 1; index < allUsersinfo.length; index++) { | |
let userInfo = allUsersinfo[index].getElementsByTagName("td"); | |
if (userInfo[1].firstChild.getAttribute("alt") == userName) { | |
if (userInfo[2].firstChild.data >= Number(needCoins)) | |
soundCoins.play(); | |
if (userInfo[4].firstChild.data.substr(0, 2) > Number(temperature)) | |
soundHotspot.play(); | |
} | |
} | |
} | |
}, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment