All Projects → tsucres → SwiftyMercuryReady

tsucres / SwiftyMercuryReady

Licence: MIT license
Add a "reader" functionality to a WKWebView

Programming Languages

swift
15916 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to SwiftyMercuryReady

osmosfeed
Turn GitHub into an RSS reader
Stars: ✭ 839 (+1033.78%)
Mutual labels:  reader
WebAppReader
基于 html5 、 Vue.js 、 Koa、Node.js 以及 EJS 的手机小说阅读器。使用 node.js 模拟后台数据,无实际后台,完全的前后端分离开发。
Stars: ✭ 15 (-79.73%)
Mutual labels:  reader
mp4-rust
🎥 MP4 reader and writer library in Rust! 🦀
Stars: ✭ 149 (+101.35%)
Mutual labels:  reader
readability-cli
A CLI for Mozilla Readability. Get clean, uncluttered, ready-to-read HTML from any webpage!
Stars: ✭ 41 (-44.59%)
Mutual labels:  reader
Ichaival
Android client for the LANraragi manga/doujinshi web manager.
Stars: ✭ 89 (+20.27%)
Mutual labels:  reader
react-viewer
Online EPUB/Comics viewer
Stars: ✭ 52 (-29.73%)
Mutual labels:  reader
DocumentReader-iOS
iOS Framework for reading and validation of identification documents
Stars: ✭ 54 (-27.03%)
Mutual labels:  reader
maildir
A Go package for reading & writing messages in maildir format
Stars: ✭ 13 (-82.43%)
Mutual labels:  reader
WKWebView-Console
How to output console.log in Xcode (using wkwebview)?
Stars: ✭ 40 (-45.95%)
Mutual labels:  wkwebview
esp-idf-rc522
C library for interfacing ESP32 with MFRC522 RFID card reader, packaged as ESP-IDF component
Stars: ✭ 60 (-18.92%)
Mutual labels:  reader
WKBridge
Bridge for WKWebView and JavaScript
Stars: ✭ 70 (-5.41%)
Mutual labels:  wkwebview
LANraragi cn
This repo is a fork of Difegue / LANraragi , those things i've done was to translate this repo into chinese ,and fix chrome browser js problem.
Stars: ✭ 147 (+98.65%)
Mutual labels:  reader
AppHostExample
a web-based project embeded AppHost
Stars: ✭ 16 (-78.38%)
Mutual labels:  wkwebview
Reader
高仿多看阅读器apk,支持PDF解析.文档支持搜索,高亮文字,墨迹等功能
Stars: ✭ 98 (+32.43%)
Mutual labels:  reader
HDEmptyView
一个Swift语言封装的EmptyView显示库,可作用于WKWebView、UITableView、UICollectionView 无网络提醒或者空数据提醒
Stars: ✭ 29 (-60.81%)
Mutual labels:  wkwebview
HTMLWithImagesToPDF
Generate a PDF from an HTML file containing images (iOS).
Stars: ✭ 38 (-48.65%)
Mutual labels:  wkwebview
react-native-config-reader
🛠 Easily access any of the build configs defined in build.gradle or info.plist from your JS code.
Stars: ✭ 44 (-40.54%)
Mutual labels:  reader
reader
get a reader mode sharable url for any url - built with cloudflare workers https://reader.tuananh.net
Stars: ✭ 24 (-67.57%)
Mutual labels:  reader-mode
parcera
Grammar-based Clojure(script) parser
Stars: ✭ 100 (+35.14%)
Mutual labels:  reader
ariel-news-app
News App developed with Flutter featuring beautiful UI, category-based news, story for faster news reading, inbuilt article viewer, share feature, and more.
Stars: ✭ 31 (-58.11%)
Mutual labels:  reader

SwiftyMercuryReady

License

>>> DEMO <<<

A MercuryApi based iOS reader written in Swift.

Motivation

Most modern webbrowers (mobile or desktop) implement a "reader mode" allowing to sanitise/epurate the design of a webpage and offer a better reading experience. However, WKWebView doesn't. Which means that an iOS app can't, natively, load a webpage and switch to the reader mode without passing it to safari. This project aims to add this functionality to a WKWebView subclass.

Presentation

Custom font size

Customisable font

Custom font size Serif

You can easily switch between 3 font sizes and change between serif/sans

Lght & Dark themes

Serif Serif

Foldable navigation bar

Serif

Navigation Back & Forward

Serif

Description

The project basically contains 3 parts, each one adding something to the previous:

  • MercuryApi: a MercuryApi client, composed of two classes: MercuryApi and MercurtResponse. They're used to communicate with the API and handle the data it sends back.
  • ReaderWebView: a WKWebView subclass that loads the data received by the API in an HTML template. It supports Dark/Light themes and different font sizes.
  • ArticleReaderController: It's a UIViewConroller subclass that implements the basic functionalities of a web browser with the ability to switch to "reader mode" on any page that is supported by MercuryApi.

Usage

MercuryApi

First of all, you have to set you set your Mercury Api key. If you don't have one, you can get it for free here.

  1. create a keys.plist file at the root of the project (along with the info.plist file)
  2. add a property called mercuryApiKey
  3. put your api key as value to this property

Then, you just use parseUrl with the url of the webpage you want to make more readable as parameter. You will get a MercuryResponse that encapsulate all the attributes generated by the API.

MercuryApi.shared.parseUrl(url: url.absoluteString, completion: {(resp) -> Void in
	if resp != nil {
		print(resp!.title)
	} 
})

See the documentation of the api for more info about them.

ReaderWebView

You have to add the ReaderWebView instance in a view (as you would with a WKWebView). Then , you load a webpage with

load(url: URL)

If the webpage is supported by the API (meaning it's able to parse it and extract the content out of it), the ReaderWebView will load the content in the html template and render the whole thing.

It's also possible to directly load a MercuryResponse:

load(MercuryResponse resp: MercuryResponse)

Use the delegate's methods contentDidLoad and contentFailedToLoad to determine whether the content successfully loaded or not (see the following section about the delegate).

Apparence

You can play with the apparence of the reader with:

	/// Available content sizes
    enum ReaderContentSize {
        case small
        case medium
        case large
    }
    /// Available themes
    enum ReaderContentTheme {
        case light
        case dark
    }
    
    /// Currently displayed theme
    var readerTheme: ReaderContentTheme
    /// Current size of the content
    var readerContentSize: ReaderContentSize
    /// Indicates whether to use a serif font or not
    var fontSerif: Bool
    
Delegate

You can implement the following methods to keep track of what's happening inside the reader:

/// Called when the user taps on a link inside the reader.
func navigationRequested(request:  URLRequest, navigationType: WKNavigationType)
/// Called when a MercuryResponse was successfully loaded in the reader
func contentDidLoad(reader: ReaderWebView, content: MercuryResponse)
/// Called when the reader failed to load a URL
func contentFailedToLoad(reader: ReaderWebView, url: URL?, content: MercuryResponse?)
/// Called when the template has been loaded in the reader webview
func readerInitialized(reader: ReaderWebView)

Note: Since the ReaderWebView inherits from WKWebView, you can, in theory, assign a WKNavigationDelegate to it. In practice though, since the webview is only used to load the reader's template, the methods of the delegate aren't really useful.

Demo

Check the ReaderWebViewDemo.swift file for a quick example.

ArticleReaderController

This part of the project is an example of implementation of the previous part. You can use it as is if it fits your needs or modify it as you want.

In short, it's a controller handling a WKWebView that has a ReaderWebView associated (meaning they will always show the same content). It implements a navigation bar and a toolbar presenting the basic webview controls (back, forward and refresh).

For a basic usage, all you have to do is instantiate the ArticleReaderController and give it a URL. Al the rest is controlled by the user.

You may find usefull to manually show/hide the reader, you can do that using the isReaderEnabled property.

Check the ArticlesReaderDemo.swift file for an example.

TODO

  • customisable background color for the reader (add swift properties for the color of the dark & light themes instead of hardcoding them in the html template)
  • better error handling in MercuryApi
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].