diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b4e4164 --- /dev/null +++ b/.gitignore @@ -0,0 +1,131 @@ +# Editors +.vscode/ +.idea/ + +# Vagrant +.vagrant/ + +# Mac/OSX +.DS_Store + +# Windows +Thumbs.db + +# Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +dist_chrome/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# node +node_modules/ + +test/ \ No newline at end of file diff --git a/background.js b/background.js new file mode 100644 index 0000000..e69de29 diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 0000000..f86c012 Binary files /dev/null and b/images/icon.png differ diff --git a/images/icon128.png b/images/icon128.png new file mode 100644 index 0000000..8b9e4d4 Binary files /dev/null and b/images/icon128.png differ diff --git a/images/icon16.png b/images/icon16.png new file mode 100644 index 0000000..21df161 Binary files /dev/null and b/images/icon16.png differ diff --git a/images/icon48.png b/images/icon48.png new file mode 100644 index 0000000..bafb384 Binary files /dev/null and b/images/icon48.png differ diff --git a/load.js b/load.js new file mode 100644 index 0000000..3010c59 --- /dev/null +++ b/load.js @@ -0,0 +1,124 @@ +// function fetchContent(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'); + +// // Get the content of the script tag with id "kartable-state" +// const scriptElement = doc.getElementById('kartable-state'); +// if (scriptElement) { +// const scriptContent = JSON.parse(scriptElement.textContent); + +// // List every key in scriptContent +// const keys = Object.keys(scriptContent); + +// // Check if there is a key at index 8 +// if (keys.length > 8) { +// const keyAtIndex8 = keys[8]; +// const contentAtIndex8 = scriptContent[keyAtIndex8]; +// console.log(contentAtIndex8); +// return contentAtIndex8 +// } else { +// console.error('Key at index 8 not found in scriptContent'); +// } +// } else { +// console.error('Script with id "kartable-state" not found'); +// } +// }) +// .catch(error => console.error(error)); +// } + +// fetchContent(window.location.href); + + +// window.onload = function() { +// replaceArticles(); +// console.log('done') +// }; + + +window.onload = function() { + setTimeout(function() { + replaceArticles(); + }, 3000); +}; + + +function opener(url) { + console.log(url); + + const match = url.match(/(\d+)$/); + + if (match) { + const number = match[0]; + console.log('Nombre à la fin de l\'URL :', number); + + fetch(`https://www.kartable.fr/ressources/a/a/a/${number}`) + .then(response => { + if (response.ok) { + return response.text(); + } + throw new Error(`Failed to fetch: ${response.statusText}`); + }) + .then(html => { + const newWindow = window.open(); + newWindow.location.href = "about:blank"; + newWindow.document.write(html); + newWindow.document.close(); + }) + .catch(error => console.error(error)); + } else { + console.log('Aucun nombre trouvé à la fin de l\'URL.'); + } +} + +function replaceArticles() { + var articles = document.querySelectorAll('.document-list__item'); + + articles.forEach(function (article) { + var titleElement = article.querySelector('.document-list__title'); + + if (titleElement) { + var articleText = titleElement.textContent; + var button = document.createElement('button'); + button.textContent = articleText; + + button.addEventListener('click', function () { + var link = titleElement.getAttribute('href'); + + if (link) { + opener(link); + } + }); + + article.parentNode.replaceChild(button, article); + console.log('done'); + } + }); + + + var articles = document.querySelectorAll('.document-readable'); + + articles.forEach(function (article) { + var articleText = article.querySelector('h3').textContent; + var button = document.createElement('button'); + button.textContent = articleText; + + button.addEventListener('click', function () { + var link = article.querySelector('h3 a'); + + if (link) { + opener(link.href); + } + }); + + article.parentNode.replaceChild(button, article); + console.log('done'); + }); +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..b529834 --- /dev/null +++ b/manifest.json @@ -0,0 +1,28 @@ +{ + "manifest_version": 3, + "name": "KartablePro", + "version": "1.0", + "description": "Débloque tous les articles sur Kartable gratuitement", + "permissions": [ + "activeTab", + "storage", + "tabs" + ], + "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.kartable.fr/*"], + "js": ["load.js"] + } + ] +} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..bab9efc --- /dev/null +++ b/popup.html @@ -0,0 +1,18 @@ + + + +
+ + +