Skip to content

Instantly share code, notes, and snippets.

@ajorpheus
Last active August 17, 2022 12:11
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 ajorpheus/047bef282505e35e5881acec9fafca09 to your computer and use it in GitHub Desktop.
Save ajorpheus/047bef282505e35e5881acec9fafca09 to your computer and use it in GitHub Desktop.
// Following grants are needed for some of the functions below to function
// @grant GM_openInTab
// @grant GM_xmlhttpRequest
// @grant GM_notification
function log_noti_simple(text, timeout = 2000) {
console.log(`Running "${GM_info.script.name}"`)
// Timeout should be at least 1 second (1000ms) for it to be useful
timeout = timeout < 1000 ? 1000 : timeout;
GM_notification({
title: `${GM_info.script.name}`,
text: text,
timeout: timeout,
onclick: () => {
console.log("My notice was clicked.");
window.focus();
}
})
}
function processJSON_Response(response) {
console.log('Received response');
console.log([
response.status,
response.statusText,
response.readyState,
response.responseHeaders,
response.responseText,
response.finalUrl
].join("\n"));
}
function reportAJAX_Error(rspObj) {
console.error(`TM scrpt => Error ${rspObj.status}! ${rspObj.statusText}`);
}
function curl(apiURL) {
GM_xmlhttpRequest({
method: "GET",
url: apiURL,
responseType: "text",
onload: processJSON_Response,
onabort: reportAJAX_Error,
onerror: reportAJAX_Error,
ontimeout: reportAJAX_Error
});
}
function callMacro(jNode, macroLocation) {
log_noti_simple("Calling macro");
console.log("Calling macro for " + window.location + " for jNode " + jNode)
//GM_openInTab(macroLocation);
curl(macroLocation)
}
function clickIt(jNode){
//alert("I am going to click it");
jNode.click()
}
function hrefClick(jNode){
//alert("I am going to click it");
window.location = jNode.attr('href')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment