From 4b4b65672cfb5d91eb8cb2880e6c70fc8233777f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=88=9A=28noham=29=C2=B2?= Date: Sun, 21 Jan 2024 18:04:22 +0100 Subject: [PATCH] 1.0 --- .gitattributes | 2 ++ .gitignore | 2 ++ background.js | 0 load.js | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 27 ++++++++++++++++++++ popup.html | 18 +++++++++++++ popup.js | 13 ++++++++++ test.py | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 198 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 background.js create mode 100644 load.js create mode 100644 manifest.json create mode 100644 popup.html create mode 100644 popup.js create mode 100644 test.py diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bea433 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +.DS_Store diff --git a/background.js b/background.js new file mode 100644 index 0000000..e69de29 diff --git a/load.js b/load.js new file mode 100644 index 0000000..a211902 --- /dev/null +++ b/load.js @@ -0,0 +1,68 @@ +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(); \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..4a03ff5 --- /dev/null +++ b/manifest.json @@ -0,0 +1,27 @@ +{ + "manifest_version": 3, + "name": "AnnabacPro", + "version": "1.0", + "description": "Débloque tous les articales sur Annabac gratuitement", + "permissions": [ + "activeTab", + "storage" + ], + "action": { + "default_popup": "popup.html", + "default_icon": { + "16": "images/icon16.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + } + }, + "background": { + "service_worker": "background.js" + }, + "content_scripts": [ + { + "matches": ["*://www.annabac.com/*"], + "js": ["load.js"] + } + ] +} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..afc75c4 --- /dev/null +++ b/popup.html @@ -0,0 +1,18 @@ + + + + + + + AnnabacPro + + + +

AnnabacPro

+ Fait par √(noham)² +
+ repo : AnnabacPro + + + + \ No newline at end of file diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..08b8790 --- /dev/null +++ b/popup.js @@ -0,0 +1,13 @@ +// popup.js + +document.addEventListener('DOMContentLoaded', function () { + var redirectButton1 = document.getElementById('redirectButton1'); + redirectButton1.addEventListener('click', function () { + window.open('https://nohamr.github.io', '_blank'); + }); + var redirectButton2 = document.getElementById('redirectButton2'); + redirectButton2.addEventListener('click', function () { + window.open('https://github.com/NohamR/AnnabacPro', '_blank'); + }); + }); + \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..7c00281 --- /dev/null +++ b/test.py @@ -0,0 +1,68 @@ +import requests +from bs4 import BeautifulSoup + +url = 'https://www.annabac.com/annales-bac/acidification-de-l-ocean' +response = requests.get(url, verify=False) + +if response.status_code == 200: + soup = BeautifulSoup(response.text, 'html.parser') + + inner_content = soup.find('div', class_='inner-content') + + if inner_content: + inner_content_text = ''.join(map(str, inner_content.contents)) + inner_content_text = inner_content_text.replace("/modules-assets/", "https://www.annabac.com/modules-assets/") + model = f""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sens d’évolution d’un système acide-base - Constitution et transformations de la matière - Physique | Annabac + + + + + +
+ {inner_content_text} +
+ + +""" + with open('filefiletest.html', 'w') as f: + f.write(model) + else: + print("Balise 'inner-content' non trouvée sur la page.") +else: + print(f"La requête a échoué avec le code d'état {response.status_code}.") \ No newline at end of file