Force Magnet Link Redirect to Parallels

Rewrites all magnet: links to openmagnet:// URLs for handling via a custom macOS Automator or Parallels app

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

作者
sharmanhall
日安装量
0
总安装量
3
评分
0 0 0
版本
1.1
创建于
2025-06-17
更新于
2025-06-17
大小
3.0 KB
许可证
MIT
适用于
所有网站

Force Magnet Link Redirect to Parallels

Description

This userscript automatically rewrites all magnet: links on any webpage into openmagnet:// links, which are handled by a custom Automator app on macOS. This allows you to seamlessly forward torrent downloads to qBittorrent or any other torrent client running inside a Parallels virtual machine.

How It Works

  • Automatic Link Rewriting: All <a href="magnet:..."> links are converted to openmagnet://?url=ENCODED_MAGNET_LINK
  • Custom URL Scheme: macOS recognizes openmagnet:// as a custom protocol and launches your designated Automator app
  • Dynamic Detection: Uses MutationObserver to catch magnet links that are added to the page after initial load
  • No Popup Interference: Sets target="_self" to prevent popup blocker issues

Features

  • Works on all websites automatically
  • Handles dynamically loaded content
  • Lightweight and fast
  • No elevated privileges required
  • Compatible with Tampermonkey, Violentmonkey, and Greasemonkey

macOS Setup Instructions

Step 1: Create the Automator App

  1. Open Automator on macOS
  2. Create a new Application
  3. Add a Run Shell Script action
  4. Set "Pass input" to as arguments
  5. Replace the default script with:
#!/bin/bash
# Extract magnet link from the custom URL scheme
MAGNET_URL="$1"
MAGNET=$(echo "$MAGNET_URL" | sed -E 's/^.*url=//' | python3 -c 'import sys, urllib.parse as u; print(u.unquote(sys.stdin.read()))')

# Path to your Parallels-based torrent app (update this path!)
APP_PATH="/Applications/Parallels Desktop.app/Contents/SharedApplications/qBittorrent.app"

# Launch the torrent app with the magnet link
open -a "$APP_PATH" --args "$MAGNET"
  1. Important: Update APP_PATH to match your actual Parallels shared application path
  2. Save the app as OpenMagnetInParallels.app in your Applications folder

Step 2: Register the URL Scheme Handler

Run these commands in Terminal to register your Automator app as the handler for openmagnet:// URLs:

# Set variables
APP="/Applications/OpenMagnetInParallels.app"
PLIST="$APP/Contents/Info.plist"

# Configure the app bundle
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.example.OpenMagnet" "$PLIST"

# Remove existing URL types and add our custom scheme
sudo /usr/libexec/PlistBuddy -c "Delete :CFBundleURLTypes" "$PLIST" 2>/dev/null
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string Magnet Redirect" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string openmagnet" "$PLIST"

# Register the app with Launch Services
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "$APP"

Step 3: Test the Setup

  1. Install this userscript in Tampermonkey/Violentmonkey
  2. Visit any torrent site with magnet links
  3. Click a magnet link - it should automatically open your Parallels-based torrent client!

Troubleshooting

Links not being rewritten?

  • Check the browser console for script errors
  • Ensure the userscript is enabled and running on the target site

Automator app not launching?

  • Verify the APP_PATH in your shell script is correct
  • Test the URL scheme by running open "openmagnet://?url=test" in Terminal

qBittorrent not receiving the magnet link?

  • Ensure qBittorrent is set as the default magnet handler within your Parallels VM
  • Check that the Parallels shared applications are properly configured

Technical Details

The script uses a MutationObserver to monitor DOM changes and automatically converts any new magnet links that appear on the page. This ensures compatibility with modern single-page applications and dynamically loaded content.

The custom openmagnet:// protocol provides a clean bridge between your browser and the Parallels environment, avoiding the need for complex browser extensions or native messaging hosts.