Skip to content

Instantly share code, notes, and snippets.

@chengluyu
Created April 29, 2021 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chengluyu/dee70e6c165c6864e2b7440e155044a3 to your computer and use it in GitHub Desktop.
Save chengluyu/dee70e6c165c6864e2b7440e155044a3 to your computer and use it in GitHub Desktop.
Chia Blockchain Force Connection
'use strict';
(function () {
const root = document.querySelectorAll('.MuiPaper-root > .MuiCardContent-root > .MuiBox-root')[2];
const urls = [
'node-eu.chia.net',
'node.chia.net',
'node-apne.chia.net',
'node-or.chia.net'
];
let current = 0;
window.forceConnection = setInterval(() => {
if (canRun()) {
const url = nextUrl();
console.log(`Force connect ${url}`)
forceConnection(url);
} else {
console.log('Cannot run. :-(');
}
}, 3000);
function nextUrl() {
const url = urls[current];
current += 1;
if (current >= urls.length) {
current = 0;
}
return url;
}
function forceConnection(url) {
if (root.innerHTML.indexOf(url) < 0) {
console.log(`${url} is not in the list. :-(`);
addConnection(url);
} else {
console.log(`${url} is in the list. :-)`);
}
}
function addConnection(url) {
let buttons = document.querySelectorAll('.MuiBox-root .MuiButtonBase-root .MuiButton-label');
buttons = [...buttons].filter(x => x.innerHTML.indexOf('peers') >= 0);
buttons[0].click();
setInput(document.querySelector('input[name="host"]'), url);
setInput(document.querySelector('input[name="port"]'), "8444");
let submit = document.querySelector('.MuiDialogActions-root button[type="submit"]');
submit.click();
console.log(`Submitted! :-)`)
function setInput(input, text) {
var setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
setter.call(input, text);
var ev2 = new Event('input', { bubbles: true });
input.dispatchEvent(ev2);
}
}
function canRun() {
const overlay = document.querySelector('.MuiBackdrop-root');
return overlay.style.opacity == 0;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment