Skip to content

Instantly share code, notes, and snippets.

@Gummibeer
Last active February 5, 2020 17:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gummibeer/50fd5abb64b50b098a4551ef73b4e8ab to your computer and use it in GitHub Desktop.
Save Gummibeer/50fd5abb64b50b098a4551ef73b4e8ab to your computer and use it in GitHub Desktop.
function waitForElement(selector) {
return new Promise(function(resolve, reject) {
var runs = 1;
var interval = setInterval(function() {
if (runs >= 30) {
clearInterval(interval);
reject(new Error('max runs exceeded'));
}
var el = document.querySelector(selector);
if (typeof(el) !== 'undefined' && el !== null) {
clearInterval(interval);
resolve(el);
}
runs++;
}, 500);
}).catch(console.error);
};
function init() {
waitForElement('button[data-test-selector="download-button"]').then(function(el1) {
el1.click();
return waitForElement('label[for="project-option-0"]').then(function(el2) {
el2.click();
return waitForElement('button[data-test-selector="project-add-and-download-button"]').then(function(el3) {
el3.click();
setTimeout(function() {
window.close();
}, 1000 * 30);
});
});
});
}
try {
init();
} catch (e) {
init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment