Universal Text Selection Persistence Across Reload
Free to download on every platform. Comes pre-installed on BotFone, BotPad and BotFlip — with extra free apps included.
About this app
WHAT IT DOES
This script detects when you select text on a page and saves the selection range—start and end positions, container element, and surrounding context—to local storage. On page reload or navigation, the script restores the previous text selection, highlighting the exact same text that was selected before. A floating panel shows the current selection status, the saved selection text, and controls to clear the selection or toggle auto-restore. A visual badge appears in the corner when a selection is saved, indicating that text has been persisted. You can manually save selections, clear them, and export saved selections as text. All selection data is stored per domain for reuse across visits.
WHERE IT RUNS
Works on any webpage with selectable text—articles, documentation, emails, forums, or any content-rich site. The script captures text selections using the Selection API and restores them using range restoration, making it compatible with most modern websites.
HOW TO USE
The panel appears automatically when you visit a page. Select any text on the page, then click "Save Current Selection" to store it. A badge appears in the corner showing a preview of the saved text—click it to open the panel. The panel shows the saved selection with a timestamp and character count. Click "Restore Selection" to re-select the saved text on the current page. Click "Copy Selection Text" to copy the saved selection to your clipboard. Use "Clear Saved Selection" to remove the stored selection. Toggle "Auto-restore on page load" to automatically restore the selection whenever you reload or revisit the page. The badge updates dynamically when selections are saved or cleared.
TECHNICAL MECHANISM: SELECTION CAPTURE WITH RANGE PERSISTENCE AND ELEMENT PATH RESOLUTION
The script uses the Selection API (window.getSelection()) to capture the current selection range, including the anchor node, focus node, and offsets. It extracts the common ancestor container and builds a stable path for the container element using one of two strategies: if the element has an ID, it uses the ID selector; otherwise, it constructs a path using tag names and sibling indices (e.g., "body > div > p[2] > span"). The selection data is stored in GM_setValue per domain with a timestamp. On restore, the script resolves the container element using the stored path, traverses text nodes within the container, and calculates the start and end offsets by walking through text nodes until the stored offsets are reached. The restore creates a new Range object and sets it as the current selection using window.getSelection().removeAllRanges() and addRange(). The badge is a fixed-position element that appears when a selection is stored, showing a truncated preview of the selected text. The auto-restore feature triggers on page load (with a 500ms delay to allow the page to render).
THE PANEL
The text selection persistence panel appears in a draggable, resizable panel that remembers its position per site. The panel shows the selection status, saved selection text with timestamp and length, and action buttons. Drag by the header to reposition, collapse to a compact icon with a click, and resize using the bottom-right corner. The panel snaps to screen edges for tidy placement and closes with the Escape key. All settings—auto-restore toggle and panel position—persist per website using GM_setValue, so your view returns exactly as you left it.
PLEASE NOTE
This script requires the free BotGentz extension to run. The selection restoration relies on the page structure remaining the same after reload—if the page content changes dynamically, the stored selection may not be restorable. The container path uses tag names and indices, which may not be stable on pages with dynamic content. The script does not store selections automatically on selection change—you must click "Save Current Selection" to persist it. The badge is a visual indicator that a selection is saved; clicking it opens the panel. All selection data is stored locally in your browser via GM_setValue and never transmitted. The script ignores selections in input fields and textareas to avoid saving sensitive data.