Created
October 2, 2011 03:25
-
-
Save akkunchoi/1256986 to your computer and use it in GitHub Desktop.
chrome image download bookmarklet
This file contains 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
// This script is modified from http://d.hatena.ne.jp/Griever/20100904/1283603283 | |
// The original happens a error "TypeError: object is not a function" on chrome 14 | |
javascript:(function(){ | |
var regexp = /https?:\/\/[^&?#]+?\.(?:jpe?g|png|gif|bmp)(?:$|\b)/i; | |
var array = Array.prototype.slice.call(document.querySelectorAll( | |
'a[href*=".png"], a[href*=".gif"], a[href*=".jpg"], a[href*=".jpeg"], a[href*=".bmp"],' + | |
'a[href*=".PNG"], a[href*=".GIF"], a[href*=".JPG"], a[href*=".JPEG"], a[href*=".BMP"]' | |
)); | |
for (var i = 0, l = array.length; i < l; i++) { | |
/* var m = regexp(array[i].href); */ | |
var m =array[i].href.match(regexp); | |
if (!m) continue; | |
var a = document.createElement('a'); | |
a.href = m; | |
dispatchMouseEvents({ type:'click', altKey:true, target:a, button:0 }); | |
} | |
function dispatchMouseEvents(opt) { | |
var evt = document.createEvent('MouseEvents'); | |
evt.initMouseEvent(opt.type, opt.canBubble||true, opt.cancelable||true, opt.view||window, | |
opt.detail||0, opt.screenX||0, opt.screenY||0, opt.clientX||0, opt.clientY||0, | |
opt.ctrlKey||false, opt.altKey||false, opt.shiftKey||false, opt.metaKey||false, | |
opt.button||0, opt.relatedTarget||null); | |
opt.target.dispatchEvent(evt); | |
return evt; | |
} | |
})();; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment