read.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. /**
  2. * Make a page more readable by disabling all page styling and applying a
  3. * bare minimum of our own. Go to the first thing that looks like the start
  4. * of the actual content so no time is wasted scrolling past initial
  5. * navigation etc.
  6. *
  7. * @title Readable++
  8. */
  9. (function read() {
  10. /* Create a new IFRAME to get a "clean" Window object, so we can use its
  11. * console. Sometimes sites (e.g. Twitter) override console.log and even
  12. * the entire console object. "delete console.log" or "delete console"
  13. * does not always work, and messing with the prototype seemed more
  14. * brittle than this. */
  15. var console = (function () {
  16. var iframe = document.getElementById('xxxJanConsole');
  17. if (!iframe) {
  18. iframe = document.createElementNS('http://www.w3.org/1999/xhtml', 'iframe');
  19. iframe.id = 'xxxJanConsole';
  20. iframe.style.display = 'none';
  21. (document.body || document.documentElement).appendChild(iframe);
  22. }
  23. return iframe && iframe.contentWindow && iframe.contentWindow.console || {
  24. log: function () {}
  25. };
  26. })();
  27. /* The style sheet for more readable content. */
  28. var css = (function () { /*@charset "utf-8";
  29. @namespace svg "http://www.w3.org/2000/svg";
  30. -jancss-comment { content:
  31. "General styles -------------------------------------------";
  32. }
  33. * {
  34. line-height: 1.5;
  35. }
  36. html {
  37. background: rgb(245, 245, 225);
  38. color: rgb(0, 0, 30);
  39. }
  40. body {
  41. max-width: 48em;
  42. margin: 0 auto;
  43. padding: 1em;
  44. font-family: "Calibri", sans-serif;
  45. font-size: 1.05rem;
  46. }
  47. p {
  48. line-height: 1.7;
  49. }
  50. :link {
  51. color: #00e;
  52. }
  53. :visited {
  54. color: #528;
  55. }
  56. :link:focus,
  57. :visited:focus,
  58. :link:hover,
  59. :visited:hover {
  60. color: #e30;
  61. }
  62. :link:active,
  63. :visited:active {
  64. color: #e00;
  65. }
  66. center,
  67. [align] {
  68. text-align: left;
  69. }
  70. b:not(.jancss-probably-structure),
  71. u,
  72. blink {
  73. font-weight: inherit;
  74. font-style: inherit;
  75. text-decoration: inherit
  76. }
  77. b.jancss-probably-structure {
  78. font-size: larger;
  79. }
  80. .jancss-probably-layout {
  81. font: inherit;
  82. }
  83. -jancss-comment { content:
  84. "Headers --------------------------------------------------";
  85. }
  86. h1:not(.jancss-probably-layout),
  87. h2:not(.jancss-probably-layout),
  88. h3:not(.jancss-probably-layout) {
  89. font-family: "Cambria", serif;
  90. }
  91. h1, h1.jancss-probably-layout {
  92. border-bottom: 1px solid #888;
  93. font-size: 200%;
  94. font-weight: 100;
  95. }
  96. h2, h2.jancss-probably-layout * {
  97. border-bottom: 1px solid #bbb;
  98. font-size: 150%;
  99. font-weight: 100;
  100. }
  101. h3, h3.jancss-probably-layout {
  102. border-bottom: 1px dotted #bbb;
  103. font-size: 117%;
  104. font-weight: 100;
  105. }
  106. h1.jancss-probably-layout *,
  107. h2.jancss-probably-layout *,
  108. h3.jancss-probably-layout * {
  109. font-size: 1rem;
  110. }
  111. -jancss-comment { content:
  112. "Links in headers (probably permalinks) -------------------";
  113. }
  114. h1 a[href]:not(:hover),
  115. h2 a[href]:not(:hover),
  116. h3 a[href]:not(:hover) {
  117. text-decoration: none;
  118. }
  119. h1 a[href]::after,
  120. h2 a[href]::after,
  121. h3 a[href]::after {
  122. font-size: 75%;
  123. content: " #";
  124. }
  125. -jancss-comment { content:
  126. "Pre-formatted text and source code -----------------------";
  127. }
  128. pre {
  129. padding: 1ex;
  130. border: 1px dotted;
  131. }
  132. code,
  133. pre,
  134. .syntaxhighlighter,
  135. .dp-highlighter {
  136. font-family: "Consolas", monospace;
  137. font-size: small;
  138. background: #ffe;
  139. }
  140. .dp-highlighter + pre[name="code"] {
  141. display: none;
  142. }
  143. -jancss-comment { content:
  144. "Forms ----------------------------------------------------";
  145. }
  146. textarea {
  147. width: 100%;
  148. height: 32ex;
  149. }
  150. -jancss-comment { content:
  151. "Tables ---------------------------------------------------";
  152. }
  153. table.jancss-probably-for-data th,
  154. table.jancss-probably-for-data td {
  155. vertical-align: top;
  156. text-align: left;
  157. padding: 0.5ex;
  158. }
  159. table.jancss-probably-for-data caption {
  160. font-weight: bold;
  161. border-bottom: 1px dotted;
  162. }
  163. table.jancss-probably-for-layout td {
  164. display: inline-block;
  165. }
  166. table.jancss-probably-for-data tr:nth-child(odd) td:not(.jancss-active-col) {
  167. background: #ffe;
  168. }
  169. table.jancss-probably-for-data tr:hover td:not(.code),
  170. table.jancss-probably-for-data .jancss-active-col {
  171. background: #ffc;
  172. }
  173. table.jancss-probably-for-data th,
  174. table.jancss-probably-for-data tr td:not(.code):hover {
  175. background: #ff9;
  176. }
  177. table.jancss-probably-for-data th code,
  178. table.jancss-probably-for-data td code {
  179. background: inherit;
  180. }
  181. -jancss-comment { content:
  182. "Make images use the full page width ----------------------";
  183. }
  184. img,
  185. input[type="image"],
  186. object,
  187. embed,
  188. video,
  189. audio,
  190. iframe,
  191. canvas,
  192. :not(svg|*) > svg|* {
  193. max-width: 100%;
  194. }
  195. figure {
  196. margin: 0;
  197. }
  198. iframe {
  199. width: 100%;
  200. }
  201. iframe[class*="twitter"] {
  202. min-height: 15em;
  203. }
  204. -jancss-comment { content:
  205. "Dim images and media until :hover ------------------------";
  206. }
  207. body:not(:hover) img,
  208. body:not(:hover) input[type="image"],
  209. body:not(:hover) object,
  210. body:not(:hover) embed,
  211. body:not(:hover) video,
  212. body:not(:hover) audio,
  213. body:not(:hover) iframe,
  214. body:not(:hover) canvas,
  215. body:not(:hover) :not(svg|*) > svg|* {
  216. opacity: 0.25;
  217. }
  218. -jancss-comment { content:
  219. "Limit icon dimensions --------------------------------";
  220. }
  221. a[href*="facebook.com"] svg,
  222. a[href*="instagram.com"] svg,
  223. a[href*="twitter.com"] svg,
  224. a[href*=".pinterest."] svg,
  225. svg[id*="icon"],
  226. svg[class*="icon"],
  227. svg[class*="inline"],
  228. svg[data-icon],
  229. svg[role="img"],
  230. [class*="icon"] svg,
  231. [class*="Icon"] svg,
  232. img[class*="icon"][src*=".svg"],
  233. img[class*="Icon"][src*=".svg"],
  234. span > svg,
  235. button svg,
  236. [class*="button"] svg,
  237. [role*="button"] svg,
  238. [class*="controls"] svg,
  239. .svg-icon,
  240. .inline-icon,
  241. .wp-smiley,
  242. .smiley,
  243. .emoticon,
  244. :not(html).emoji {
  245. max-width: 1.4em;
  246. max-height: 1.4em;
  247. }
  248. -jancss-comment { content:
  249. "Make everything scrollable -------------------------------";
  250. }
  251. [style*="position: fixed"],
  252. [style*="position:fixed"] {
  253. position: static !important;
  254. }
  255. -jancss-comment { content:
  256. "Make side notes and pull quotes less conspicuous ---------";
  257. }
  258. aside:not(:hover),
  259. [data-expander-id],
  260. [id^="footnote_plugin_tooltip_text_"]:not(:hover),
  261. blockquote[class*="quote"]:not(:hover),
  262. q[class*="pull"]:not(:hover),
  263. blockquote[class*="pull"]:not(:hover),
  264. .quote-box:not(:hover),
  265. .su-pullquote:not(:hover),
  266. .pullquote:not(:hover),
  267. .pullQuote:not(:hover),
  268. .pull-quote:not(:hover) {
  269. opacity: 0.25;
  270. }
  271. -jancss-comment { content:
  272. "Decrease common forum and metadata font size -------------";
  273. }
  274. .postprofile,
  275. .signature {
  276. font-size: smaller;
  277. border-top: 1px dotted;
  278. opacity: 0.5;
  279. }
  280. -jancss-comment { content:
  281. "Hide common social media elements ------------------------";
  282. }
  283. iframe[src*=".facebook.com/"],
  284. iframe[src*=".twitter.com/widgets/"],
  285. iframe[src*="//plusone.google.com/_/+1/"],
  286. iframe[src*="//www.reddit.com/static/button/"],
  287. iframe[src*="//s7.addthis.com/"],
  288. iframe[src*="//www.stumbleupon.com/badge/embed/"],
  289. iframe[src*="//widgets.bufferapp.com/"] {
  290. width: 12em;
  291. height: 4ex;
  292. border: 1px dotted;
  293. }
  294. .twtr-widget.twtr-scroll {
  295. max-height: 30ex;
  296. overflow: auto;
  297. }
  298. .article__share {
  299. display: none;
  300. }
  301. #social_btns {
  302. display: none;
  303. }
  304. .taboola {
  305. display: none;
  306. }
  307. .social-media > .share {
  308. display: none;
  309. }
  310. :-moz-any(
  311. div,
  312. ul,
  313. li
  314. ):-moz-any(
  315. :-moz-any(
  316. [id*="social"],
  317. [id*="Social"]
  318. ):-moz-any(
  319. [id*="media"],
  320. [id*="Media"]
  321. ):-moz-any(
  322. [id*="share"],
  323. [id*="Share"],
  324. [id*="sharing"],
  325. [id*="Sharing"]
  326. ),
  327. :-moz-any(
  328. [id*="social"],
  329. [id*="Social"]
  330. [id*="share"],
  331. [id*="Share"],
  332. [id*="sharing"],
  333. [id*="Sharing"]
  334. ):-moz-any(
  335. [id*="toolbar"],
  336. [id*="Toolbar"],
  337. [id*="buttons"],
  338. [id*="Buttons"],
  339. ),
  340. :-moz-any(
  341. [class*="social"],
  342. [class*="Social"]
  343. ):-moz-any(
  344. [class*="media"],
  345. [class*="Media"]
  346. ):-moz-any(
  347. [class*="share"],
  348. [class*="Share"],
  349. [class*="sharing"],
  350. [class*="Sharing"]
  351. ),
  352. :-moz-any(
  353. [class*="social"],
  354. [class*="Social"]
  355. [class*="share"],
  356. [class*="Share"],
  357. [class*="sharing"],
  358. [class*="Sharing"]
  359. ):-moz-any(
  360. [class*="toolbar"],
  361. [class*="Toolbar"],
  362. [class*="buttons"],
  363. [class*="Buttons"],
  364. )
  365. ) {
  366. display: none;
  367. }
  368. :matches(
  369. div,
  370. ul,
  371. li
  372. ):matches(
  373. :matches(
  374. [id*="social"],
  375. [id*="Social"]
  376. ):matches(
  377. [id*="media"],
  378. [id*="Media"]
  379. ):matches(
  380. [id*="share"],
  381. [id*="Share"],
  382. [id*="sharing"],
  383. [id*="Sharing"]
  384. ),
  385. :matches(
  386. [id*="social"],
  387. [id*="Social"]
  388. [id*="share"],
  389. [id*="Share"],
  390. [id*="sharing"],
  391. [id*="Sharing"]
  392. ):matches(
  393. [id*="toolbar"],
  394. [id*="Toolbar"],
  395. [id*="buttons"],
  396. [id*="Buttons"],
  397. ),
  398. :matches(
  399. [class*="social"],
  400. [class*="Social"]
  401. ):matches(
  402. [class*="media"],
  403. [class*="Media"]
  404. ):matches(
  405. [class*="share"],
  406. [class*="Share"],
  407. [class*="sharing"],
  408. [class*="Sharing"]
  409. ),
  410. :matches(
  411. [class*="social"],
  412. [class*="Social"]
  413. [class*="share"],
  414. [class*="Share"],
  415. [class*="sharing"],
  416. [class*="Sharing"]
  417. ):matches(
  418. [class*="toolbar"],
  419. [class*="Toolbar"],
  420. [class*="buttons"],
  421. [class*="Buttons"],
  422. )
  423. ) {
  424. display: none;
  425. }
  426. -jancss-comment { content:
  427. "Hide ad elements that slipped through my ad blocker ------";
  428. }
  429. iframe[id^="google_ads_"] {
  430. display: none;
  431. }
  432. -jancss-comment { content:
  433. "Hide empty list items ------------------------------------";
  434. }
  435. li:empty, li.jancss-emptyish {
  436. display: none;
  437. }
  438. -jancss-comment { content:
  439. "Make common navigation elements more compact -------------";
  440. }
  441. :-moz-any(
  442. nav,
  443. body [class*="avigat"],
  444. body [id*="avigat"],
  445. body [class*="-nav-"],
  446. body [class*="nav-"],
  447. body [class$="-nav"],
  448. body [id*="-nav-"],
  449. body [id*="nav-"],
  450. body [id$="-nav"],
  451. body [role="navigation"]
  452. ) ul {
  453. display: inline;
  454. margin: 0;
  455. padding: 0;
  456. }
  457. :-webkit-any(
  458. nav,
  459. body [class*="avigat"],
  460. body [id*="avigat"],
  461. body [class*="-nav-"],
  462. body [class*="nav-"],
  463. body [class$="-nav"],
  464. body [id*="-nav-"],
  465. body [id*="nav-"],
  466. body [id$="-nav"],
  467. body [role="navigation"]
  468. ) ul {
  469. display: inline;
  470. margin: 0;
  471. padding: 0;
  472. }
  473. :any(
  474. nav,
  475. body [class*="avigat"],
  476. body [id*="avigat"],
  477. body [class*="-nav-"],
  478. body [class*="nav-"],
  479. body [class$="-nav"],
  480. body [id*="-nav-"],
  481. body [id*="nav-"],
  482. body [id$="-nav"],
  483. body [role="navigation"]
  484. ) ul {
  485. display: inline;
  486. margin: 0;
  487. padding: 0;
  488. }
  489. :-moz-any(
  490. nav,
  491. body [class*="avigat"],
  492. body [id*="avigat"],
  493. body [class*="-nav-"],
  494. body [class*="nav-"],
  495. body [class$="-nav"],
  496. body [id*="-nav-"],
  497. body [id*="nav-"],
  498. body [id$="-nav"],
  499. body [role="navigation"]
  500. ) li {
  501. display: inline;
  502. margin: 0;
  503. padding: 0 .5em;
  504. border-right: 1px dotted;
  505. }
  506. :-webkit-any(
  507. nav,
  508. body [class*="avigat"],
  509. body [id*="avigat"],
  510. body [class*="-nav-"],
  511. body [class*="nav-"],
  512. body [class$="-nav"],
  513. body [id*="-nav-"],
  514. body [id*="nav-"],
  515. body [id$="-nav"],
  516. body [role="navigation"]
  517. ) li {
  518. display: inline;
  519. margin: 0;
  520. padding: 0 .5em;
  521. border-right: 1px dotted;
  522. }
  523. :any(
  524. nav,
  525. body [class*="avigat"],
  526. body [id*="avigat"],
  527. body [class*="-nav-"],
  528. body [class*="nav-"],
  529. body [class$="-nav"],
  530. body [id*="-nav-"],
  531. body [id*="nav-"],
  532. body [id$="-nav"],
  533. body [role="navigation"]
  534. ) li {
  535. display: inline;
  536. margin: 0;
  537. padding: 0 .5em;
  538. border-right: 1px dotted;
  539. }
  540. -jancss-comment { content:
  541. "Hide old cufón text replacement --------------------------";
  542. }
  543. .cufon-canvas canvas {
  544. display: none;
  545. }
  546. -jancss-comment { content:
  547. "Make notes on decorrespondent.nl less conspicuous --------";
  548. }
  549. .contentitem-sidenote:not(:hover) > :not(.contentitem-sidenote-snippet),
  550. .contentitem-infocard-toggle-container + .contentitem-infocard-contents:not(:hover) {
  551. opacity: 0.25;
  552. }
  553. .contentitem-sidenote:hover > :not(.contentitem-sidenote-snippet),
  554. .contentitem-infocard-toggle-container + .contentitem-infocard-contents:hover {
  555. background: #ffc;
  556. }
  557. -jancss-comment { content:
  558. "Hide the source text on Google Translate-d pages ---------";
  559. }
  560. .google-src-text {
  561. display: none;
  562. }
  563. -jancss-comment { content:
  564. "Hide big ScrollMagic spacers, e.g. on Co.Design ----------";
  565. }
  566. .scrollmagic-pin-spacer {
  567. display: none;
  568. }
  569. -jancss-comment { content:
  570. "Always hide our IFRAME used to restore console.log -------";
  571. }
  572. #xxxJanConsole {
  573. display: none;
  574. }
  575. */; }).toString()
  576. .replace(/^function\s*\(\s*\)\s*\{\s*\/\*/, '')
  577. .replace(/\*\/\s*\;?\s*\}\s*$/, '');
  578. /* The attributes to disable. */
  579. var attrs = [
  580. 'style',
  581. 'background', 'bgcolor', 'color', 'text', 'link', 'vlink', 'alink', 'hlink',
  582. 'table@width', 'colgroup@width', 'col@width', 'tr@width', 'td@width', 'th@width', 'table@height', 'tr@height', 'td@height', 'th@height',
  583. 'img@width', 'img@height',
  584. 'border',
  585. 'frameborder',
  586. 'align',
  587. 'face', 'font@size', 'basefont@size'
  588. ];
  589. /* Elements to remove completely. */
  590. var elementsToRemoveSelectors = [
  591. '.bt-popin' /* Used on standaard.be. */
  592. ];
  593. /* The selectors to try for the header elements, whose text content will be compared to the page title. The last match wins. */
  594. var headerSelectors = [
  595. '[class*="head"]:not(:empty)',
  596. '[class*="Head"]:not(:empty)',
  597. '[id*="head"]:not(:empty)',
  598. '[id*="Head"]:not(:empty)',
  599. '[role="heading"]',
  600. '[class*="title"]:not(:empty)',
  601. '[class*="Title"]:not(:empty)',
  602. 'h1:not(:empty), h2:not(:empty), h3:not(:empty)',
  603. 'h1:not(:empty)[itemprop~="name"], h2:not(:empty)[itemprop~="name"], h3:not(:empty)[itemprop~="name"]',
  604. 'h1:not(:empty)[itemprop~="headline"], h2:not(:empty)[itemprop~="headline"], h3:not(:empty)[itemprop~="headline"]'
  605. ];
  606. var ancestorsForHeadersToIgnoreSelectors = [
  607. 'aside',
  608. '.related-posts',
  609. '.article-slider',
  610. '.article-drawer'
  611. ];
  612. /* The selectors to try (in this order) for the first content element to scroll to when no suitable header was found. */
  613. var contentSelectors = [
  614. /* The most semantically rich elements should be used correctly so we
  615. * can ass-u-me them to be the main content element, right?
  616. */
  617. 'main h1:not(:empty)',
  618. 'main header',
  619. 'main h2:not(:empty)',
  620. 'main',
  621. 'body [itemprop="blogPost"] h1:not(:empty)',
  622. 'body [itemprop="blogPost"] header',
  623. 'body [itemprop="blogPost"] h2:not(:empty)',
  624. 'body [itemprop="blogPost"]',
  625. 'body [role="main"] h1:not(:empty)',
  626. 'body [role="main"] header',
  627. 'body [role="main"] h2:not(:empty)',
  628. 'body [role="main"]',
  629. 'body [role="document"] h1:not(:empty)',
  630. 'body [role="document"] header',
  631. 'body [role="document"] h2:not(:empty)',
  632. 'body [role="document"]',
  633. 'body [role="article"] h1:not(:empty)',
  634. 'body [role="article"] header',
  635. 'body [role="article"] h2:not(:empty)',
  636. 'body [role="article"]',
  637. 'body #main h1:not(:empty)',
  638. 'body #main header',
  639. 'body #main h2:not(:empty)',
  640. 'body #main',
  641. /* <article> is also "semantically rich", but there are several sites
  642. * that have a list of related articles, each in its own <article>. A
  643. * "real" article would not have any <article> siblings.
  644. */
  645. ':not(li) > article:only-of-type',
  646. /* Common IDs and classes for the main content element (e.g. weblog
  647. * post IDs, newspaper articles, …)
  648. */
  649. 'body #article',
  650. 'body :not(#spotlight) > .article',
  651. 'body .articleContent',
  652. 'body #article_top',
  653. 'body #article_body',
  654. 'body #article_main',
  655. 'body .post-body:not(.field-item)',
  656. ':not(input):not(textarea).post',
  657. ':not(input):not(textarea).blogpost',
  658. ':not(input):not(textarea).blogPost',
  659. 'body [id^="post0"]',
  660. 'body [id^="post1"]',
  661. 'body [id^="post2"]',
  662. 'body [id^="post3"]',
  663. 'body [id^="post4"]',
  664. 'body [id^="post5"]',
  665. 'body [id^="post6"]',
  666. 'body [id^="post7"]',
  667. 'body [id^="post8"]',
  668. 'body [id^="post9"]',
  669. 'body [id^="post-0"]',
  670. 'body [id^="post-1"]',
  671. 'body [id^="post-2"]',
  672. 'body [id^="post-3"]',
  673. 'body [id^="post-4"]',
  674. 'body [id^="post-5"]',
  675. 'body [id^="post-6"]',
  676. 'body [id^="post-7"]',
  677. 'body [id^="post-8"]',
  678. 'body [id^="post-9"]',
  679. 'body #entry',
  680. 'body .entry',
  681. 'body #content',
  682. 'body .content',
  683. 'body [id^="content"]',
  684. 'body [class^="content"]',
  685. 'body #main',
  686. 'body .main',
  687. /* Consider the first header (in DOM order) to be the most important
  688. * one and ass-u-me it is the start of the main content.
  689. */
  690. 'h1:not(:empty)',
  691. 'body #header',
  692. 'header',
  693. 'body .header',
  694. 'h2:not(:empty)',
  695. /* When all else fails, just look for bigger text, which would
  696. * probably be used instead of the appropriate header elements.
  697. */
  698. 'big'
  699. ];
  700. /* Structure elements incorrectly used for layout purposes ("make it big and bold"). */
  701. var structureElementsForLayoutSelectors = [
  702. '//*[contains(" h1 h2 h3 h4 h5 h6 h7 ", concat(" ", local-name(), " ")) and string-length(normalize-space()) > 120]'
  703. ];
  704. /* Layout elements incorrectly used for structure purposes ("bold means header"). */
  705. var layoutElementsForStructureSelectors = [
  706. /* Because there is no support for the Selectors Level 4 "subject of
  707. * a selector" syntax yet (or any definite syntax, for that matter),
  708. * I simply ass-u-me in the code below that the subject is a "B"
  709. * element. Either the result of the selector, or the previous
  710. * element sibling.
  711. */
  712. 'b:first-child + :empty',
  713. ':empty + b + :empty',
  714. ':empty + b:last-child',
  715. 'div > b:only-child, p > b:only-child'
  716. ];
  717. /* URI pattern for syntax highlighting style sheets. */
  718. var syntaxHighlightHrefRegex = /\b((syntax|pygments)(hi(ghlight(er)?|lite(r)?))?|sh(Core|Theme[^.]*)|geshi|codecolorer)[./]/i;
  719. /* Keep track of which elements have had their event handlers
  720. * disabled/re-enabled.
  721. */
  722. var elementsWithToggledEventHandlers = {};
  723. var eventHandlerAttributesToToggle = [
  724. 'oncontextmenu',
  725. 'onshow',
  726. 'oninput',
  727. 'onkeydown',
  728. 'onkeyup',
  729. 'onkeypress',
  730. 'onmousedown',
  731. 'onmouseup',
  732. 'onmouseenter',
  733. 'onmouseleave',
  734. 'onmouseover',
  735. 'onmouseout',
  736. 'onmousemove',
  737. 'onresize',
  738. 'onscroll',
  739. 'onwheel',
  740. 'onselect',
  741. 'onselectstart',
  742. 'onselectionchange'
  743. ];
  744. /* All main content elements (the one in the main document and those
  745. * nested in any IFRAMEs etc.) */
  746. var contentElements = [];
  747. /* The main function. */
  748. (function execute(document) {
  749. function addClass(element, classNames) {
  750. /* HTMLElement.classList does not work on iOS 4's Safari, so this is a fallback. */
  751. classNames.split(/\s+/).forEach(function (className) {
  752. element.className = ((' ' + element.className + ' ').replace(' ' + className.trim() + ' ', '') + ' ' + className).trim();
  753. });
  754. }
  755. function removeClass(element, classNames) {
  756. classNames.split(/\s+/).forEach(function (className) {
  757. element.className = (' ' + element.className + ' ').replace(' ' + className.trim() + ' ', '').trim();
  758. });
  759. }
  760. function toArray(arrayLike) {
  761. return Array.prototype.slice.call(arrayLike);
  762. }
  763. var all = toArray(document.getElementsByTagName('*')),
  764. ourStyleSheet = document.getElementById('jancss'),
  765. allStyleSheets = toArray(document.styleSheets),
  766. prettyPrintStyleSheet,
  767. matches;
  768. /* Special hack for The Guardian (and possibly others), which re-enables the CSS because it detects a change in font size. */
  769. window.TextResizeDetector && TextResizeDetector.stopDetector && TextResizeDetector.stopDetector();
  770. /* Clear all scheduled callbacks. Naively ass-u-me that any call to
  771. * setTimeout/setInterval returns the next ID from a monotonically
  772. * increasing function that is used for both timeout and interval
  773. * IDs. Therefore, to clear all timeouts and intervals, it suffices
  774. * to get a new timeout ID and then clear everything up to that ID.
  775. *
  776. * Though the HTML5 specification says nothing about the return value
  777. * of setTimeout/setInterval, this appears to work in Firefox 22,
  778. * Chrome 27, Opera 12 and Safari 5.
  779. */
  780. var maxTimeoutId = setTimeout(function () {
  781. for (var i = 1; i < maxTimeoutId; i++) {
  782. clearTimeout(i);
  783. clearInterval(i);
  784. }
  785. }, 4); /* 4 ms is the minimum timeout as per HTML5. */
  786. /* Now clear all the requested animation frame callbacks. Again, this
  787. * naively assumes the ID will increment one by one. MDN explicitly
  788. * advises against assumptions such as this one: https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame#Return_value
  789. */
  790. var requestAnimationFrame = window.requestAnimationFrame
  791. || window.mozRequestAnimationFrame
  792. || window.webkitRequestAnimationFrame
  793. || window.msRequestAnimationFrame
  794. || function () { };
  795. var cancelAnimationFrame = window.cancelAnimationFrame
  796. || window.mozCancelAnimationFrame
  797. || window.webkitCancelAnimationFrame
  798. || window.msCancelAnimationFrame
  799. || function () { };
  800. var maxAnimationFrameRequestId = requestAnimationFrame(function () {
  801. for (i = 1; i < maxAnimationFrameRequestId * 2; i++) {
  802. cancelAnimationFrame(i);
  803. }
  804. /* Log requests to the original requestAnimationFrame. */
  805. window.requestAnimationFrame = function (callback) {
  806. var callbackSource = callback.toSource && callback.toSource();
  807. if (callbackSource && callbackSource.indexOf('Readable++ requestAnimationFrame interceptor') === -1) {
  808. console.log('Readable++: intercepted call to requestAnimationFrame at ' + new Date());
  809. console.log('Readable++: callback for requestAnimationFrame: ' + callbackSource);
  810. }
  811. };
  812. });
  813. /* While in Readable++ mode, disable some elements' event handlers.
  814. * This prevents hijacking events like "scroll" and "resize", which
  815. * can be abused to annoy me with visual effects and whatnot, and
  816. * "contextmenu" and "selectstart", which are clearly defined as
  817. * universal and inalienable human rights. Look it up at your local
  818. * Wikipedia office.
  819. */
  820. [window, document, document.documentElement, document.body].forEach(function (elem) {
  821. /* In non-HTML documents, elements like document.body can be
  822. * null. */
  823. if (!elem) {
  824. return;
  825. }
  826. /* Because the window for IFRAMEs is the same as the outer
  827. * document's window, we need to keep track of wether we
  828. * have toggled the event handlers. Otherwise, they might
  829. * get disabled and re-enabled immediately after.
  830. */
  831. if (elementsWithToggledEventHandlers[elem]) {
  832. return;
  833. }
  834. elementsWithToggledEventHandlers[elem] = true;
  835. /* Toggle selected event handlers that have been set using
  836. * "elem.oneventx = function () { … };"
  837. */
  838. eventHandlerAttributesToToggle.forEach(function (attrib) {
  839. if (elem['jancss-' + attrib]) {
  840. elem[attrib] = elem['jancss-' + attrib];
  841. delete elem['jancss-' + attrib];
  842. } else if (elem[attrib]) {
  843. elem['jancss-' + attrib] = elem[attrib];
  844. elem[attrib] = function () { };
  845. }
  846. });
  847. /* Toggle all event handlers that have been set using jQuery. */
  848. if (typeof jQuery === 'function') {
  849. /* Since jQuery 1.7. */
  850. if (typeof jQuery.hasData === 'function' && jQuery.hasData(elem)) {
  851. /* Spotted in the wild: "jQuery._data is undefined". */
  852. if (typeof jQuery._data !== 'function') {
  853. return;
  854. }
  855. var data = jQuery._data(elem);
  856. if (data.jancssEvents) {
  857. data.events = data.jancssEvents;
  858. delete data.jancssEvents;
  859. jQuery._data(elem, data);
  860. return;
  861. } else if (data.events) {
  862. data.jancssEvents = data.events;
  863. delete data.events;
  864. jQuery._data(elem, data);
  865. return;
  866. }
  867. }
  868. /* Before jQuery 1.7 and after jQuery 1.2.3 */
  869. if (jQuery.fn.data) {
  870. var $elem = jQuery(elem);
  871. var eventsData = $elem.data('events');
  872. var jancssEventsData = $elem.data('jancssEvents');
  873. if (jancssEventsData) {
  874. $elem.data('events', jancssEventsData);
  875. $elem.removeData('jancssEvents');
  876. } else if (eventsData) {
  877. $elem.data('jancssEvents', eventsData);
  878. $elem.removeData('events');
  879. }
  880. }
  881. }
  882. });
  883. /* The code above does not work for event listeners added using
  884. * addEventListener. Some sites listen for the "resize" event and
  885. * then reposition elements by setting their style directly. To
  886. * counteract this, simply delete all "style" attributes that get set
  887. * while our style sheet is enabled. That'll show 'em!
  888. */
  889. if (typeof MutationObserver === 'function' && !document.jancssHasMutationObserver) {
  890. document.jancssHasMutationObserver = true;
  891. var observer = new MutationObserver(function (mutations) {
  892. if (ourStyleSheet.disabled) {
  893. return;
  894. }
  895. mutations.forEach(function(mutation) {
  896. if (!mutation.target.hasAttribute('style') || mutation.target.id === 'xxxJanConsole' || mutation.target.xxxJanReadableAllowStyle) {
  897. return;
  898. }
  899. console.log('Readable++: removing "style" attribute set while in Readable++ mode on element ', mutation.target);
  900. mutation.target.removeAttribute(mutation.attributeName);
  901. });
  902. });
  903. observer.observe(document, {
  904. attributes: true,
  905. attributeFilter: ['style'],
  906. subtree: true
  907. });
  908. }
  909. /* Load bLazy.js "retina" images. This is more specific than the
  910. * generic lazy-loading attributes below, and needs special handling
  911. * because it specifies multiple sources in one attribute.
  912. */
  913. toArray(document.querySelectorAll('img.b-lazy[data-src*="|"]')).forEach(function (img) {
  914. var attribute = 'data-src';
  915. var sources = img.getAttribute(attribute).split('|');
  916. img.src = sources.pop();
  917. img.removeAttribute(attribute);
  918. });
  919. /* Load Riloadr "<noscript>" images. This is more specific than the
  920. * generic lazy-loading attributes below, and needs special handling
  921. * because it would reset the images to blank when scrolling after
  922. * Readable++ has been applied.
  923. */
  924. toArray(document.querySelectorAll('img[data-src] + noscript')).forEach(function (noscript) {
  925. var img = noscript.previousElementSibling;
  926. var placeholder = img.previousElementSibling;
  927. if (placeholder && placeholder.tagName.toLowerCase() === 'svg') {
  928. placeholder.parentNode.removeChild(placeholder);
  929. }
  930. img.outerHTML = noscript.textContent;
  931. noscript.parentNode.removeChild(noscript);
  932. });
  933. /* Load images that are supposed to be loaded lazily. */
  934. [
  935. 'data-original',
  936. 'data-lazyload',
  937. 'data-lazy-src',
  938. 'data-full-src',
  939. 'data-src'
  940. ].forEach(function (attribute) {
  941. toArray(document.querySelectorAll('img[' + attribute + ']')).forEach(function (img) {
  942. img.src = img.getAttribute(attribute);
  943. img.removeAttribute(attribute);
  944. });
  945. });
  946. /* Show controls on AUDIO and VIDEO elements. */
  947. [].forEach.call(document.querySelectorAll('audio, video'), function (element) {
  948. element.controls = true;
  949. });
  950. /* Hide empty list items that are not ":empty" as per CSS. So,
  951. * "empty" as in "containing text-less placeholders typically used
  952. * for social sharing by showing an icon or logo or whatnot"
  953. * (e.g. <li><a href="#"><span class="icon-fb"></span></a></li>).
  954. */
  955. toArray(document.querySelectorAll('li :empty:not(img):not(input)')).forEach(function (elem) {
  956. while (elem.tagName && elem.tagName.toLowerCase() !== 'li') {
  957. elem = elem.parentNode;
  958. }
  959. if (elem.textContent.trim() === '' && !elem.querySelector('img, input'))
  960. {
  961. addClass(elem, 'jancss-emptyish');
  962. }
  963. });
  964. /* Remove known-bad elements. */
  965. toArray(document.querySelectorAll(elementsToRemoveSelectors.join(', '))).forEach(function (element) {
  966. element.parentNode.removeChild(element);
  967. });
  968. /* The first time this bookmarklet is called, add our style sheet and
  969. * check for layout elements. */
  970. if (!ourStyleSheet) {
  971. (ourStyleSheet = document.createElementNS('http://www.w3.org/1999/xhtml', 'style')).id = 'jancss';
  972. ourStyleSheet.innerHTML = css;
  973. (document.head || document.body || document.documentElement).appendChild(ourStyleSheet);
  974. ourStyleSheet.disabled = true;
  975. /* Highlight matching data table columns on :hover. I do not
  976. * know how to do this in pure CSS without COLGROUPs. */
  977. function columnMouseHandler(e) {
  978. if (!/^t[dh]$/i.test('' + e.target.tagName)) {
  979. return;
  980. }
  981. var targetCell = e.target, nthChild = targetCell.cellIndex + 1, table = targetCell.parentNode;
  982. while (table && table.tagName.toLowerCase() !== 'table') {
  983. table = table.parentNode;
  984. }
  985. var activeColumnClassName = 'jancss-active-col';
  986. toArray(table.querySelectorAll('td:nth-child(' + nthChild + ')')).forEach(function (cell) {
  987. if (e.type === 'mouseenter') {
  988. addClass(cell, activeColumnClassName);
  989. } else {
  990. removeClass(cell, activeColumnClassName);
  991. }
  992. });
  993. }
  994. /* Check which tables are used for data instead of layout. */
  995. toArray(document.querySelectorAll('table')).forEach(function (table) {
  996. var isTableForData = true;
  997. /* Are there any nested tables? */
  998. if (table.querySelector('table')) {
  999. var isWikipediaInfobox = (' ' + table.className + ' ').match(/infobox/);
  1000. if (!isWikipediaInfobox) {
  1001. console.log('Readable++: TABLE contains other TABLEs, so probably for layout: ', table);
  1002. isTableForData = false;
  1003. }
  1004. }
  1005. /* Are we in quirks mode and does this table takes up most of the page height? */
  1006. else if (document.compatMode === 'BackCompat' && document.documentElement.scrollHeight > window.innerHeight && table.scrollHeight > 3/4 * document.documentElement.scrollHeight) {
  1007. console.log('Readable++: TABLE seems pretty high in this document in quirks mode, so probably for layout: ', table);
  1008. isTableForData = false;
  1009. }
  1010. /* If the table has several rows, look whether they are consistent in their number of cells. */
  1011. else if (table.rows.length > 3) {
  1012. var numCellsPerRow = [];
  1013. toArray(table.rows).forEach(function (row) {
  1014. if (numCellsPerRow.indexOf(row.cells.length) === -1) {
  1015. numCellsPerRow.push(row.cells.length);
  1016. }
  1017. });
  1018. /* Are we in quirks mode and does this table have at least three rows with a different number of cells? */
  1019. if (document.compatMode === 'BackCompat' && numCellsPerRow.length >= 3) {
  1020. console.log('Readable++: TABLE has a lot of differing cell counts in this document in quirks mode, so probably for layout: ', table);
  1021. isTableForData = false;
  1022. }
  1023. /* Does this table only have rows with just a single column? */
  1024. else if (numCellsPerRow.length === 1 && numCellsPerRow[0] === 1) {
  1025. console.log('Readable++: TABLE has only rows of one cell each, so probably for layout: ', table);
  1026. isTableForData = false;
  1027. }
  1028. }
  1029. if (isTableForData) {
  1030. addClass(table, 'jancss-probably-for-data');
  1031. table.addEventListener('mouseenter', columnMouseHandler, true);
  1032. table.addEventListener('mouseleave', columnMouseHandler, true);
  1033. } else {
  1034. addClass(table, 'jancss-probably-for-layout');
  1035. }
  1036. });
  1037. /* (Re-)add some syntax highlighters' CSS if necessary. Those styles are often defined in the main CSS, so the HREF test in toggleStyles() does not match. */
  1038. if (document.querySelector('.prettyprint')) {
  1039. prettyPrintStyleSheet = document.createElementNS('http://www.w3.org/1999/xhtml', 'style');
  1040. prettyPrintStyleSheet.textContent = '@import url(https://janmoesen.github.io/bookmarklets/css/prettify.css)';
  1041. document.head.appendChild(prettyPrintStyleSheet);
  1042. } else if (document.querySelector('.syntaxhighlighter')) {
  1043. prettyPrintStyleSheet = document.createElementNS('http://www.w3.org/1999/xhtml', 'style');
  1044. prettyPrintStyleSheet.textContent = '@import url(https://janmoesen.github.io/bookmarklets/css/syntaxhighlighter.css)';
  1045. document.head.appendChild(prettyPrintStyleSheet);
  1046. } else if (document.querySelector('.highlight .c, .highlight .k, .highlight .m, .highlight .s, .highlight .w')) {
  1047. prettyPrintStyleSheet = document.createElementNS('http://www.w3.org/1999/xhtml', 'style');
  1048. prettyPrintStyleSheet.textContent = '@import url(https://janmoesen.github.io/bookmarklets/css/pygments.css)';
  1049. document.head.appendChild(prettyPrintStyleSheet);
  1050. } else if (document.querySelector('code[class*="language-"] .token.punctuation')) {
  1051. prettyPrintStyleSheet = document.createElementNS('http://www.w3.org/1999/xhtml', 'style');
  1052. prettyPrintStyleSheet.textContent = '@import url(https://janmoesen.github.io/bookmarklets/css/prism.css)';
  1053. document.head.appendChild(prettyPrintStyleSheet);
  1054. }
  1055. /* Add some classes to structure elements that have been used for layout. */
  1056. structureElementsForLayoutSelectors.forEach(function (selector) {
  1057. var xPathResult = document.evaluate(selector, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  1058. for (var i = 0; i < xPathResult.snapshotLength; i++) {
  1059. var elem = xPathResult.snapshotItem(i);
  1060. addClass(elem, 'jancss-probably-layout');
  1061. }
  1062. });
  1063. /* Add some classes to layout elements that have been used for structure. */
  1064. layoutElementsForStructureSelectors.forEach(function (selector) {
  1065. toArray(document.querySelectorAll(selector)).forEach(function (elem) {
  1066. if (elem.tagName.toLowerCase() !== 'b') {
  1067. elem = elem.previousElementSibling;
  1068. }
  1069. addClass(elem, 'jancss-probably-structure');
  1070. });
  1071. });
  1072. }
  1073. /* Toggle between our readable and the page's original style sheet(s). */
  1074. function toggleStyles() {
  1075. ourStyleSheet.disabled = !ourStyleSheet.disabled;
  1076. if (prettyPrintStyleSheet) {
  1077. prettyPrintStyleSheet.disabled = ourStyleSheet.disabled;
  1078. }
  1079. allStyleSheets.forEach(function (styleSheet, i) {
  1080. if (styleSheet.ownerNode !== ourStyleSheet && !syntaxHighlightHrefRegex.test(styleSheet.href)) {
  1081. /* Remember whether this style sheet was originally disabled or not. We can't store on the CSSStyleSheet object, so use our DOM node. */
  1082. if (ourStyleSheet['jancss-originally-disabled-' + i] === undefined) {
  1083. ourStyleSheet['jancss-originally-disabled-' + i] = styleSheet.disabled;
  1084. }
  1085. if (ourStyleSheet.disabled) {
  1086. /* Restore this style sheet's original state. */
  1087. styleSheet.disabled = ourStyleSheet['jancss-originally-disabled-' + i];
  1088. } else {
  1089. /* Disable this style sheet when ours is enabled. */
  1090. styleSheet.disabled = true;
  1091. try {
  1092. /* … unless it is a pretty-print style sheet. */
  1093. if (styleSheet.cssRules[0] && styleSheet.cssRules[0].type === styleSheet.cssRules[0].IMPORT_RULE && styleSheet.cssRules[0].href) {
  1094. styleSheet.disabled = !styleSheet.cssRules[0].href.match(/^https:\/\/janmoesen\.github\.io\//);
  1095. }
  1096. } catch (e) {
  1097. }
  1098. }
  1099. }
  1100. });
  1101. /* Process all attributes for all elements. */
  1102. all.forEach(function (elem, i) {
  1103. attrs.forEach(function (attr, j) {
  1104. /* Parse the attribute definition. Attributes can be restricted to certain elements, e.g. "table@width". */
  1105. if (!(matches = attr.match(/([^@]+)@([^@]+)/)) || (elem.tagName && elem.tagName.toLowerCase() == matches[1])) {
  1106. attr = matches ? matches[2] : attr;
  1107. var names = { enabled: attr, disabled: 'jancss-' + attr };
  1108. if (elem.hasAttribute(names.enabled)) {
  1109. elem.setAttribute(names.disabled, elem.getAttribute(names.enabled));
  1110. elem.removeAttribute(names.enabled);
  1111. } else if (elem.hasAttribute(names.disabled)) {
  1112. elem.setAttribute(names.enabled, elem.getAttribute(names.disabled));
  1113. elem.removeAttribute(names.disabled);
  1114. }
  1115. }
  1116. });
  1117. });
  1118. /* Restore the inline styles for certain code highlighters. */
  1119. var disabledStyleAttr = 'jancss-style';
  1120. toArray(document.querySelectorAll('.wp_syntax [' + disabledStyleAttr + ']')).forEach(function (elem) {
  1121. elem.setAttribute('style', elem.getAttribute(disabledStyleAttr));
  1122. elem.removeAttribute(disabledStyleAttr);
  1123. });
  1124. }
  1125. /* Find the first thing that looks like the start of the actual content so we can scroll to it after applying our CSS. */
  1126. function findContentElement() {
  1127. /* When there seems to be a link to an in-page anchor (e.g. foo.html#mainContent), try to get the linked element. */
  1128. if (location.hash) {
  1129. var inPageAnchor, inPageAnchorSelectors = [
  1130. 'a[name="' + location.hash.substring(1) + '"]',
  1131. location.hash.replace(/\./g, '\\.')
  1132. ];
  1133. for (var i = 0; i < inPageAnchorSelectors.length; i++) {
  1134. try {
  1135. if ((inPageAnchor = document.querySelector(inPageAnchorSelectors[i]))) {
  1136. console.log('Readable++: found in-page anchor based on location.hash: ', inPageAnchor);
  1137. return inPageAnchor;
  1138. }
  1139. } catch (e) {
  1140. }
  1141. }
  1142. }
  1143. /* Check for headers whose text appears in the page title. */
  1144. var headerInPageTitle;
  1145. var charactersToIgnore = /[^A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]+/g;
  1146. function normalizeText(str) {
  1147. return str
  1148. .replace(/\xAD/g, '')
  1149. .replace(charactersToIgnore, ' ')
  1150. .trim();
  1151. }
  1152. var metaTitleElement = document.querySelector('meta[property="og:title"], meta[property="twitter:title"], meta[name="title"]');
  1153. var normalizedMetaTitle = metaTitleElement && normalizeText(metaTitleElement.content);
  1154. var normalizedPageTitle = normalizeText(document.title);
  1155. headerSelectors.forEach(function (selector) {
  1156. toArray(document.querySelectorAll(selector)).forEach(function (element) {
  1157. var normalizedText = normalizeText(element.textContent);
  1158. /* Make sure the element has text. */
  1159. if (!normalizedText.length) {
  1160. return;
  1161. }
  1162. /* Make sure the element is visible. */
  1163. var boundingRect = element.getBoundingClientRect();
  1164. if (!boundingRect.width || !boundingRect.height) {
  1165. return;
  1166. }
  1167. /* Make sure the element is "above the fold" (or near it). Some sites use
  1168. * bigger headings for a footer section than for the actual content, but in
  1169. * general, the real header should be visible within the first screenful. */
  1170. if (boundingRect.top + window.scrollY > window.innerHeight * 1.5) {
  1171. return;
  1172. }
  1173. /* Make sure the title can contain the element's text. */
  1174. if (
  1175. normalizedPageTitle.length < normalizedText.length
  1176. && (!metaTitleElement || normalizedMetaTitle.length < normalizedText.length)
  1177. ) {
  1178. return;
  1179. }
  1180. /* See if the element's text appears in the page title. */
  1181. var substringIndex = normalizedPageTitle.indexOf(normalizedText);
  1182. if (substringIndex === -1 && metaTitleElement) {
  1183. substringIndex = normalizedMetaTitle.indexOf(normalizedText);
  1184. }
  1185. if (substringIndex === -1) {
  1186. return;
  1187. }
  1188. /* Make sure the element is not contained in an ASIDE or a sidebar (e.g. in a list of articles). */
  1189. if (typeof element.closest === 'function' && element.closest(ancestorsForHeadersToIgnoreSelectors.join(', '))) {
  1190. return;
  1191. }
  1192. headerInPageTitle = element;
  1193. });
  1194. });
  1195. if (headerInPageTitle) {
  1196. console.log('Readable++: found suitable header element whose text appears in the page title: ', headerInPageTitle);
  1197. return headerInPageTitle;
  1198. }
  1199. /* Fall back to common content element selectors. */
  1200. for (var i = 0; i < contentSelectors.length; i++) {
  1201. try {
  1202. var element = document.querySelector(contentSelectors[i]);
  1203. /* Make sure the element was either an anchor or something "visible". */
  1204. if (element && (element.tagName.toLowerCase() === 'a' || element.offsetWidth || element.offsetHeight)) {
  1205. console.log('Readable++: found matching selector for content element: ' + contentSelectors[i] + '\nElement: ', element);
  1206. return element;
  1207. }
  1208. }
  1209. catch (e) {
  1210. console.log('Readable++: bad selector for content element: ' + contentSelectors[i] + '\nException: ' + e);
  1211. }
  1212. }
  1213. }
  1214. /* Check if there is an element that we should scroll into view so we can immediately start reading. */
  1215. var contentElement, shouldScrollContentIntoView = false;
  1216. var selection = document.getSelection && document.getSelection();
  1217. if (selection && selection.anchorNode && (selection + '').length) {
  1218. /* If the user has created a selection, scroll the element containing that selection into view. (I often triple-click a paragraph to select it before reading.) */
  1219. shouldScrollContentIntoView = true;
  1220. contentElement = selection.anchorNode;
  1221. while (contentElement.nodeType !== contentElement.ELEMENT_NODE && contentElement.parentNode) {
  1222. contentElement = contentElement.parentNode;
  1223. }
  1224. console.log('Readable++: found selected element to scroll into view: ', contentElement);
  1225. } else if (ourStyleSheet.disabled && (contentElement = findContentElement())) {
  1226. /* When switching from the original style sheet to ours, scroll to the start of the content, unless the user had scrolled already. */
  1227. var tmpElement = contentElement, contentTop = 0;
  1228. do {
  1229. contentTop += tmpElement.offsetTop;
  1230. } while ((tmpElement = tmpElement.offsetParent));
  1231. shouldScrollContentIntoView = !window.scrollY || Math.abs(window.scrollY - contentTop) < 20;
  1232. }
  1233. /* Finally, toggle the style sheets. */
  1234. toggleStyles();
  1235. /* Scroll to the start of the content if we found it and have not scrolled yet. */
  1236. shouldScrollContentIntoView && contentElements.push(contentElement);
  1237. /* Recurse for frames and iframes. */
  1238. try {
  1239. toArray(document.querySelectorAll('frame, iframe, object[type^="text/html"], object[type^="application/xhtml+xml"]')).forEach(function (elem) {
  1240. execute(elem.contentDocument);
  1241. });
  1242. } catch (e) {
  1243. /* Catch exceptions for out-of-domain access, but do not do anything with them. */
  1244. }
  1245. })(document);
  1246. /* When there are IFRAMEs etc. with their own main content element,
  1247. * scrolling them into view as soon as they are found would override the
  1248. * main document’s scroll position. By scrolling the nested elements into
  1249. * view *first*, and the main document’s main content element *last*,
  1250. * things behave more as expected.
  1251. */
  1252. var contentElement;
  1253. while ((contentElement = contentElements.pop())) {
  1254. contentElement.scrollIntoView({
  1255. behavior: 'smooth',
  1256. block: 'start',
  1257. inline: 'start'
  1258. });
  1259. };
  1260. })();