loranloran

Pour LeTram - gestion des sinistres (v2)

Nov 3rd, 2022 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.    
  3. /**
  4.  * Wait for an element before resolving a promise
  5.  * @param {String} querySelector - Selector of element to wait for
  6.  * @param {Integer} timeout - Milliseconds to wait before timing out, or 0 for no timeout              
  7.  */
  8. function waitForElement(querySelector, timeout){
  9.   return new Promise((resolve, reject)=>{
  10.     var timer = false;
  11.     if(document.querySelectorAll(querySelector).length) return resolve();
  12.     const observer = new MutationObserver(()=>{
  13.       if(document.querySelectorAll(querySelector).length){
  14.         observer.disconnect();
  15.         if(timer !== false) clearTimeout(timer);
  16.         return resolve();
  17.       }
  18.     });
  19.     observer.observe(document.body, {
  20.       childList: true,
  21.       subtree: true
  22.     });
  23.     if(timeout) timer = setTimeout(()=>{
  24.       observer.disconnect();
  25.       reject();
  26.     }, timeout);
  27.   });
  28. }
  29.  
  30. waitForElement("#category", 15000).then(function(){
  31.       document.querySelector("#category > div > div:nth-child(4) > button").setAttribute("onclick","location.href = '/declaration-sinistre/';");
  32. }).catch(()=>{
  33.     console.log("element did not load in 15 seconds");
  34. });
  35.  
  36. waitForElement("#nextBtn", 15000).then(function(){
  37.     document.getElementById("nextBtn").onclick = function(event) {
  38.         if (document.querySelector("#category > div > div:nth-child(4) > button").classList.contains('border-themeColor')) {
  39.             window.location ='/declaration-sinistre/';
  40.             event.preventDefault();
  41.             return false;
  42.         }
  43.     }
  44. }).catch(()=>{
  45.   console.log("element did not load in 15 seconds");
  46. });
  47. </script>
Advertisement
Add Comment
Please, Sign In to add comment