Feedback on NI Community

cancel
Showing results for 
Search instead for 
Did you mean: 

Firefox addon for displaying attached images

At some point Firefox stopped opening image files in a new tab when I click on them and instead started downloading them. This has been an annoyance for me on the NI forums, so I wrote this Firefox addon which works in the forums here - it finds all the attachments in the page and if the attachment is an image (see point 4 below), it will modify the page to display the image under the attachment.

 

This does make browsing the forums easier, so I figured I would upload it in case someone else wants it. I suppose you could also do this using something like Greasemonkey, but I don't have anything like that installed.

 

Some caveats:

 

  1. This is provided as-is. It's fairly simplistic, so I don't expect it should cause any problems. You can look inside the zip file to see how it works. The manifest file has the general details and the js file has the actual code.
  2. I did this for Firefox. I don't expect this would work directly in other browsers, but the logic is fairly simple if you want to reimplement it.
  3. There's an annoying behavior where I can't drag the scrollbar for the image. If I do, the browser almost immediately starts dragging the image instead. I can still use the scrollbar by clicking in it or on the arrows. Haven't figured out why this happens.
  4. The addon checks if the attachment has the text .png|.jpg|.jpeg|.gif|.bmp somewhere in the link to detect images. It might have been more elegant to find the mime type of the link, but it doesn't look like there's an easy way to do that and I figured this would work well enough.

 

Installation instructions

 

  1. Download the file.
  2. This file has a zip extension because the forums don't allow uploading xpi files. To install it, you will probably need to remove the zip extension.
  3. Click the menu button
  4. Click Add-ons and select Extensions.
  5. To add the downloaded add-on to the list of available add-ons, drag and drop the file into the Add-ons window. The add-on is added to the list.
  6. The installation process should begin.
  7. Once installed, it should work immediately on pages under forums.ni.com.

If the install instructions are unclear, you can see it with images here.

 

This is the actual code, for those who care:

 

// find all of the attachment links
var attachments = document.getElementsByClassName("lia-link-navigation attachment-link");

var i;
var attcLink;
var attcID;
var newEl;
var newDiv;


//for each attachment: if it's an image, create a new img tag element in the link with the image, so that we can see the image
for (i = 0; i < attachments.length; i++) {
	attcLink=attachments[i].href;
	if (attcLink.search(/.png|.jpg|.jpeg|.gif|.bmp/i)>0 ){ //use a case insensitive match and check for different image types
		attcID=attachments[i].id;
		document.getElementById(attcID).appendChild(document.createElement("br")); //add a line break after the attachment link
		newDiv=document.createElement("div");
		document.getElementById(attcID).appendChild(newDiv); //add a div which can hold the scrollbar
		newEl=document.createElement("img");
		newEl.setAttribute("src",attcLink);
		newDiv.setAttribute("style","overflow-x:scroll; white-space: nowrap;"); //force a horizontal scroll if the image doesn't fit
		newDiv.appendChild(newEl); //add the image 
		newDiv.appendChild(document.createElement("br")); //add a line break after the image
		newDiv.appendChild(document.createElement("br")); //add a line break after the image
	}
	
} 

 


___________________
Try to take over the world!
0 Kudos
Message 1 of 5
(1,881 Views)
Thanks a lot for sharing. I will definitely try it for myself.
0 Kudos
Message 2 of 5
(1,817 Views)

Why isn't the site opening those images in a new tab?

 

That should be fairly trivial.

 

I'm not using Firefox. 😐

0 Kudos
Message 3 of 5
(1,577 Views)

wiebe@CARYA wrote:

Why isn't the site opening those images in a new tab?

 

That should be fairly trivial.


I think the issue is with the browsers, which at some point stopped opening image links in new tabs. For this to work, the new tab would probably need to be a dedicated page wrapping the image. Not exactly complicated HTML, but I'm not holding my breath waiting for it to be implemented. I think I may have looked at that for the add-on and decided it was either impossible or more complicated than I was going to handle at the time.

 

I believe the FF and Chrome model for extensions is identical, so it's quite possible that the code will work in Chrome as-is, but it would probably require creating an account, building the extension for Chrome, figuring out how to load a custom extension, etc. I don't use Chrome, so I'm not familiar with how that process works there.


___________________
Try to take over the world!
0 Kudos
Message 4 of 5
(1,566 Views)

@tst wrote:

wiebe@CARYA wrote:

Why isn't the site opening those images in a new tab?

 

That should be fairly trivial.


I think the issue is with the browsers,


It could be Edge.

 

Even if I right click the lick and select "open in new window", the file is downloaded.

 

Another annoying thing is that you can easily embed an attached file, but it's not possible to embed an image that's embedded. The insert image allows a URL, but there's no way to get the URL of an embedded image. So to embed an image from another thread, you have to download it and upload it. 

0 Kudos
Message 5 of 5
(1,556 Views)