1const formObserver = new MutationObserver((mutations) => { 2 mutations.forEach((mutation) => { 3 if (mutation.addedNodes) { 4 for (const node of mutation.addedNodes) { 5 const match = node instanceof Element && (node.querySelector("form") || node.nodeName == 'FORM'); 6 7 if (match) { 8 if(node.nodeName == 'FORM' && !node.matches('[data-token-handler-added]') && !node.classList.contains('olb-form')) { 9 addTokenSubmitEvent(node); 10 } else { 11 node.querySelectorAll('form:not([data-token-handler-added]):not(.olb-form)').forEach(form => addTokenSubmitEvent(form)); 12 } 13 14 break; 15 } 16 }; 17 } 18 }); 19}); 20 21function addTokenSubmitEvent(form){ 22 form.addEventListener('submit', formSubmitHandler, true); 23 form.dataset.tokenHandlerAdded = true; 24} 25 26// Start observing the DOM 27formObserver.observe(document, { childList: true, subtree: true }); 28 29document.addEventListener("DOMContentLoaded", function() { 30 if(showRequestErrorMsg === true){ 31 let container = document.querySelectorAll('main.content .container').item(0); 32 let tempDiv = document.createElement('div'); 33 34 tempDiv.innerHTML = '<div class="relative" style="z-index: 1;"><div class="message error">Unable to authenticate request. Please try again.</div></div>'; 35 container.insertBefore(tempDiv.firstElementChild, container.firstElementChild); 36 } 37}); 38 39const formSubmitHandler = async function (evt) { 40 if(this.dataset.submitted == null){ 41 evt.preventDefault(); 42 evt.stopImmediatePropagation(); 43 44 try{ 45 let tokenObj = await getFormTokenJS(); 46 let newToken = tokenObj.token; 47 let tokenInputId = tokenObj.inputId; 48 49 let tempDiv = document.createElement('div'); 50 tempDiv.innerHTML = '<input type="hidden" class="' + tokenInputId + '" name="' + tokenInputId + '" value="' + newToken + '">'; 51 let tokenInput = tempDiv.firstElementChild; 52 53 this.querySelectorAll(':scope > .' + tokenInputId).forEach(elem => elem.remove()); 54 this.insertBefore(tokenInput, this.firstElementChild); 55 56 this.dataset.submitted = true; 57 58 this.requestSubmit(); 59 } catch(error) { 60 this.querySelectorAll('input[type=submit]').item(0).value = 'Submit'; 61 this.querySelectorAll('input[type=submit]').item(0).disabled = false; 62 alert(error); 63 return false; 64 } 65 } 66} 67 68async function getFormTokenJS(){ 69 var newToken = ''; 70 71 try { 72 let response = await fetch('/ajax/getToken.php', { 73 method: 'GET', 74 cache: 'no-cache', 75 priority: 'high', 76 headers: { 77 'X-Requested-With': 'xmlhttprequest' 78 } 79 }); 80 81 var data = await response.json(); 82 newToken = data.token; 83 84 return { 85 inputId: tokenParamName, 86 token: newToken 87 } 88 } catch (error){ 89 console.log('Could not retrieve token'); 90 console.log(error); 91 92 throw new Error('Unable to authenticate request. Please try again.'); 93 } 94}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.