Jump to content
  • Advertisement
Sign in to follow this  

[web] Bookmarklet - Replace Large Images

This topic is 3665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm a visitor of a forum that often contains extremely large images. This often makes it inconvenient to browse through the posts of a topic because my browser pauses to display each image. What I'd like to do is create a greasemonkey script - effectively an automatically executed javascript file - that would replace each image larger than a certain width with a placeholder and add a button below it to set the image back to its initial source. Of course, no modifications can be made to the original web site html - it has to work via javascript. This is how far I got:
var images = document.images;
var counter=0;

for (i=0;i<images.length;i++){
	if (images.width>2000){
		var OSrc = images.src;
		var tempName="switch_" + counter;
		images.onmousedown='alert("HI!");'//function () {var found=document.getElementByID(name);alert("Image clicked! Alt text is " + found.alt + "!");found.onclick="";found.src=found.alt;found.alt="";}'
		var newButton = document.createElement("button");
		newButton.appendChild(document.createTextNode("Show Image"));

function showImage(name,OSrc){
	var found=document.getElementByID(name);
	alert("Image clicked! Alt text is " + found.alt + "!");
As you can see, I was trying several methods of making something clickable. I tried giving the image an onclick function but couldn't get it to execute (no alert message). I tried adding a button just below the image but failed in that regard too. Anything I'm doing wrong with getting a button to appear, or make the image have an onclick attribute? I know the script is executing as the images are all replace with the Google logo (a placeholder). Thanks, -metroid48

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!