Skip to content

Instantly share code, notes, and snippets.

@PhompAng
Forked from kmxz/run-in-browser-console.js
Last active August 3, 2021 13:30
Show Gist options
  • Save PhompAng/10076b7789593462ef5438a80410a242 to your computer and use it in GitHub Desktop.
Save PhompAng/10076b7789593462ef5438a80410a242 to your computer and use it in GitHub Desktop.
Script to add to gartic.io
const setNativeValue = (element, value) => {
const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set;
const prototype = Object.getPrototypeOf(element);
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set;
if (valueSetter && valueSetter !== prototypeValueSetter) {
prototypeValueSetter.call(element, value);
} else {
valueSetter.call(element, value);
}
element.dispatchEvent(new Event('input', { bubbles: true }));
};
const main = src => {
const words = src.split('\n').filter(_ => _).map(_ => _.trim()).filter((v, i, a) => a.indexOf(v) === i);
const $input = document.querySelector('#screens > div > div.content.bg.createTheme > div.globalSettings > div:nth-child(3) > form > div:nth-child(1) > label.text > input[type="text"]');
const $difficulties = ['easy', 'medium', 'hard'].map(id => document.getElementById(id));
const $btAdd = document.querySelector('#screens > div > div.content.bg.createTheme > div.globalSettings > div:nth-child(3) > form > div:nth-child(1) > label.btAdd > input');
let i = 0;
const doSingle = () => {
if (i >= words.length) { window.alert('All done!'); return; }
const entry = words[i];
setNativeValue($input, entry)
$difficulties[0].click();
setTimeout(() => {
$btAdd.click();
i++;
setTimeout(doSingle, 150);
}, 150);
};
doSingle();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment