function fetchAndModifyContent(url) { fetch(url) .then(response => { if (response.ok) { return response.text(); } throw new Error(`Failed to fetch: ${response.statusText}`); }) .then(html => { const parser = new DOMParser(); const doc = parser.parseFromString(html, 'text/html'); const innerContentMain = doc.querySelector('.inner-content-main'); const innerContent = innerContentMain.querySelector('.inner-content'); if (innerContent) { let innerContentText = Array.from(innerContent.childNodes) .map(node => node.outerHTML || node.nodeValue) .join(''); innerContentText = innerContentText.replace(/\/modules-assets\//g, "https://www.annabac.com/modules-assets/"); innerContentText = innerContentText.replace(/]*src="https:\/\/cdn\.mathjax\.org\/mathjax\/latest\/MathJax\.js\?config=TeX-AMS-MML_HTMLorMML"[^>]*><\/script>/g, ''); innerContentText = innerContentText.replace(/]*href="https:\/\/www\.annabac\.com\/modules-assets\/styles\/commonAnnabac2020\.css"[^>]*>/g, ''); innerContentText = innerContentText.replace(/]*href="https:\/\/www\.annabac\.com\/modules-assets\/styles\/9782401064171_metabase_Phy_Chim_Term\.css"[^>]*>/g, ''); assignContent(innerContentText); } else { console.log('Inner content not found'); } }) .catch(error => console.error(error)); } function assignContent(content) { const html = ` Viewer
${content}
`; console.log('page opened'); const newWindow = window.open(); newWindow.location.href = "about:blank"; newWindow.document.write(html); newWindow.document.close(); } // const currentUrl = window.location.href; // fetchAndModifyContent(currentUrl); function replaceLinks() { var links = document.querySelectorAll('.parcours-revision-inner a'); links.forEach(link => { var button = document.createElement('button'); button.textContent = link.textContent; button.addEventListener('click', function() { var url = link.href; fetchAndModifyContent(url); }); link.parentNode.replaceChild(button, link); }); } replaceLinks();