Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- /**
- * Wait for an element before resolving a promise
- * @param {String} querySelector - Selector of element to wait for
- * @param {Integer} timeout - Milliseconds to wait before timing out, or 0 for no timeout
- */
- function waitForElement(querySelector, timeout){
- return new Promise((resolve, reject)=>{
- var timer = false;
- if(document.querySelectorAll(querySelector).length) return resolve();
- const observer = new MutationObserver(()=>{
- if(document.querySelectorAll(querySelector).length){
- observer.disconnect();
- if(timer !== false) clearTimeout(timer);
- return resolve();
- }
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- if(timeout) timer = setTimeout(()=>{
- observer.disconnect();
- reject();
- }, timeout);
- });
- }
- waitForElement("#category", 15000).then(function(){
- document.querySelector("#category > div > div:nth-child(4) > button").setAttribute("onclick","location.href = '/declaration-sinistre/';");
- }).catch(()=>{
- console.log("element did not load in 15 seconds");
- });
- waitForElement("#nextBtn", 15000).then(function(){
- document.getElementById("nextBtn").onclick = function(event) {
- if (document.querySelector("#category > div > div:nth-child(4) > button").classList.contains('border-themeColor')) {
- window.location ='/declaration-sinistre/';
- event.preventDefault();
- return false;
- }
- }
- }).catch(()=>{
- console.log("element did not load in 15 seconds");
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment