Last active
May 6, 2018 09:02
-
-
Save GHolk/699c7b42d02e9dfd1c8f9af011f1eef1 to your computer and use it in GitHub Desktop.
read evaluate print loop of grease monkey environment
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 greasy monkey repl | |
// @description read evaluate print loop of grease monkey environment | |
// @namespace http://gholk.github.io/ | |
// @version 4 | |
// @match * | |
// @grant GM.info | |
// @grant GM.deleteValue | |
// @grant GM.getValue | |
// @grant GM.listValues | |
// @grant GM.setValue | |
// @grant GM.getResourceUrl | |
// @grant GM.notification | |
// @grant GM.openInTab | |
// @grant GM.setClipboard | |
// @grant GM.xmlHttpRequest | |
// @grant unsafeWindow | |
// ==/UserScript== | |
async function repl() { | |
let result = 'input javascript code' | |
while (true) { | |
const expression = prompt(result) | |
result = await eval(expression) | |
await sleep(0) | |
} | |
} | |
function xmlHttpRequestPromise(url, option) { | |
return new Promise(resolve => { | |
const newOption = {url, onload, ...option} | |
if (!newOption.method) newOption.method = 'GET' | |
GM.xmlHttpRequest(newOption) | |
function onload(response) { | |
resolve(response) | |
} | |
}) | |
} | |
function sleep(second) { | |
return new Promise(wake => setTimeout(wake, second * 1000)) | |
} | |
repl() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment