all articles

disable reader mode on safari

2016-10-06 @sunderls

Reader Safari js

Reader view on safari

attention to the icon in address bar

2016-07-01 21 00 55

it is convenient, but I'd like to disable it

well, don't care about the reasons, I just want id hidden. How can we do it?

safari uses js script to show the button

Safari shows the button if it thinks it is better. What is the criteria? I think it is based on the text. Look at the js source code here : https://github.com/adadgio/safari-reader-js/blob/17ae3dafcea5d7f65decb7497c1307bb5a59ebf0/safari-reader.source.js

how safari judges

1.safari picks up some visual points, like center, left-top, right-down https://github.com/adadgio/safari-reader-js/blob/17ae3dafcea5d7f65decb7497c1307bb5a59ebf0/safari-reader.source.js#L1761

2.then it find the dom at these points, by document.elementFromPoint(x,y) https://github.com/adadgio/safari-reader-js/blob/17ae3dafcea5d7f65decb7497c1307bb5a59ebf0/safari-reader.source.js#L1761

3.check the dom (then parent, then parent'parent, untile body) to give it a score, to judge whether it is element of article. If it is, then show the button.

OK, we can just disable elementFromPoint?

Yes, I've found a solution and tested. You can give a transparent overlay over the top, and safari will be mislead when using elementFromPoint, since every time it will be lead to the overlay which has no text

some hints

1.safari will recheck when dom changes, so you need to add the mark every time you think you should

2.iOS safari will check every time you scroll, so you can hide the mask on Mac, but you have to keep the mask on iOS.