Created
February 23, 2018 07:44
-
-
Save karubabu/a3a43b5aed4e6571e674b02e5da4fab6 to your computer and use it in GitHub Desktop.
danbooru系のサイトで画像をクリック時にDLする
This file contains hidden or 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 danbooru dl support | |
| // @namespace http://tampermonkey.net/ | |
| // @version 0.2 | |
| // @description try to take over the world! | |
| // @author karubabu | |
| // @match https://*/post/show/* | |
| // @grant GM_download | |
| // @grant GM_notification | |
| // ==/UserScript== | |
| function exist_png(){ | |
| return document.getElementsByClassName("original-file-unchanged").length === 1; | |
| } | |
| function get_url(is_png=false){ | |
| if(is_png === true){ | |
| return document.getElementsByClassName("original-file-unchanged")[0].href; | |
| } | |
| return document.getElementsByClassName("original-file-changed")[0].href; | |
| } | |
| function download(furl, fname){ | |
| GM_download({url: furl, name: fname, onload: GM_notification(fname + " complete!")}); | |
| } | |
| (function() { | |
| 'use strict'; | |
| console.log("url: " + get_url(exist_png())); | |
| var pic_url = get_url(exist_png()); | |
| var file_name = decodeURI(pic_url.match(".*/([^\?#;/:]+).*$")[1]); | |
| console.log("filename: " + file_name); | |
| var sub = document.getElementById("right-col"); | |
| sub.addEventListener("click", function(e){ | |
| download(pic_url, file_name); | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment