Last active
September 21, 2018 12:30
-
-
Save Koopzington/e5a9d0d52630355e7a07b314eac19f7f to your computer and use it in GitHub Desktop.
deviantArt Hotkeys for Notifications
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 dA Hotkeys | |
// @namespace https://koopzington.github.com/ | |
// @version 0.4 | |
// @description DeviantArt also has Hotkeys now! | |
// @author Koopzington@gmail.com | |
// @match https://*.deviantart.com/* | |
// @downloadURL https://gist.github.com/Koopzington/e5a9d0d52630355e7a07b314eac19f7f/raw/da-hotkeys.user.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Avoid bloating code | |
const qs = document.querySelector.bind(document); | |
const mousedownEvent = new MouseEvent('mousedown', { | |
view: window, | |
bubbles: true, | |
cancelable: true | |
}); | |
const mouseupEvent = new MouseEvent('mouseup', { | |
view: window, | |
bubbles: true, | |
cancelable: true | |
}); | |
// A simple .click() doesn't seem to work on some elements | |
function simulateClick(e) { | |
e.dispatchEvent(mousedownEvent); | |
e.dispatchEvent(mouseupEvent); | |
} | |
window.onkeydown = event => { | |
let e = null; | |
// Don't do anything if the target of the event is an input | |
// (including the div.writer that acts as proxy for textareas in comments) | |
if (event.target.form !== undefined || event.target.classList.contains('writer')) { | |
return; | |
} | |
// Select all | |
if (event.key === 'a') { | |
// Start searching from an available mcbox because there are empty mczones | |
e = qs('.mcbox'); | |
if (e !== null) { | |
e = e.closest('.mczone').querySelector('[data-dapx-element="MC_SelectAll"]'); | |
} else { | |
// Alternatively search for the "All" button displayed next to the logo while seeing deviations | |
e = qs('a.minibrowse_close'); | |
} | |
if (e !== null) { | |
e.click(); | |
} | |
} | |
// Click first available llama-button | |
if (event.key === 'l') { | |
e = qs('.oclb-give'); | |
if (e !== null) { | |
e.click(); | |
} | |
} | |
if (event.key === 'n') { | |
window.location = 'https://www.deviantart.com/notifications/'; | |
} | |
// Click on image for bigger version | |
if (event.key === '+') { | |
qs('.dev-view-deviation img').click(); | |
} | |
// Click the Delete Button | |
if (event.key === 'Delete') { | |
// "Remove from Messages" button on deviations | |
e = qs('.remove-message-button'); | |
if (e === null) { | |
// "Remove (n)" Button in the same mczone as the first selected item | |
e = qs('.mcbox-sel').closest('.mczone').querySelector('[data-dapx-element="MC_Remove"]'); | |
} | |
if (e !== null) { | |
e.click(); | |
} | |
} | |
// Click the first thumb | |
if (event.key === '#') { | |
qs('.mcbox-thumb a.thumb').click(); | |
} | |
// Select the next element, keep scrolling functionality if page doesn't have an mcbox element | |
if (event.key === 'ArrowDown') { | |
if (qs('.mcbox') === null || qs('.minibrowse-container') !== null) { | |
return; | |
} | |
event.preventDefault(); | |
e = qs('.mcbox-sel + .mcbox'); | |
if (e !== null) { | |
simulateClick(e); | |
} else { | |
simulateClick(qs('.mcbox')); | |
} | |
} | |
// Select previous element, keep scrolling functionality if page doesn't have an mcbox element | |
if (event.key === 'ArrowUp') { | |
if (qs('.mcbox') === null || qs('.minibrowse-container') !== null) { | |
return; | |
} | |
event.preventDefault(); | |
e = qs('.mcbox-sel'); | |
if (e !== null) { | |
simulateClick(e.previousSibling); | |
} else { | |
simulateClick(qs('.mcbox')); | |
} | |
} | |
// Next-Button while browsing | |
if (event.key === 'ArrowRight') { | |
if (qs('li.next a.away') === null || qs('.minibrowse-container') !== null) { | |
return; | |
} | |
event.preventDefault(); | |
qs('li.next a.away').click(); | |
} | |
// Next-Button while browsing | |
if (event.key === 'ArrowLeft') { | |
if (qs('li.prev a.away') === null || qs('.minibrowse-container') !== null) { | |
return; | |
} | |
event.preventDefault(); | |
qs('li.prev a.away').click(); | |
} | |
// If selected element is a stack, click "See all" or open the journal message | |
if (event.key === 'Enter') { | |
e = qs('.mcbox-sel .stacklink-cover'); | |
if (e === null) { | |
e = qs('.mcbox-sel a.thumb'); | |
} | |
if (e !== null) { | |
e.click(); | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: