4

There is an issue with all Stack Exchange sites: Even when Stack Overflow is browsed using HTTPS all custom avatars are fetched via HTTP (although they are also available via HTTPS).
The question was closed as duplicate and there will be probably no action in the nearest future, so I wanted to workaround it with Greasemonkey.

I was able to replace all URLs to images with following scripts:

var links = document.evaluate("//img[contains(@src, 'https://i.stack.imgur.com')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); 
for (var i=0; i < links.snapshotLength; i++) 
{ 
    var thisLink = links.snapshotItem(i); 
    hisLink.src = thisLink.src.replace("https://i.stack.imgur.com/", "https://i.stack.imgur.com/");
} 

Source URLs are replaced, but as I see in a Firebug console Firefox first fetches it via HTTP and for a moment fetches them again via HTTPS (and rightly display a warning Loading mixed (insecure) display content on a secure page "https://i.stack.imgur.com/tKsDb.png").

My question. Is it possible to use Greasemonkey to change a page (URLs to the images) before Firefox will fetch them?

Community
  • 1
  • 1
Marcin Zajączkowski
  • 4,036
  • 1
  • 32
  • 41
  • document.write(" – dandavis Jan 24 '14 at 22:34
  • 1
    Possible? Maybe. Best bet is to use one of the local redirection tools, if your LAN router does not have this capability. Crude hack is to use AdBlock to stop undesired images and Greasemonkey to add the HTTPS equivalents. – Brock Adams Jan 24 '14 at 22:54
  • Thanks @Brock, I thought about local proxy, but the idea with AdBlock is much more funny and easier to implement. – Marcin Zajączkowski Jan 24 '14 at 23:23
  • You could try putting // @run-at document-start in your header and keep looping until the document is fully loaded. I'm not sure you can change the links before they starts loading though. http://wiki.greasespot.net/Metadata_block – Emery Lapinski Feb 25 '14 at 04:52
  • Metadate `@run-at document-start` runs the userscript *before* document begins loading. You could try to use `MutationObserver` or DOM mutation events to manipulate `src` immediately after insertion. – Pinke Helga Jun 24 '14 at 21:32
  • No longer the case. Stack Exchange will automatically load imgur URLs via HTTPS. See: [HTTPS-only images](https://meta.stackoverflow.com/q/343276) on Meta Stack Overflow. – double-beep Nov 28 '21 at 12:25

0 Answers0