Created
August 18, 2019 02:17
-
-
Save fallaciousreasoning/ffdb5fa9f5768b4588d87a71076491f2 to your computer and use it in GitHub Desktop.
Adds support for opening magnet:// links in Deluge Web. If you want this to work for you, you'll likely have to configure the @match url to be the url of your Deluge Web, and set `dom.registerProtocolHandler.insecure.enabled` to true in your Firefox about:config, as by default protocol handlers cannot be registered on http sites.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Deluge Protocol Handler | |
// @namespace Violentmonkey Scripts | |
// @match http://192.168.86.74:8112/* | |
// @grant none | |
// ==/UserScript== | |
if (navigator.registerProtocolHandler) | |
navigator.registerProtocolHandler("magnet", "http://192.168.86.74:8112/?magnet=%s", "Deluge"); | |
const waitUntil = (condition, action) => { | |
if (condition()) { | |
action() | |
return; | |
} | |
setTimeout(() => waitUntil(condition, action), 500); | |
} | |
const addTorrent = (path) => { | |
deluge.client.web.add_torrents([{ | |
path: path, | |
options: { | |
file_priorities: [], | |
add_paused: false, | |
compact_allocation: false, | |
download_location: "/media/Seagate/Downloads", | |
move_completed: true, | |
move_completed_path: "/media/Seagate/AudioBooks", | |
max_connections: 0, | |
max_download_speed: -1, | |
max_upload_slots: -1, | |
max_upload_speed: -1, | |
prioritize_first_last_pieces: true | |
} | |
}]); | |
} | |
const canAddTorrent = () => deluge && deluge.client && deluge.client.web && deluge.client.web.add_torrents; | |
window.addEventListener('load', () => { | |
const searchParams = new URLSearchParams(window.location.search); | |
if (!searchParams.has('magnet')) | |
return; | |
const magnetLink = searchParams.get('magnet'); | |
waitUntil(canAddTorrent, () => addTorrent(magnetLink)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment