Skip to content

tizee-tampermonkey-scripts/tampermonkey-zhihu-copy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Zhihu Answer Copy - Tampermonkey Script

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.

Features

  • 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

Installation

Prerequisites

  • Tampermonkey browser extension (Chrome, Firefox, Safari, Edge)

Installation Steps

Option 1: Direct Installation (Recommended)

  1. Install Tampermonkey extension for your browser
  2. Click this link to install the script
  3. Confirm the installation in Tampermonkey

Option 2: Manual Installation

  1. Install Tampermonkey extension for your browser
  2. Open Tampermonkey dashboard
  3. Click "Create a new script"
  4. Copy and paste the contents of user.js into the editor
  5. Save the script (Ctrl+S or Cmd+S)

Option 3: GitHub Installation

  1. Clone or download this repository
  2. Open Tampermonkey dashboard
  3. Click "Utilities" tab
  4. Under "Install from a URL", paste: https://raw.githubusercontent.com/tizee-tampermonkey-scripts/tampermonkey-zhihu-copy/main/user.js
  5. Click "Install"

Usage

  1. Navigate to Zhihu or any question page
  2. Look for the copy button (📋 icon) next to each answer's action buttons
  3. Click the copy button to copy the answer content
  4. The button will briefly show a green checkmark (✓) to confirm successful copying
  5. Paste the content wherever needed - it will include both formatted HTML and plain text versions

How It Works

The script operates by:

  1. Detection: Identifies answer containers on Zhihu pages using CSS selectors
  2. Injection: Adds a custom copy button to each answer's action group
  3. Content Processing: Extracts and processes answer content while preserving:
    • Text formatting (bold, italic, etc.)
    • Link URLs and styling
    • Paragraph structure
  4. Clipboard Operations: Uses the modern Clipboard API to copy both HTML and plain text formats
  5. Dynamic Updates: Uses MutationObserver to handle newly loaded answers as users scroll

Compatibility

  • Supported Sites: zhihu.com question pages and homepage
  • Supported Browsers: Chrome, Firefox, Safari, Edge (with Tampermonkey)
  • Requirements: Modern browser with Clipboard API support

Technical Details

File Structure

tampermonkey-zhihu-answer-copy/
├── user.js          # Main Tampermonkey script
├── LICENSE          # MIT License
└── README.md        # This documentation

Key Components

  • 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

Code Architecture

  • 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

Security and Privacy

  • 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

Development

Local Development

  1. Clone the repository
  2. Make changes to user.js
  3. Install the local version in Tampermonkey for testing
  4. Test on Zhihu question pages

Building for Distribution

The script is ready for distribution as-is. No build process required.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly on Zhihu
  5. Submit a pull request

Troubleshooting

Common Issues

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

Debug Mode

Enable Tampermonkey's debug mode to see detailed logs in the browser console.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

v1.0.0

  • Initial release
  • Basic copy functionality for Zhihu answers
  • Visual feedback with checkmark animation
  • Support for dynamic content loading
  • Preservation of HTML formatting and links

Support

For bug reports, feature requests, or questions:

  • Open an issue on GitHub
  • Check existing issues before creating new ones

Related Projects

About

copy zhihu answer quickly

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published