tophf / mpiv

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

Auto-activate on hovered image at `load` event #56

Closed darkred closed 3 years ago

darkred commented 3 years ago

Implements #34

Re-add https://github.com/tophf/mpiv/commit/a7cb177d887c119a9fde950692bd827b4ec9bd47 via its own setting disabled by default

If you agree to merge, I'll also add a wiki entry that:

The new setting Auto-activate on hovered image at load event is currently aimed for Firefox users only (there's a bug in Chrome, see: https://crbug.com/307375)

tophf commented 3 years ago

You can implement the same via an additional userscript:

// ==UserScript==
// @name        force :hover event in Firefox
// @match       *://*/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

if (!/chrom/i.test(navigator.userAgent)) {
  addEventListener('load', () => {
    const el = [...document.querySelectorAll(':hover')].pop();
    if (el) {
      const r = el.getBoundingClientRect();
      el.dispatchEvent(new MouseEvent('mouseover', {
        clientX: r.left,
        clientY: r.top,
        bubbles: true,
      }));
    }
  }, {once: true});
}
darkred commented 3 years ago

Thank you so much !! I'm grateful ! (I added a ! in the outer if)