Skip to content

Instantly share code, notes, and snippets.

@mchelem
Last active October 3, 2022 20:49
Show Gist options
  • Select an option

  • Save mchelem/59c5d8e4ea79620b7637ba72a4814b6d to your computer and use it in GitHub Desktop.

Select an option

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
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