Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aktentasche/9490e93e0011dd96aa69b1f6241a6ce2 to your computer and use it in GitHub Desktop.
Save aktentasche/9490e93e0011dd96aa69b1f6241a6ce2 to your computer and use it in GitHub Desktop.
robo seiten txt download
// ==UserScript==
// @name Webseitentext runterladen
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Download only human-readable text from any webpage as a TXT file
// @author You
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function downloadReadableText() {
const allTextSet = new Set(); // Using a set to avoid duplicates
const elements = document.querySelectorAll('p, li, td, th, h1, h2, h3, h4, h5, h6, caption, span, a');
elements.forEach(element => {
if (isVisible(element)) {
let text = element.textContent || '';
text = text.replace(/\s+/g, ' ').trim(); // Normalize whitespace and trim
if (text) {
allTextSet.add(text);
}
}
});
// Convert Set back to an array and combine into one string, separated by new lines
const allText = Array.from(allTextSet).join("\n");
// Create a Blob with the text data
const blob = new Blob([allText], {type: 'text/plain'});
// Create a link element for downloading
const link = document.createElement("a");
const url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", document.title.replace(/[^a-z0-9]/gi, '_').toLowerCase() + ".txt"); // Sanitize filename
document.body.appendChild(link);
link.click();
// Clean up by revoking the Blob URL and removing the link
URL.revokeObjectURL(url);
document.body.removeChild(link);
}
function isVisible(el) {
const style = window.getComputedStyle(el);
return style && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0';
}
// Add a button to download the page text
const button = document.createElement("button");
button.textContent = "Seite als Text herunterladen";
button.style.position = "fixed";
button.style.bottom = "20px";
button.style.right = "20px";
button.style.zIndex = "1000";
document.body.appendChild(button);
button.onclick = downloadReadableText;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment