Skip to content

Instantly share code, notes, and snippets.

@thesved
Last active September 5, 2020 08:11
Show Gist options
  • Save thesved/c626461209d26317326dcaf346f80a1f to your computer and use it in GitHub Desktop.
Save thesved/c626461209d26317326dcaf346f80a1f to your computer and use it in GitHub Desktop.
chrome.extension.sendMessage({}, function(response) {
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
clearInterval(readyStateCheckInterval);
var actions = [
[function(){return clickNode('.bp3-icon-more', '')}, 10],
[function(){return clickNode('a.bp3-menu-item', 'Export All')}, 10],
[function(){return clickNode('.bp3-dialog .bp3-button', 'Markdown')}, 10],
[function(){return clickNode('.bp3-dialog a.bp3-menu-item', 'JSON')}, 10],
[function(){return clickNode('.bp3-dialog .bp3-button', 'Export All')}, 1000],
[function(){return domCheck('.bp3-spinner-animation')}, 500],
[function(){console.log('DONE!!!!'); return true;}, 0]
];
var clicks;
document.addEventListener('keypress', ev => {
if (ev.code == "KeyS" && ev.ctrlKey && !ev.altKey) {
console.log("CTRL + S pressed");
clicks = [...actions];
rotate();
}
});
// rotating through actions
function rotate() {
if (clicks.length == 0) return;
var sleep = clicks[0][1];
if (clicks[0][0]()) {
clicks.shift();
}
setTimeout(rotate, sleep);
}
// click a node
function clickNode(selector, text){
var element;
if (text) {
element = Array.from(document.querySelectorAll(selector)).filter(v=>{ return v.innerText == text });
} else {
element = [document.querySelector(selector)].filter(v=>v);
}
if (element.length > 0) {
element[0].click();
return true;
}
return false;
}
// check if a node is present
function domCheck(selector) {
if (document.querySelector(selector)) {
return false;
}
return true;
}
}
}, 10);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment