Text Extractor

Estrae il testo di una pagina web e lo salva in un file .txt

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Text Extractor
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Estrae il testo di una pagina web e lo salva in un file .txt
// @author       Magneto1
// @license      MIT
// @match        *://*/*
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    // Funzione per estrarre il testo dalla pagina e salvarlo in un file .txt
    function extractText() {
        const bodyText = document.body.innerText; // Estrae il testo dal corpo della pagina
        if (bodyText) {
            const blob = new Blob([bodyText], { type: 'text/plain' }); // Crea un blob di testo
            const url = URL.createObjectURL(blob); // Crea un URL per il blob
            const a = document.createElement('a'); // Crea un elemento <a> per il download
            a.href = url;
            a.download = 'estratto.txt'; // Nome del file di download
            document.body.appendChild(a); // Aggiungi l'elemento al DOM
            a.click(); // Simula un clic per avviare il download
            document.body.removeChild(a); // Rimuovi l'elemento dal DOM
            URL.revokeObjectURL(url); // Revoca l'URL per liberare risorse
            alert('Testo estratto e salvato in estratto.txt!');
        } else {
            alert('Nessun testo trovato nella pagina.');
        }
    }

    // Aggiungi un comando al menu di Violentmonkey per estrarre il testo
    GM_registerMenuCommand("Estrai Testo dalla Pagina", extractText);

    // Aggiungi un listener per la combinazione di tasti Ctrl + I
    document.addEventListener('keydown', (event) => {
        if (event.ctrlKey && event.key === 'i') {
            event.preventDefault(); // Previene l'azione predefinita
            extractText();
        }
    });
})();