Created
December 9, 2013 08:19
-
-
Save dduleone/7868995 to your computer and use it in GitHub Desktop.
JavaScript Chrome Toolbar Button to turn a folder listing of images into img tags with the images. The width of the images will be the width of the browser window, and the aspect ratio will be maintained. Intended use case is for sharing a folder of images via ChromeCast
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
javascript:(function () { | |
var anchors = document.getElementsByTagName('a'); | |
var body = document.getElementsByTagName('body')[0]; | |
body.style.margin='0px'; | |
for (i in anchors) { | |
if (anchors[i].href && anchors[i].href.toUpperCase().indexOf('.JPG') !== -1) { | |
var img = document.createElement('img'); | |
img.src = anchors[i].href; | |
img.onload = function () { | |
var height = this.height; | |
var width = this.width; | |
var ratio = window.innerWidth / width; | |
this.width = window.innerWidth; | |
this.height = height * ratio; | |
}; | |
body.appendChild(img); | |
} | |
}; | |
var table = document.getElementsByTagName('table'); | |
for (var t in table) { | |
table[t].style.display = 'none'; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment