Created
May 8, 2013 13:57
-
-
Save sash13/5540599 to your computer and use it in GitHub Desktop.
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 exBlogLoad | |
| // @description Download image from exblog.jp | |
| // @author Tsumugi Kotobuki | |
| // @license MIT | |
| // @version 0.01 | |
| // @include http://*.exblog.jp/* | |
| // ==/UserScript== | |
| (function (window, undefined) { | |
| var w; | |
| if (typeof unsafeWindow != undefined) { | |
| w = unsafeWindow | |
| } else { | |
| w = window; | |
| } | |
| window.downloadFile = function(sUrl) { | |
| //If in Chrome or Safari - download via virtual link click | |
| if (window.downloadFile.isChrome || window.downloadFile.isSafari) { | |
| //Creating new link node. | |
| var link = document.createElement('a'); | |
| link.href = sUrl; | |
| if (link.download !== undefined){ | |
| //Set HTML5 download attribute. This will prevent file from opening if supported. | |
| var fileName = sUrl.substring(sUrl.lastIndexOf('/') + 1, sUrl.length); | |
| link.download = fileName; | |
| } | |
| //Dispatching click event. | |
| if (document.createEvent) { | |
| var e = document.createEvent('MouseEvents'); | |
| e.initEvent('click' ,true ,true); | |
| link.dispatchEvent(e); | |
| return true; | |
| } | |
| } | |
| // Force file download (whether supported by server). | |
| var query = '?download'; | |
| window.open(sUrl + query); | |
| } | |
| window.downloadFile.isChrome = navigator.userAgent.toLowerCase().indexOf('chrome')>-1; | |
| window.downloadFile.isSafari = navigator.userAgent.toLowerCase().indexOf('safari')>-1; | |
| addButton = function() { | |
| myButton = document.createElement("input"); | |
| myButton.type = "button"; | |
| myButton.value = "Download"; | |
| myButton.onclick = function() { | |
| var objects = document.getElementsByClassName("IMAGE_MID"); | |
| for (i=0;i<objects.length;i++) | |
| downloadFile(objects[i].src) | |
| } | |
| placeHolder = document.getElementsByClassName("posttail")[0]; | |
| placeHolder.appendChild(myButton); | |
| } | |
| if (w.self != w.top) { | |
| return; | |
| } | |
| addButton(); | |
| })(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment