Text Highlighter

Evidenzia il testo su una pagina web

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Text Highlighter
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Evidenzia il testo su una pagina web
// @author       Magneto1
// @license      MIT
// @match        *://*/*
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// ==/UserScript==

(function() {
    'use strict';

    // Aggiungi uno stile per l'evidenziazione
    GM_addStyle(`
        .highlight {
            background-color: yellow;
            cursor: pointer;
        }
    `);

    // Funzione per evidenziare il testo selezionato
    const highlightSelectedText = () => {
        const selection = window.getSelection();
        if (selection.rangeCount > 0) {
            const range = selection.getRangeAt(0);
            const span = document.createElement('span');
            span.className = 'highlight';
            range.surroundContents(span);
            saveHighlights();
        }
    };

    // Funzione per salvare le evidenziazioni nel localStorage
    const saveHighlights = () => {
        const highlights = document.querySelectorAll('.highlight');
        const highlightArray = Array.from(highlights).map(highlight => highlight.innerText);
        localStorage.setItem('highlights', JSON.stringify(highlightArray));
    };

    // Funzione per caricare le evidenziazioni dal localStorage
    const loadHighlights = () => {
        const highlights = JSON.parse(localStorage.getItem('highlights')) || [];
        highlights.forEach(text => {
            const regex = new RegExp(text, 'g');
            document.body.innerHTML = document.body.innerHTML.replace(regex, `<span class="highlight">${text}</span>`);
        });
    };

    // Carica le evidenziazioni all'avvio
    loadHighlights();

    // Aggiungi un comando al menu di Violentmonkey per evidenziare il testo
    GM_registerMenuCommand("Evidenzia Testo Selezionato", highlightSelectedText);
})();