tophf / mpiv

A fully reworked fork of Mouseover Popup Image Viewer
MIT License
167 stars 21 forks source link

Util.rel2abs breaks MPIV for blob urls #80

Closed pintassilgo closed 2 years ago

pintassilgo commented 2 years ago

WhatsApp Web uses blob for everything. MPIV works fine for <img> blobs in WhatsApp, but in many cases the website uses a <div> with backgroud-image, like for displaying images within quoted messages. Then I created this rule:

{
 "d": "web.whatsapp.com",
 "e": "div[role='button'] div:last-of-type > div[style]",
 "s": "return node.style.backgroundImage.slice(5,-2)",
 "xhr": false
}

But it fails here: https://github.com/tophf/mpiv/blob/f998a9367afce7f1f4e4e77e37060a1162778b4e/script.user.js#L2272

So I changed https://github.com/tophf/mpiv/blob/f998a9367afce7f1f4e4e77e37060a1162778b4e/script.user.js#L2742-L2747 to

  rel2abs(rel, abs = location.href) {
    try {
      return rel.startsWith('data:') ||
             rel.startsWith('blob:') ||
             /^[-\w]+:\/\//.test(rel) ?
               rel :
               new URL(rel, abs).href;

And now MPIV works properly to zoom the image.

tophf commented 2 years ago

The reason for that condition was that blobs didn't work on some popular site. I forgot which one so I can't test it now and hence can't insist on keeping it :-)