Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wikipedia preview function #595

Merged
merged 56 commits into from
May 12, 2024
Merged

Conversation

Jaifroid
Copy link
Member

Fixes #278.

This is currently specific to Wikimedia ZIMs (i.e. those scraped by mwOffliner) because the HTML has to be parsed based on certain tags provided by mwOffliner.

@kelson42 has suggested that a more generic way could be to snapshot a rendered (but hidden) view of the article and display a png. This would be more generic, although we need to think whether users would expect or even appreciate a generic preview. It's certainly the case that Wikipedia users expect such a feature (and this is the easiest case to cater for).

This feature should be ported upstream to Kiwix JS, but currently the click "infrastructure" is missing there in ServiceWorker mode (or rather, it is done differently), so the code would need to be adapted. See kiwix/kiwix-js#719.

@Jaifroid Jaifroid added enhancement upstream Should be worked on in kiwix-js experimental Experimental features labels Apr 30, 2024
@Jaifroid Jaifroid added this to the Release 3.3.0 milestone Apr 30, 2024
@Jaifroid Jaifroid self-assigned this Apr 30, 2024
@Jaifroid
Copy link
Member Author

Jaifroid commented May 7, 2024

Some to-do items:

  • Fix dark theme support (background is currently transparent with dark theme which produces illegible mix of foreground and background
  • Fix calculation of base URI: i.e., get absolute ZIM url for images (otherwise they will not load automatically in SW mode if path of current document is not same as path of invoked document fragment)
  • Consider supporting Restricted mode, i.e. manually extracting the image from the ZIM
  • Add arrow pointer in direction of text (ideally situated at site of mouse pointer)
  • Add some options to the box: principally, open in new tab or window
  • Make box show with long press (supporting touchscreen)
  • Do not display a completely empty balloon (e.g. links on front page of MDWiki ZIMs)
  • Add user option to disable
  • Rework contextmenu suppression
  • Show and position empty popover with "Loading..." message before populating with content (due to slow loading on Android)
  • Ensure popover is never wider than screen width
  • Arrow should be fixed to div - currently it scrolls if user scrolls screen!

@Jaifroid
Copy link
Member Author

Feature is tested and working on Chromium and Firefox for desktop: mouseover is best method, but long-press also works for touchscreen users, and keyboard (tabbing into links) also evokes the popover. Also tested on UWP app, all working fine with mouseover and touch.

On Android, an installed PWA can use the feature with long-press, and I've included different sizes for portrait and landscape orientation when there is a narrow screen. However, in Firefox for Android long-press seems to be hard-wired to the context menu and is not overridden. However, Firefox for Android cannot load large ZIM archives due to https://bugzilla.mozilla.org/show_bug.cgi?id=1807360, so I doubt anyone uses the PWA in that browser on Android.

I have yet to test Safari / iOS in simulator.

@Jaifroid
Copy link
Member Author

Jaifroid commented May 11, 2024

OK, iOS at least on an iPad has its own "hard-wired" preview feature which my code doesn't interfere with, so I think that's acceptable. See screenshot.

image

EDIT: Same on iPhone.

@Jaifroid
Copy link
Member Author

Feature is working great on Safari desktop on macOS. Both mouseover and keyboard (macOS doesn't have touch).

image

@Jaifroid
Copy link
Member Author

At least on Android, the icons top right are not consistently attached.

@Jaifroid
Copy link
Member Author

Now working in Firefox for Android (with long-press), but close icons are not registering, despite some tweaks. Needs debugging.

@Jaifroid
Copy link
Member Author

Finally icons are working on Firefox!

@Jaifroid
Copy link
Member Author

All tested and working in Chrome (>=49), Firefox (>=68 - earlier versions work but don't support WebP), UWP (Edge Legacy), Safari on macOS. Ready to merge.

@Jaifroid Jaifroid merged commit 7a072ad into main May 12, 2024
@Jaifroid Jaifroid deleted the Add-wikipedia-preview-function branch May 12, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement experimental Experimental features upstream Should be worked on in kiwix-js
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support "page preview" feature of Wikipedia and Wikivoyage
1 participant