Skip to content

Instantly share code, notes, and snippets.

@GHolk
Last active May 6, 2018 09:02
Show Gist options
  • Save GHolk/699c7b42d02e9dfd1c8f9af011f1eef1 to your computer and use it in GitHub Desktop.
Save GHolk/699c7b42d02e9dfd1c8f9af011f1eef1 to your computer and use it in GitHub Desktop.
read evaluate print loop of grease monkey environment
// ==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