Skip to content

Instantly share code, notes, and snippets.

@deliciousblackink
Last active September 7, 2016 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deliciousblackink/17111c5f35d53e9603142524dc87a600 to your computer and use it in GitHub Desktop.
Save deliciousblackink/17111c5f35d53e9603142524dc87a600 to your computer and use it in GitHub Desktop.
// ==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