A userscript that allows you to visually select and download elements from web pages while preserving images, styles, and layout.
- Visual highlighting of page elements on hover
- Click to select specific elements
- Shift+Click to select multiple elements
- Selection panel showing all selected elements
- Ability to remove individual elements from selection
- Escape key to cancel selection
- Ability to capture nested elements
- Select multiple elements with Shift+Click
- Visual indicators showing selected elements
- Selection panel to manage selected elements
- Download all selected elements as a single HTML file
- Clear all selections with a single click
- Keyboard shortcuts:
C: Clear all selectionsD: Download selected elementsEscape: Exit selection mode
- Activate the Element Highlighter
- Hold Shift and click on elements to add them to selection
- Use the selection panel to:
- View all selected elements
- Remove specific elements
- Highlight individual elements
- Download all selected elements
- Clear all selections
- Converts relative image URLs to absolute
- Preserves image dimensions
- Handles
<picture>elements and srcset - Processes SVG elements with dimension preservation
- Extracts background images from CSS
- Maintains responsive image functionality
- Preserves essential styles:
- Layout (width, height, margin, padding)
- Text formatting (font-size, weight, alignment, color)
- Background colors
- Borders and border-radius
- Table formatting
- Flexbox properties
- Converts external CSS to inline styles
- Includes minimal base CSS for consistency
The script is organized into logical modules:
- Handles URL conversion from relative to absolute
- Processes different URL formats (data URIs, root-relative, etc.)
- Processes HTML elements for download
- Handles links, images, and styles
- Special processing for SVG elements
- Extracts background images from CSS
- Manages user interface elements
- Handles overlay creation and styling
- Creates and updates the selection panel
- Displays notifications to the user
- Manages the list of selected elements
- Handles adding and removing elements from selection
- Creates visual indicators for selected elements
- Highlights selected elements when requested
- Controls element highlighting functionality
- Manages mouse and keyboard interactions
- Toggles highlight mode on/off
- Coordinates multiple element selection
- Handles the actual element download
- Creates standalone HTML with preserved styling
- Downloads single elements or multiple elements
- Generates downloadable blobs
-
Install a userscript manager:
-
Install this script:
- Click the userscript manager icon
- Create new script
- Copy and paste the contents of
element-highlighter.user.js - Save the script
- Navigate to any webpage
- Click the userscript manager icon
- Select "Toggle Element Highlighter" from the menu
- Hover over elements to highlight them
- Click on an element to select and download it. Note that during highlighting, default browser text selection and context menu behaviors are prevented to ensure smooth element selection.
When the element highlighter is active, the default browser behavior of text selection using the Shift key and context menus are disabled to ensure seamless element selection.
Shift+Click: Add element to selection. Note: holding Shift key during highlighting will not trigger default browser text selection.C: Clear all selectionsD: Download all selected elementsEscape: Exit element selection mode
For single elements, the script generates a standalone HTML file containing:
- The selected element with all nested content
- Original page source URL in comments
- Timestamp of capture
- Simplified but functional CSS
- Absolute URLs for all images
- Preserved layout and formatting
For multiple elements, the output includes:
- All selected elements in a single HTML file
- Elements separated with clear headers
- Page metadata including source URL and capture time
- Print-friendly styling for documentation or reports
html_data_scrape/
├── element-highlighter.user.js # Main userscript
└── README.md # Documentation
Potential enhancements:
- Additional image format support
- Enhanced CSS preservation
- Customizable style retention
- Custom keyboard shortcuts
- Settings panel for configuration
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
MIT License - See LICENSE file for details
ExactDoug (http://exactpartners.com/)
- 0.5 - Multiple element selection with selection management panel
- 0.4 - Code organization into logical modules with improved documentation
- 0.3 - CSS handling and simplification
- 0.2 - Enhanced image processing
- 0.1 - Initial release with basic functionality