Last active
February 5, 2020 17:29
-
-
Save Gummibeer/50fd5abb64b50b098a4551ef73b4e8ab to your computer and use it in GitHub Desktop.
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
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