Skip to content

Instantly share code, notes, and snippets.

@tsamb
Created July 8, 2016 00:05
Show Gist options
  • Save tsamb/8c17ffc34cbe3e4e2715b7b94489f913 to your computer and use it in GitHub Desktop.
Save tsamb/8c17ffc34cbe3e4e2715b7b94489f913 to your computer and use it in GitHub Desktop.
Some code to paste into the console of webpages to change all of their images. (The website must have jQuery installed!)
// How do you create an prompt on the page then get an input of a search term
// Then replace all of the images with images based on that search term?
jQuery.getJSON(
"https://api.giphy.com/v1/gifs/search",
{q: "Ryan Gosling", api_key: "dc6zaTOxFJmzC"}
).done(function(response) {
var images = response.data.map(function(imgObj) {
return imgObj.images.original.url;
});
jQuery("img").each(function(i, img) {
img.src = images[Math.floor(Math.random() * images.length)];
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment