Last active
September 16, 2020 19:24
-
-
Save pjobson/af3187409b656e7d6947101e856b1743 to your computer and use it in GitHub Desktop.
DelugeWeb Modficaitons UserScript
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 Modifications | |
// @namespace Violentmonkey Scripts | |
// @match http://localhost:8112/ | |
// @grant none | |
// @version 1.0 | |
// @author Paul Jobson <pjobson@gmail.com> | |
// @description Mods for DelugeWeb for streamlining the program. Adds: a default move to path, move path input focus, move path input enter key detection. | |
// ==/UserScript== | |
// Change this, you don't want files moved into your home directory! | |
const DefaultMoveToPath = '~/'; | |
const observer = new MutationObserver((mutations) => { | |
mutations.forEach((mutation) => { | |
if (!mutation.addedNodes) return | |
for (let i = 0; i < mutation.addedNodes.length; i++) { | |
// do things to your newly added nodes here | |
let node = mutation.addedNodes[i]; | |
if (node.tagName === 'INPUT' && node.getAttribute('name') === 'location') { | |
// set the new seeding path | |
node.value = node.value || DefaultMoveToPath; | |
// focus the input | |
setTimeout(() => { | |
node.focus(); | |
}, 500); | |
// addevent to the input | |
node.addEventListener('keyup', (ev) => { | |
if (ev.key === 'Enter') { | |
const btn = document.getElementById('ext-gen238'); | |
btn.click(); | |
} | |
}) | |
observer.disconnect(); | |
} | |
} | |
}) | |
}) | |
observer.observe(document.body, { | |
childList: true | |
, subtree: true | |
, attributes: false | |
, characterData: false | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment