Created
January 3, 2018 13:31
-
-
Save karubabu/0c7d085b958f1abe8bf380a4dc85646d to your computer and use it in GitHub Desktop.
danbooruの画像をクリックしたら適当な名前を付けてだうんよーよするやつ
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.1 | |
// @description try to take over the world! | |
// @author karubabu | |
// @match https://*/post/show/* | |
// @grant none | |
// ==/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() { | |
'use strict'; | |
console.log("url: " + get_url(exist_png())); | |
var pic_url = get_url(exist_png()); | |
var fileName = decodeURI(pic_url.match(".*/([^\?#;/:]+).*$")[1]); | |
console.log("filename: " + fileName); | |
(function(){ | |
var a = document.createElement('a'); | |
a.download = fileName; | |
a.href = pic_url; | |
//a.click(); | |
})(); | |
var sub = document.getElementById("image"); | |
sub.addEventListener("click", function(e){ | |
var a = document.createElement('a'); | |
a.download = fileName; | |
a.href = pic_url; | |
var evt = document.createEvent('MouseEvent'); | |
evt.initEvent("click",true,false); | |
a.dispatchEvent(evt); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment