Last active
October 3, 2022 20:49
-
-
Save mchelem/59c5d8e4ea79620b7637ba72a4814b6d to your computer and use it in GitHub Desktop.
Bookmarklet to display images listed in a file on the current GCP bucket path
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
| javascript: (function() { | |
| let filteredInputId = document.getElementById("filterInputId"); | |
| if (filteredInputId) { | |
| filteredInputId.remove(); | |
| } | |
| let table = document.getElementsByTagName("table")[0]; | |
| table.parentNode.insertAdjacentHTML("beforebegin", '<input id="filterInputId" type="file">'); | |
| let url = location.protocol + '//' + location.host + location.pathname; | |
| url = url.split(';')[0]; | |
| url = url.replace("https://console.cloud.google.com/storage/browser", "https://storage.cloud.google.com"); | |
| document.getElementById('filterInputId').addEventListener('change', function() { | |
| var fileReader = new FileReader(); | |
| fileReader.onload = function(e) { | |
| let imageNames = e.target.result.trim().split(/[\r\n]+/g); | |
| let imageElements = imageNames.map(name => { | |
| let path = url + '/' + name.trim(); | |
| let element = "<img height=200 src='" + path + "' title='" + name + "'/>"; | |
| return element; | |
| }); | |
| imageElements = Array.from(new Set(imageElements)); | |
| let imageGrid = document.getElementById("imageGrid"); | |
| if (imageGrid) { | |
| imageGrid.remove(); | |
| } | |
| table.insertAdjacentHTML("beforebegin", "<div id='imageGrid'>" + imageElements.join("") + "</div>"); | |
| }; | |
| fileReader.readAsText(this.files[0]); | |
| }) | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment