Last active
September 7, 2016 17:20
-
-
Save deliciousblackink/17111c5f35d53e9603142524dc87a600 to your computer and use it in GitHub Desktop.
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 Download & Upvote | |
// @version 0.3 | |
// @description Disclaimer: my js is kinda rusty, feel free to comment if you spot a derp | |
// @author DeliciousBlackInk | |
// @include /^https:\/\/(derpibooru\.org|trixiebooru\.org|derpiboo\.ru)\/(\d)(.*)$/ | |
// @grant none | |
// ==/UserScript== | |
var downloadButton = document.querySelector('[title^="Download this image"]'); | |
downloadButton.addEventListener('click', upvote, true); | |
/* the pop-up download location window Firefox throws at us | |
blocks the site's script. here's a quick & dirty hack: remove the | |
download link from the button and open it later, once the image's been | |
upvoted */ | |
var downloadLink = downloadButton.getAttribute('href'); | |
downloadButton.removeAttribute('href'); | |
/* make the empty button seem as an ordinary link */ | |
downloadButton.style.cursor = 'pointer'; | |
function upvote() { | |
var upvoteButton = document.querySelector('.interaction--upvote'); | |
if (!upvoteButton.classList.contains('active')) { | |
upvoteButton.click(); | |
} | |
/* here's the point of that monstrous hack: force the link to open in another tab */ | |
window.open(downloadLink, '_blank'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment