ScriptKitty

Derpibooru Quicksave button script!

Jul 24th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Derpibooru Quick Save Script
  3. // @namespace   Violentmonkey Scripts
  4. // @match       *://derpibooru.org/*
  5. // @grant       none
  6. // @run-at      document-end
  7. // @version     2.0
  8. // @author      Scriptki77y
  9. // @description Adds a download button to image previews on derpibooru for quick saving!
  10. // ==/UserScript==
  11.  
  12. window.onload = () => {
  13.     let long_filenames = true; // Download long or short file names???
  14.     for (el of document.querySelectorAll('[class*=main] .media-box')) { // remove [class*=main] to target all images on page
  15.         try {
  16.             let data = el.children;
  17.             let header = data[0];
  18.             data = data[1].children[0];
  19.             data = JSON.parse(data.dataset.uris);
  20.             url = long_filenames ? data.full.replace('/img/view/', '/img/download/') : data.large.replace('/img/', '/img/download/').replace('/large', '');
  21.             header.appendChild(new DOMParser()
  22.                 .parseFromString(`<a rel="nofollow" title="Quicksave!" href="${url}"><i class="fa fa-download"></i> QS</a>`, "text/html")
  23.                 .body
  24.                 .childNodes[0]);
  25.         } catch (e) {
  26.             console.error('derpibooru downloader button script: ', e);
  27.         }
  28.     }
  29. };
Add Comment
Please, Sign In to add comment