A Tampermonkey userscript that adds a "Copy" button to each answer on Zhihu, allowing users to easily copy answer content along with its URL. The script preserves formatting and styling while providing a smooth user experience with visual feedback.
- One-click copying: Adds intuitive copy buttons to every answer
- Rich content preservation: Maintains HTML formatting and styling when copying
- URL inclusion: Automatically includes the answer URL for proper attribution
- Visual feedback: Shows animated checkmark confirmation after successful copy
- Dynamic support: Works with both existing and dynamically loaded answers
- Minimal UI: Clean, unobtrusive design that blends with Zhihu's interface
- Tampermonkey browser extension (Chrome, Firefox, Safari, Edge)
- Install Tampermonkey extension for your browser
- Click this link to install the script
- Confirm the installation in Tampermonkey
- Install Tampermonkey extension for your browser
- Open Tampermonkey dashboard
- Click "Create a new script"
- Copy and paste the contents of
user.jsinto the editor - Save the script (Ctrl+S or Cmd+S)
- Clone or download this repository
- Open Tampermonkey dashboard
- Click "Utilities" tab
- Under "Install from a URL", paste:
https://raw.githubusercontent.com/tizee-tampermonkey-scripts/tampermonkey-zhihu-copy/main/user.js - Click "Install"
- Navigate to Zhihu or any question page
- Look for the copy button (📋 icon) next to each answer's action buttons
- Click the copy button to copy the answer content
- The button will briefly show a green checkmark (✓) to confirm successful copying
- Paste the content wherever needed - it will include both formatted HTML and plain text versions
The script operates by:
- Detection: Identifies answer containers on Zhihu pages using CSS selectors
- Injection: Adds a custom copy button to each answer's action group
- Content Processing: Extracts and processes answer content while preserving:
- Text formatting (bold, italic, etc.)
- Link URLs and styling
- Paragraph structure
- Clipboard Operations: Uses the modern Clipboard API to copy both HTML and plain text formats
- Dynamic Updates: Uses MutationObserver to handle newly loaded answers as users scroll
- Supported Sites: zhihu.com question pages and homepage
- Supported Browsers: Chrome, Firefox, Safari, Edge (with Tampermonkey)
- Requirements: Modern browser with Clipboard API support
tampermonkey-zhihu-answer-copy/
├── user.js # Main Tampermonkey script
├── LICENSE # MIT License
└── README.md # This documentation
- SVG Icons: Custom copy and checkmark icons designed to match Zhihu's aesthetic
- CSS Styling: Smooth transitions and hover effects for good UX
- Content Processing: Preserves rich text formatting while extracting clean content
- Error Handling: Graceful fallbacks for clipboard access issues
- Modular Design: Clean separation of concerns with dedicated functions
- Event Handling: Efficient mutation observers for dynamic content
- Performance: Minimal impact on page performance and memory usage
- No Data Collection: The script does not send any data to external servers
- Local Processing: All content processing happens locally in your browser
- Clipboard Access: Only accesses clipboard when you explicitly click the copy button
- Minimal Permissions: Only requests necessary permissions for DOM manipulation
- Clone the repository
- Make changes to
user.js - Install the local version in Tampermonkey for testing
- Test on Zhihu question pages
The script is ready for distribution as-is. No build process required.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly on Zhihu
- Submit a pull request
Script not working:
- Ensure Tampermonkey is enabled
- Check if the script is enabled in Tampermonkey dashboard
- Refresh the Zhihu page
Copy button not appearing:
- Check browser console for errors (F12 → Console)
- Ensure you're on a supported page (question pages or homepage)
- Try refreshing the page
Clipboard access denied:
- Ensure your browser allows clipboard access
- Check browser permissions for the site
Enable Tampermonkey's debug mode to see detailed logs in the browser console.
This project is licensed under the MIT License - see the LICENSE file for details.
- Initial release
- Basic copy functionality for Zhihu answers
- Visual feedback with checkmark animation
- Support for dynamic content loading
- Preservation of HTML formatting and links
For bug reports, feature requests, or questions:
- Open an issue on GitHub
- Check existing issues before creating new ones
- Tampermonkey - The userscript manager