Skip to content

Instantly share code, notes, and snippets.

@umeshmohan
Last active June 2, 2017 10:18
Show Gist options
  • Save umeshmohan/4e2844f34868820f020d to your computer and use it in GitHub Desktop.
Save umeshmohan/4e2844f34868820f020d to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Images from Google books preview
// @namespace https://heterorrhina.in/
// @version 0.1
// @description Provides a button to open an auto updating page containing only images from the book preview of Google books
// @author Umesh Mohan
// @match https://books.google.co.in/books*
// @grant none
// ==/UserScript==
var imgsrcL, imgWindow, br, viewport, link;
function updateimgList() {
var imgL = viewport.getElementsByTagName("img"), imgN, imgsrc, img;
for (imgN in imgL) {
imgsrc = imgL[imgN].src;
if (imgsrc == undefined || imgsrc == "") {continue;}
if (imgsrcL.indexOf(imgsrc) == -1) {
imgsrcL.push(imgsrc);
img = imgWindow.document.createElement("img");
img.style.width = "100%";
img.src = imgsrc;
imgWindow.document.body.appendChild(img);
imgWindow.document.body.appendChild(br);
}
}
}
function Refresh() {
viewport = document.getElementById("viewport")
viewport.addEventListener("DOMSubtreeModified",updateimgList,false);
imgWindow = window.open();
br = imgWindow.document.createElement("br");
imgsrcL = [];
updateimgList();
imgWindow.document.title = document.title;
}
link = document.createElement("a");
link.innerHTML = "😇";
link.style.cursor = "pointer";
link.onclick = Refresh;
document.getElementsByClassName("kd-appname")[0].appendChild(link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment