main.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  1. // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
  2. 'use strict';
  3. // <Polyfills>
  4. if (!document.scrollingElement) document.scrollingElement = document.documentElement;
  5. if (!NodeList.prototype.forEach) NodeList.prototype.forEach = Array.prototype.forEach;
  6. if (!Element.prototype.matches) {
  7. Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.webkitMatchesSelector;
  8. }
  9. if (!Element.prototype.closest) {
  10. Element.prototype.closest = function (s) {
  11. let el = this;
  12. do {
  13. if (el.matches(s)) return el;
  14. el = el.parentElement;
  15. } while (el);
  16. return null;
  17. };
  18. }
  19. if (!Element.prototype.remove) Element.prototype.remove = function () { if (this.parentNode) this.parentNode.removeChild(this); };
  20. // </Polyfills>
  21. // <Utils>
  22. function xmlHttpRequestJson(req) {
  23. let json = req.response;
  24. if (req.responseType !== 'json') { // IE11
  25. try {
  26. json = JSON.parse(req.responseText);
  27. } catch (ex) {
  28. json = null;
  29. }
  30. }
  31. return json;
  32. }
  33. // </Utils>
  34. // <Global context>
  35. /* eslint-disable no-var */
  36. var context;
  37. /* eslint-enable no-var */
  38. (function parseJsonVars() {
  39. const jsonVars = document.getElementById('jsonVars');
  40. const json = JSON.parse(jsonVars.innerHTML);
  41. jsonVars.outerHTML = '';
  42. context = json.context;
  43. context.ajax_loading = false;
  44. context.i18n = json.i18n;
  45. context.shortcuts = json.shortcuts;
  46. context.urls = json.urls;
  47. context.icons = json.icons;
  48. context.icons.read = decodeURIComponent(context.icons.read);
  49. context.icons.unread = decodeURIComponent(context.icons.unread);
  50. context.extensions = json.extensions;
  51. }());
  52. // </Global context>
  53. function badAjax(reload) {
  54. openNotification(context.i18n.notif_request_failed, 'bad');
  55. if (reload) {
  56. setTimeout(function () { location.reload(); }, 2000);
  57. }
  58. return true;
  59. }
  60. function needsScroll(elem) {
  61. const winBottom = document.scrollingElement.scrollTop + document.scrollingElement.clientHeight;
  62. const elemTop = elem.offsetParent.offsetTop + elem.offsetTop;
  63. const elemBottom = elemTop + elem.offsetHeight;
  64. if (elemTop < document.scrollingElement.scrollTop || elemBottom > winBottom) {
  65. return elemTop - (document.scrollingElement.clientHeight / 2);
  66. }
  67. return 0;
  68. }
  69. function str2int(str) {
  70. if (!str) {
  71. return 0;
  72. }
  73. return parseInt(str.replace(/\D/g, ''), 10) || 0;
  74. }
  75. function numberFormat(nStr) {
  76. if (nStr < 0) {
  77. return 0;
  78. }
  79. // http://www.mredkj.com/javascript/numberFormat.html
  80. nStr += '';
  81. const x = nStr.split('.');
  82. const x2 = x.length > 1 ? '.' + x[1] : '';
  83. const rgx = /(\d+)(\d{3})/;
  84. let x1 = x[0];
  85. while (rgx.test(x1)) {
  86. x1 = x1.replace(rgx, '$1 $2');
  87. }
  88. return x1 + x2;
  89. }
  90. function incLabel(p, inc, spaceAfter) {
  91. const i = str2int(p) + inc;
  92. return i > 0 ? ((spaceAfter ? '' : ' ') + '(' + numberFormat(i) + ')' + (spaceAfter ? ' ' : '')) : '';
  93. }
  94. function incUnreadsFeed(article, feed_id, nb) {
  95. // Update unread: feed
  96. let elem = document.getElementById(feed_id);
  97. let feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  98. const feed_priority = elem ? str2int(elem.getAttribute('data-priority')) : 0;
  99. if (elem) {
  100. elem.setAttribute('data-unread', feed_unreads + nb);
  101. elem = elem.querySelector('.item-title');
  102. if (elem) {
  103. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  104. }
  105. }
  106. // Update unread: category
  107. elem = document.getElementById(feed_id);
  108. elem = elem ? elem.closest('.category') : null;
  109. if (elem) {
  110. feed_unreads = str2int(elem.getAttribute('data-unread'));
  111. elem.setAttribute('data-unread', feed_unreads + nb);
  112. elem = elem.querySelector('.title');
  113. if (elem) {
  114. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  115. }
  116. }
  117. // Update unread: all
  118. if (feed_priority > 0) {
  119. elem = document.querySelector('#aside_feed .all .title');
  120. if (elem) {
  121. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  122. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  123. }
  124. }
  125. // Update unread: favourites
  126. if (article && article.closest('div').classList.contains('favorite')) {
  127. elem = document.querySelector('#aside_feed .favorites .title');
  128. if (elem) {
  129. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  130. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  131. }
  132. }
  133. let isCurrentView = false;
  134. // Update unread: title
  135. document.title = document.title.replace(/^((?:\([\s0-9]+\) )?)/, function (m, p1) {
  136. const feed = document.getElementById(feed_id);
  137. if (article || (feed && feed.closest('.active'))) {
  138. isCurrentView = true;
  139. return incLabel(p1, nb, true);
  140. } else if (document.querySelector('.all.active')) {
  141. isCurrentView = feed_priority > 0;
  142. return incLabel(p1, feed_priority > 0 ? nb : 0, true);
  143. } else {
  144. return p1;
  145. }
  146. });
  147. return isCurrentView;
  148. }
  149. function incUnreadsTag(tag_id, nb) {
  150. let t = document.getElementById(tag_id);
  151. if (t) {
  152. const unreads = str2int(t.getAttribute('data-unread'));
  153. t.setAttribute('data-unread', unreads + nb);
  154. t.querySelector('.item-title').setAttribute('data-unread', numberFormat(unreads + nb));
  155. }
  156. t = document.querySelector('.category.tags .title');
  157. if (t) {
  158. const unreads = str2int(t.getAttribute('data-unread'));
  159. t.setAttribute('data-unread', numberFormat(unreads + nb));
  160. }
  161. }
  162. function removeArticle(div) {
  163. if (!div || div.classList.contains('not_read') || (context.auto_mark_article && div.classList.contains('active'))) {
  164. return;
  165. }
  166. let scrollTop = box_to_follow.scrollTop;
  167. let dirty = false;
  168. const p = div.previousElementSibling;
  169. const n = div.nextElementSibling;
  170. if (p && p.classList.contains('day') && n && n.classList.contains('day')) {
  171. scrollTop -= p.offsetHeight;
  172. dirty = true;
  173. p.remove();
  174. }
  175. if (div.offsetHeight > 0 && div.offsetParent.offsetTop + div.offsetTop + div.offsetHeight < scrollTop) {
  176. scrollTop -= div.offsetHeight;
  177. dirty = true;
  178. }
  179. div.remove();
  180. if (dirty) {
  181. box_to_follow.scrollTop = scrollTop;
  182. }
  183. }
  184. const pending_entries = {};
  185. let mark_read_queue = [];
  186. function send_mark_read_queue(queue, asRead, callback) {
  187. if (!queue || queue.length === 0) {
  188. if (callback) {
  189. callback();
  190. }
  191. return;
  192. }
  193. const req = new XMLHttpRequest();
  194. req.open('POST', '.?c=entry&a=read' + (asRead ? '' : '&is_read=0'), true);
  195. req.responseType = 'json';
  196. req.onerror = function (e) {
  197. for (let i = queue.length - 1; i >= 0; i--) {
  198. delete pending_entries['flux_' + queue[i]];
  199. }
  200. badAjax(this.status == 403);
  201. };
  202. req.onload = function (e) {
  203. if (this.status != 200) {
  204. return req.onerror(e);
  205. }
  206. const json = xmlHttpRequestJson(this);
  207. if (!json) {
  208. return req.onerror(e);
  209. }
  210. for (let i = queue.length - 1; i >= 0; i--) {
  211. const div = document.getElementById('flux_' + queue[i]);
  212. const myIcons = context.icons;
  213. let inc = 0;
  214. if (div.classList.contains('not_read')) {
  215. div.classList.remove('not_read');
  216. div.querySelectorAll('a.read').forEach(function (a) {
  217. a.href = a.href.replace('&is_read=0', '') + '&is_read=1';
  218. });
  219. div.querySelectorAll('a.read > .icon').forEach(function (img) { img.outerHTML = myIcons.read; });
  220. inc--;
  221. if (context.auto_remove_article) {
  222. removeArticle(div);
  223. }
  224. } else {
  225. div.classList.add('not_read');
  226. div.classList.add('keep_unread'); // Split for IE11
  227. div.querySelectorAll('a.read').forEach(function (a) {
  228. a.href = a.href.replace('&is_read=1', '');
  229. });
  230. div.querySelectorAll('a.read > .icon').forEach(function (img) { img.outerHTML = myIcons.unread; });
  231. inc++;
  232. }
  233. const feed_link = div.querySelector('.website > a, a.website');
  234. if (feed_link) {
  235. const feed_url = feed_link.href;
  236. const feed_id = feed_url.substr(feed_url.lastIndexOf('f_'));
  237. incUnreadsFeed(div, feed_id, inc);
  238. }
  239. delete pending_entries['flux_' + queue[i]];
  240. }
  241. faviconNbUnread();
  242. if (json.tags) {
  243. const tagIds = Object.keys(json.tags);
  244. for (let i = tagIds.length - 1; i >= 0; i--) {
  245. const tagId = tagIds[i];
  246. incUnreadsTag(tagId, (asRead ? -1 : 1) * json.tags[tagId].length);
  247. }
  248. }
  249. toggle_bigMarkAsRead_button();
  250. onScroll();
  251. if (callback) {
  252. callback();
  253. }
  254. };
  255. req.setRequestHeader('Content-Type', 'application/json');
  256. req.send(JSON.stringify({
  257. ajax: true,
  258. _csrf: context.csrf,
  259. id: queue,
  260. }));
  261. }
  262. let send_mark_read_queue_timeout = 0;
  263. function send_mark_queue_tick(callback) {
  264. send_mark_read_queue_timeout = 0;
  265. const queue = mark_read_queue.slice(0);
  266. mark_read_queue = [];
  267. send_mark_read_queue(queue, true, callback);
  268. }
  269. const delayedFunction = send_mark_queue_tick;
  270. function delayedClick(a) {
  271. if (a) {
  272. delayedFunction(function () { a.click(); });
  273. }
  274. }
  275. function mark_read(div, only_not_read, asBatch) {
  276. if (!div || !div.id || context.anonymous ||
  277. (only_not_read && !div.classList.contains('not_read'))) {
  278. return false;
  279. }
  280. if (pending_entries[div.id]) {
  281. return false;
  282. }
  283. pending_entries[div.id] = true;
  284. const asRead = div.classList.contains('not_read');
  285. const entryId = div.id.replace(/^flux_/, '');
  286. if (asRead && asBatch) {
  287. mark_read_queue.push(entryId);
  288. if (send_mark_read_queue_timeout == 0) {
  289. send_mark_read_queue_timeout = setTimeout(function () { send_mark_queue_tick(null); }, 1000);
  290. }
  291. } else {
  292. const queue = [entryId];
  293. send_mark_read_queue(queue, asRead);
  294. }
  295. }
  296. function mark_previous_read(div) {
  297. while (div) {
  298. mark_read(div, true, true);
  299. div = div.previousElementSibling;
  300. }
  301. }
  302. function mark_favorite(div) {
  303. if (!div) {
  304. return false;
  305. }
  306. const a = div.querySelector('a.bookmark');
  307. const url = a ? a.href : '';
  308. if (!url) {
  309. return false;
  310. }
  311. if (pending_entries[div.id]) {
  312. return false;
  313. }
  314. pending_entries[div.id] = true;
  315. const req = new XMLHttpRequest();
  316. req.open('POST', url, true);
  317. req.responseType = 'json';
  318. req.onerror = function (e) {
  319. delete pending_entries[div.id];
  320. badAjax(this.status == 403);
  321. };
  322. req.onload = function (e) {
  323. if (this.status != 200) {
  324. return req.onerror(e);
  325. }
  326. const json = xmlHttpRequestJson(this);
  327. if (!json) {
  328. return req.onerror(e);
  329. }
  330. let inc = 0;
  331. if (div.classList.contains('favorite')) {
  332. div.classList.remove('favorite');
  333. inc--;
  334. } else {
  335. div.classList.add('favorite');
  336. inc++;
  337. }
  338. div.querySelectorAll('a.bookmark').forEach(function (a) { a.href = json.url; });
  339. div.querySelectorAll('a.bookmark > .icon').forEach(function (img) { img.outerHTML = json.icon; });
  340. const favourites = document.querySelector('#aside_feed .favorites .title');
  341. if (favourites) {
  342. favourites.textContent = favourites.textContent.replace(/((?: \([\s0-9]+\))?\s*)$/, function (m, p1) {
  343. return incLabel(p1, inc, false);
  344. });
  345. }
  346. if (div.classList.contains('not_read')) {
  347. const elem = document.querySelector('#aside_feed .favorites .title');
  348. const feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  349. if (elem) {
  350. elem.setAttribute('data-unread', numberFormat(feed_unreads + inc));
  351. }
  352. }
  353. delete pending_entries[div.id];
  354. };
  355. req.setRequestHeader('Content-Type', 'application/json');
  356. req.send(JSON.stringify({
  357. ajax: true,
  358. _csrf: context.csrf,
  359. }));
  360. }
  361. const freshrssOpenArticleEvent = document.createEvent('Event');
  362. freshrssOpenArticleEvent.initEvent('freshrss:openArticle', true, true);
  363. function toggleContent(new_active, old_active, skipping) {
  364. // If skipping, move current without activating or marking as read
  365. if (!new_active) {
  366. return;
  367. }
  368. if (context.does_lazyload && !skipping) {
  369. new_active.querySelectorAll('img[data-original], iframe[data-original]').forEach(function (el) {
  370. el.src = el.getAttribute('data-original');
  371. el.removeAttribute('data-original');
  372. });
  373. }
  374. if (old_active !== new_active) {
  375. if (!skipping) {
  376. new_active.classList.add('active');
  377. }
  378. new_active.classList.add('current');
  379. if (old_active) {
  380. old_active.classList.remove('active');
  381. old_active.classList.remove('current'); // Split for IE11
  382. if (context.auto_remove_article) {
  383. removeArticle(old_active);
  384. }
  385. }
  386. } else {
  387. new_active.classList.toggle('active');
  388. }
  389. const relative_move = context.current_view === 'global';
  390. const box_to_move = relative_move ? document.getElementById('panel') : document.scrollingElement;
  391. if (context.sticky_post) { // Stick the article to the top when opened
  392. const prev_article = new_active.previousElementSibling;
  393. const nav_menu = document.querySelector('.nav_menu');
  394. let nav_menu_height = 0;
  395. if (getComputedStyle(nav_menu).position === 'fixed' || getComputedStyle(nav_menu).position === 'sticky') {
  396. nav_menu_height = nav_menu.offsetHeight;
  397. }
  398. let new_pos = new_active.offsetParent.offsetTop + new_active.offsetTop - nav_menu_height;
  399. if (prev_article && prev_article.offsetParent && new_active.offsetTop - prev_article.offsetTop <= 150) {
  400. new_pos = prev_article.offsetParent.offsetTop + prev_article.offsetTop - nav_menu_height;
  401. if (relative_move) {
  402. new_pos -= box_to_move.offsetTop;
  403. }
  404. }
  405. if (skipping) {
  406. // when skipping, this feels more natural if it’s not so near the top
  407. new_pos -= document.body.clientHeight / 4;
  408. }
  409. box_to_move.scrollTop = new_pos;
  410. }
  411. if (new_active.classList.contains('active') && !skipping) {
  412. if (context.auto_mark_article) {
  413. mark_read(new_active, true, true);
  414. }
  415. new_active.dispatchEvent(freshrssOpenArticleEvent);
  416. }
  417. onScroll();
  418. }
  419. function prev_entry(skipping) {
  420. const old_active = document.querySelector('.flux.current');
  421. let new_active = old_active;
  422. if (new_active) {
  423. do new_active = new_active.previousElementSibling;
  424. while (new_active && !new_active.classList.contains('flux'));
  425. if (!new_active) {
  426. prev_feed();
  427. }
  428. } else {
  429. new_active = document.querySelector('.flux');
  430. }
  431. toggleContent(new_active, old_active, skipping);
  432. }
  433. function next_entry(skipping) {
  434. const old_active = document.querySelector('.flux.current');
  435. let new_active = old_active;
  436. if (new_active) {
  437. do new_active = new_active.nextElementSibling;
  438. while (new_active && !new_active.classList.contains('flux'));
  439. if (!new_active) {
  440. next_feed();
  441. }
  442. } else {
  443. new_active = document.querySelector('.flux');
  444. }
  445. toggleContent(new_active, old_active, skipping);
  446. }
  447. function next_unread_entry(skipping) {
  448. const old_active = document.querySelector('.flux.current');
  449. let new_active = old_active;
  450. if (new_active) {
  451. do new_active = new_active.nextElementSibling;
  452. while (new_active && !new_active.classList.contains('not_read'));
  453. if (!new_active) {
  454. next_feed();
  455. }
  456. } else {
  457. new_active = document.querySelector('.not_read');
  458. }
  459. toggleContent(new_active, old_active, skipping);
  460. }
  461. function prev_feed() {
  462. let found = false;
  463. let adjacent = null;
  464. const feeds = document.querySelectorAll('#aside_feed .feed');
  465. for (let i = feeds.length - 1; i >= 0; i--) {
  466. const feed = feeds[i];
  467. if (feed.classList.contains('active')) {
  468. found = true;
  469. continue;
  470. }
  471. if (!found) {
  472. continue;
  473. }
  474. if (getComputedStyle(feed).display === 'none') {
  475. continue;
  476. }
  477. if (feed.dataset.unread != 0) {
  478. return delayedClick(feed.querySelector('a.item-title'));
  479. } else if (adjacent === null) {
  480. adjacent = feed;
  481. }
  482. }
  483. if (found) {
  484. delayedClick(adjacent.querySelector('a.item-title'));
  485. } else {
  486. last_feed();
  487. }
  488. }
  489. function next_feed() {
  490. let found = false;
  491. let adjacent = null;
  492. const feeds = document.querySelectorAll('#aside_feed .feed');
  493. for (let i = 0; i < feeds.length; i++) {
  494. const feed = feeds[i];
  495. if (feed.classList.contains('active')) {
  496. found = true;
  497. continue;
  498. }
  499. if (!found) {
  500. continue;
  501. }
  502. if (getComputedStyle(feed).display === 'none') {
  503. continue;
  504. }
  505. if (feed.dataset.unread != 0) {
  506. return delayedClick(feed.querySelector('a.item-title'));
  507. } else if (adjacent === null) {
  508. adjacent = feed;
  509. }
  510. }
  511. if (found) {
  512. delayedClick(adjacent.querySelector('a.item-title'));
  513. } else {
  514. first_feed();
  515. }
  516. }
  517. function first_feed() {
  518. const a = document.querySelector('#aside_feed .category.active .feed:not([data-unread="0"]) a.item-title');
  519. delayedClick(a);
  520. }
  521. function last_feed() {
  522. const links = document.querySelectorAll('#aside_feed .category.active .feed:not([data-unread="0"]) a.item-title');
  523. if (links && links.length > 0) {
  524. delayedClick(links[links.length - 1]);
  525. }
  526. }
  527. function prev_category() {
  528. const active_cat = document.querySelector('#aside_feed .category.active');
  529. if (active_cat) {
  530. let cat = active_cat;
  531. do cat = cat.previousElementSibling;
  532. while (cat && getComputedStyle(cat).display === 'none');
  533. if (cat) {
  534. delayedClick(cat.querySelector('a.title'));
  535. }
  536. } else {
  537. last_category();
  538. }
  539. }
  540. function next_category() {
  541. const active_cat = document.querySelector('#aside_feed .category.active');
  542. if (active_cat) {
  543. let cat = active_cat;
  544. do cat = cat.nextElementSibling;
  545. while (cat && getComputedStyle(cat).display === 'none');
  546. if (cat) {
  547. delayedClick(cat.querySelector('a.title'));
  548. }
  549. } else {
  550. first_category();
  551. }
  552. }
  553. function next_unread_category() {
  554. const active_cat = document.querySelector('#aside_feed .category.active');
  555. if (active_cat) {
  556. let cat = active_cat;
  557. do cat = cat.nextElementSibling;
  558. while (cat && cat.getAttribute('data-unread') <= 0);
  559. if (cat) {
  560. delayedClick(cat.querySelector('a.title'));
  561. }
  562. } else {
  563. first_category();
  564. }
  565. }
  566. function first_category() {
  567. const a = document.querySelector('#aside_feed .category:not([data-unread="0"]) a.title');
  568. delayedClick(a);
  569. }
  570. function last_category() {
  571. const links = document.querySelectorAll('#aside_feed .category:not([data-unread="0"]) a.title');
  572. if (links && links.length > 0) {
  573. delayedClick(links[links.length - 1]);
  574. }
  575. }
  576. function collapse_entry() {
  577. const flux_current = document.querySelector('.flux.current');
  578. toggleContent(flux_current, flux_current, false);
  579. }
  580. function toggle_media() {
  581. const media = document.querySelector('.flux.current video,.flux.current audio');
  582. if (media === null) {
  583. return;
  584. }
  585. if (media.paused) {
  586. media.play();
  587. } else {
  588. media.pause();
  589. }
  590. }
  591. function user_filter(key) {
  592. const filter = document.getElementById('dropdown-query');
  593. const filters = filter.parentElement.querySelectorAll('.dropdown-menu > .query > a');
  594. if (typeof key === 'undefined') {
  595. if (!filters.length) {
  596. return;
  597. }
  598. // Display the filter div
  599. location.hash = filter.id;
  600. // Force scrolling to the filter div
  601. const scroll = needsScroll(document.querySelector('.header'));
  602. if (scroll !== 0) {
  603. document.scrollingElement.scrollTop = scroll;
  604. }
  605. // Force the key value if there is only one action, so we can trigger it automatically
  606. if (filters.length === 1) {
  607. key = 1;
  608. } else {
  609. return;
  610. }
  611. }
  612. // Trigger selected share action
  613. key = parseInt(key);
  614. if (key <= filters.length) {
  615. filters[key - 1].click();
  616. }
  617. }
  618. function auto_share(key) {
  619. const share = document.querySelector('.flux.current.active .dropdown-target[id^="dropdown-share"]');
  620. if (!share) {
  621. return;
  622. }
  623. const shares = share.parentElement.querySelectorAll('.dropdown-menu .item a');
  624. if (typeof key === 'undefined') {
  625. // Display the share div
  626. location.hash = share.id;
  627. // Force scrolling to the share div
  628. const scrollTop = needsScroll(share.closest('.bottom'));
  629. if (scrollTop !== 0) {
  630. document.scrollingElement.scrollTop = scrollTop;
  631. }
  632. // Force the key value if there is only one action, so we can trigger it automatically
  633. if (shares.length === 1) {
  634. key = 1;
  635. } else {
  636. return;
  637. }
  638. }
  639. // Trigger selected share action and hide the share div
  640. key = parseInt(key);
  641. if (key <= shares.length) {
  642. shares[key - 1].click();
  643. share.parentElement.querySelector('.dropdown-menu + a.dropdown-close').click();
  644. }
  645. }
  646. let box_to_follow;
  647. function onScroll() {
  648. if (!box_to_follow) {
  649. return;
  650. }
  651. if (context.auto_mark_scroll) {
  652. const hidden_px = -5; // negative = pixels over the edge
  653. const minTop = hidden_px + box_to_follow.scrollTop;
  654. document.querySelectorAll('.not_read:not(.keep_unread)').forEach(function (div) {
  655. if (div.offsetHeight > 0 &&
  656. div.offsetParent.offsetTop + div.offsetTop + div.offsetHeight < minTop) {
  657. mark_read(div, true, true);
  658. }
  659. });
  660. }
  661. let streamFooter;
  662. if (context.auto_load_more && (streamFooter = document.getElementById('stream-footer'))) {
  663. if (box_to_follow.offsetHeight > 0 &&
  664. box_to_follow.scrollTop + box_to_follow.offsetHeight + (window.innerHeight / 2) >= streamFooter.offsetTop) {
  665. // Too close to the last pre-loaded article
  666. load_more_posts();
  667. } else {
  668. const after = document.querySelectorAll('.flux.current ~ .flux').length;
  669. if (after > 0 && after <= 5) {
  670. // Too few pre-loaded articles
  671. load_more_posts();
  672. }
  673. }
  674. }
  675. }
  676. function init_posts() {
  677. if (context.auto_load_more || context.auto_mark_scroll || context.auto_remove_article) {
  678. box_to_follow = context.current_view === 'global' ? document.getElementById('panel') : document.scrollingElement;
  679. let lastScroll = 0; // Throttle
  680. let timerId = 0;
  681. (box_to_follow === document.scrollingElement ? window : box_to_follow).onscroll = function () {
  682. clearTimeout(timerId);
  683. if (lastScroll + 500 < Date.now()) {
  684. lastScroll = Date.now();
  685. onScroll();
  686. } else {
  687. timerId = setTimeout(onScroll, 500);
  688. }
  689. };
  690. onScroll();
  691. }
  692. if (!navigator.share && document.styleSheets.length > 0) {
  693. // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
  694. // do not show the menu entry if browser does not support navigator.share
  695. document.styleSheets[0].insertRule(
  696. 'button.as-link[data-type="web-sharing-api"] {display: none !important;}',
  697. document.styleSheets[0].cssRules.length
  698. );
  699. }
  700. }
  701. function rememberOpenCategory(category_id, isOpen) {
  702. if (context.display_categories === 'remember') {
  703. const open_categories = JSON.parse(localStorage.getItem('FreshRSS_open_categories') || '{}');
  704. if (isOpen) {
  705. open_categories[category_id] = true;
  706. } else {
  707. delete open_categories[category_id];
  708. }
  709. localStorage.setItem('FreshRSS_open_categories', JSON.stringify(open_categories));
  710. }
  711. }
  712. function openCategory(category_id) {
  713. const category_element = document.getElementById(category_id);
  714. if (!category_element) return;
  715. category_element.querySelector('.tree-folder-items').classList.add('active');
  716. const img = category_element.querySelector('a.dropdown-toggle img');
  717. if (!img) return;
  718. img.src = img.src.replace('/icons/down.', '/icons/up.');
  719. img.alt = '🔼';
  720. }
  721. function loadJs(name) {
  722. if (!document.getElementById(name)) {
  723. const script = document.createElement('script');
  724. script.setAttribute('id', name);
  725. script.setAttribute('src', '../scripts/' + name + '?' + context.mtime[name]);
  726. script.setAttribute('defer', 'defer');
  727. script.setAttribute('async', 'async');
  728. document.head.appendChild(script);
  729. }
  730. }
  731. function init_column_categories() {
  732. if (context.current_view !== 'normal' && context.current_view !== 'reader') {
  733. return;
  734. }
  735. // Restore sidebar scroll position
  736. document.getElementById('sidebar').scrollTop = +sessionStorage.getItem('FreshRSS_sidebar_scrollTop');
  737. // Restore open categories
  738. if (context.display_categories === 'remember') {
  739. const open_categories = JSON.parse(localStorage.getItem('FreshRSS_open_categories') || '{}');
  740. Object.keys(open_categories).forEach(function (category_id) {
  741. openCategory(category_id);
  742. });
  743. }
  744. document.getElementById('aside_feed').onclick = function (ev) {
  745. let a = ev.target.closest('.tree-folder > .tree-folder-title > a.dropdown-toggle');
  746. if (a) {
  747. const icon = a.querySelector('.icon');
  748. const category_id = a.closest('.category').id;
  749. if (icon.alt === '🔽' || icon.innerHTML === '🔽') {
  750. if (icon.src) {
  751. icon.src = icon.src.replace('/icons/down.', '/icons/up.');
  752. icon.alt = '🔼';
  753. } else {
  754. icon.innerHTML = '🔼';
  755. }
  756. rememberOpenCategory(category_id, true);
  757. } else {
  758. if (icon.src) {
  759. icon.src = icon.src.replace('/icons/up.', '/icons/down.');
  760. icon.alt = '🔽';
  761. } else {
  762. icon.innerHTML = '🔽';
  763. }
  764. rememberOpenCategory(category_id, false);
  765. }
  766. const ul = a.closest('li').querySelector('.tree-folder-items');
  767. let nbVisibleItems = 0;
  768. for (let i = ul.children.length - 1; i >= 0; i--) {
  769. if (ul.children[i].offsetHeight) {
  770. nbVisibleItems++;
  771. }
  772. }
  773. ul.classList.toggle('active');
  774. // CSS transition does not work on max-height:auto
  775. ul.style.maxHeight = ul.classList.contains('active') ? (nbVisibleItems * 4) + 'em' : 0;
  776. return false;
  777. }
  778. a = ev.target.closest('.tree-folder-items > .feed .dropdown-toggle');
  779. if (a) {
  780. loadJs('extra.js');
  781. loadJs('feed.js');
  782. const itemId = a.closest('.item').id;
  783. const templateId = itemId.substring(0, 2) === 't_' ? 'tag_config_template' : 'feed_config_template';
  784. const id = itemId.substr(2);
  785. const feed_web = a.getAttribute('data-fweb');
  786. const div = a.parentElement;
  787. const dropdownMenu = div.querySelector('.dropdown-menu');
  788. const template = document.getElementById(templateId)
  789. .innerHTML.replace(/------/g, id).replace('http://example.net/', feed_web);
  790. if (!dropdownMenu) {
  791. a.href = '#dropdown-' + id;
  792. div.querySelector('.dropdown-target').id = 'dropdown-' + id;
  793. div.insertAdjacentHTML('beforeend', template);
  794. if (feed_web.length < 1) {
  795. div.querySelector('.item.link.website').remove();
  796. }
  797. const b = div.querySelector('button.confirm');
  798. if (b) {
  799. b.disabled = false;
  800. }
  801. } else if (getComputedStyle(dropdownMenu).display === 'none') {
  802. const id2 = div.closest('.item').id.substr(2);
  803. a.href = '#dropdown-' + id2;
  804. } else {
  805. a.href = '#close';
  806. }
  807. return true;
  808. }
  809. return true;
  810. };
  811. }
  812. function init_shortcuts() {
  813. Object.keys(context.shortcuts).forEach(function (k) {
  814. context.shortcuts[k] = (context.shortcuts[k] || '').toUpperCase();
  815. });
  816. document.addEventListener('keydown', ev => {
  817. if (ev.target.closest('input, textarea') ||
  818. ev.ctrlKey || ev.metaKey || (ev.altKey && ev.shiftKey)) {
  819. return;
  820. }
  821. const s = context.shortcuts;
  822. let k = (ev.key.trim() || ev.code || 'Space').toUpperCase();
  823. // IE11
  824. if (k === 'SPACEBAR') k = 'SPACE';
  825. else if (k === 'DEL') k = 'DELETE';
  826. else if (k === 'ESC') k = 'ESCAPE';
  827. if (location.hash.match(/^#dropdown-/)) {
  828. const n = parseInt(k);
  829. if (n) {
  830. if (location.hash === '#dropdown-query') {
  831. user_filter(n);
  832. } else {
  833. auto_share(n);
  834. }
  835. ev.preventDefault();
  836. return;
  837. }
  838. }
  839. if (k === s.actualize) {
  840. const btn = document.getElementById('actualize');
  841. if (btn) {
  842. btn.click();
  843. }
  844. ev.preventDefault();
  845. return;
  846. }
  847. if (k === s.next_entry) {
  848. if (ev.altKey) {
  849. next_category();
  850. } else if (ev.shiftKey) {
  851. next_feed();
  852. } else {
  853. next_entry(false);
  854. }
  855. ev.preventDefault();
  856. return;
  857. }
  858. if (k === s.next_unread_entry) {
  859. if (ev.altKey) {
  860. next_unread_category();
  861. } else if (ev.shiftKey) {
  862. next_feed();
  863. } else {
  864. next_unread_entry(false);
  865. }
  866. ev.preventDefault();
  867. return;
  868. }
  869. if (k === s.prev_entry) {
  870. if (ev.altKey) {
  871. prev_category();
  872. } else if (ev.shiftKey) {
  873. prev_feed();
  874. } else {
  875. prev_entry(false);
  876. }
  877. ev.preventDefault();
  878. return;
  879. }
  880. if (k === s.mark_read) {
  881. if (ev.altKey) {
  882. mark_previous_read(document.querySelector('.flux.current'));
  883. } else if (ev.shiftKey) {
  884. document.querySelector('.nav_menu .read_all').click();
  885. } else { // Toggle the read state
  886. mark_read(document.querySelector('.flux.current'), false, false);
  887. }
  888. ev.preventDefault();
  889. return;
  890. }
  891. if (k === s.first_entry) {
  892. if (ev.altKey) {
  893. first_category();
  894. } else if (ev.shiftKey) {
  895. first_feed();
  896. } else {
  897. const old_active = document.querySelector('.flux.current');
  898. const first = document.querySelector('.flux');
  899. if (first.classList.contains('flux')) {
  900. toggleContent(first, old_active, false);
  901. }
  902. }
  903. ev.preventDefault();
  904. return;
  905. }
  906. if (k === s.last_entry) {
  907. if (ev.altKey) {
  908. last_category();
  909. } else if (ev.shiftKey) {
  910. last_feed();
  911. } else {
  912. const old_active = document.querySelector('.flux.current');
  913. const last = document.querySelector('.flux:last-of-type');
  914. if (last.classList.contains('flux')) {
  915. toggleContent(last, old_active, false);
  916. }
  917. }
  918. ev.preventDefault();
  919. return;
  920. }
  921. if (ev.altKey || ev.shiftKey) {
  922. return;
  923. }
  924. if (k === s.mark_favorite) { // Toggle the favorite state
  925. mark_favorite(document.querySelector('.flux.current'));
  926. ev.preventDefault();
  927. return;
  928. }
  929. if (k === s.go_website) {
  930. if (context.auto_mark_site) {
  931. mark_read(document.querySelector('.flux.current'), true, false);
  932. }
  933. const link_go_website = document.querySelector('.flux.current a.go_website');
  934. if (link_go_website) {
  935. const newWindow = window.open();
  936. if (newWindow) {
  937. newWindow.opener = null;
  938. newWindow.location = link_go_website.href;
  939. ev.preventDefault();
  940. }
  941. }
  942. return;
  943. }
  944. if (k === s.skip_next_entry) { next_entry(true); ev.preventDefault(); return; }
  945. if (k === s.skip_prev_entry) { prev_entry(true); ev.preventDefault(); return; }
  946. if (k === s.collapse_entry) { collapse_entry(); ev.preventDefault(); return; }
  947. if (k === s.auto_share) { auto_share(); ev.preventDefault(); return; }
  948. if (k === s.user_filter) { user_filter(); ev.preventDefault(); return; }
  949. if (k === s.load_more) { load_more_posts(); ev.preventDefault(); return; }
  950. if (k === s.close_dropdown) { location.hash = null; ev.preventDefault(); return; }
  951. if (k === s.help) { window.open(context.urls.help); ev.preventDefault(); return; }
  952. if (k === s.focus_search) { document.getElementById('search').focus(); ev.preventDefault(); return; }
  953. if (k === s.normal_view) { delayedClick(document.querySelector('#nav_menu_views .view-normal')); ev.preventDefault(); return; }
  954. if (k === s.reading_view) { delayedClick(document.querySelector('#nav_menu_views .view-reader')); ev.preventDefault(); return; }
  955. if (k === s.global_view) { delayedClick(document.querySelector('#nav_menu_views .view-global')); ev.preventDefault(); return; }
  956. if (k === s.rss_view) { delayedClick(document.querySelector('#nav_menu_views .view-rss')); ev.preventDefault(); return; }
  957. if (k === s.toggle_media) { toggle_media(); ev.preventDefault(); }
  958. });
  959. }
  960. function init_stream(stream) {
  961. stream.onclick = function (ev) {
  962. let el = ev.target.closest('.flux a.read');
  963. if (el) {
  964. mark_read(el.closest('.flux'), false, false);
  965. return false;
  966. }
  967. el = ev.target.closest('.flux a.bookmark');
  968. if (el) {
  969. mark_favorite(el.closest('.flux'));
  970. return false;
  971. }
  972. el = ev.target.closest('.dynamictags');
  973. if (el) {
  974. loadDynamicTags(el);
  975. return true;
  976. }
  977. el = ev.target.closest('.item.title > a');
  978. if (el) { // Allow default control/command-click behaviour such as open in background-tab
  979. return ev.ctrlKey || ev.metaKey;
  980. }
  981. el = ev.target.closest('.flux .content .text a');
  982. if (el) {
  983. if (!el.closest('div').classList.contains('author')) {
  984. el.target = '_blank';
  985. el.rel = 'noreferrer';
  986. }
  987. return true;
  988. }
  989. el = ev.target.closest('.item.share > button[data-type="print"]');
  990. if (el) { // Print
  991. const tmp_window = window.open();
  992. for (let i = 0; i < document.styleSheets.length; i++) {
  993. tmp_window.document.writeln('<link href="' + document.styleSheets[i].href + '" rel="stylesheet" type="text/css" />');
  994. }
  995. tmp_window.document.writeln(el.closest('.flux_content').querySelector('.content').innerHTML);
  996. tmp_window.document.close();
  997. tmp_window.focus();
  998. tmp_window.print();
  999. tmp_window.close();
  1000. return false;
  1001. }
  1002. el = ev.target.closest('.item.share > button[data-type="clipboard"]');
  1003. if (el) { // Clipboard
  1004. if (navigator.clipboard) {
  1005. navigator.clipboard.writeText(el.dataset.url)
  1006. .then(() => {
  1007. toggleClass(el, 'error');
  1008. })
  1009. .catch(e => {
  1010. console.log(e);
  1011. toggleClass(el, 'error');
  1012. });
  1013. } else {
  1014. // fallback, if navigator.clipboard is not available f.e. if access is not via https or localhost
  1015. const inputElement = document.createElement('input');
  1016. inputElement.value = el.dataset.url;
  1017. document.body.appendChild(inputElement);
  1018. inputElement.select();
  1019. if (document.execCommand && document.execCommand('copy')) {
  1020. toggleClass(el, 'ok');
  1021. } else {
  1022. console.log('document.execCommand("copy") failed');
  1023. toggleClass(el, 'error');
  1024. }
  1025. inputElement.remove();
  1026. }
  1027. return false;
  1028. }
  1029. el = ev.target.closest('.item.share > button[data-type="web-sharing-api"]');
  1030. if (el && navigator.share) { // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
  1031. const shareData = {
  1032. url: el.dataset.url,
  1033. title: decodeURI(el.dataset.title),
  1034. };
  1035. navigator.share(shareData);
  1036. return false;
  1037. }
  1038. el = ev.target.closest('.item.share > a[data-type="email-webmail-firefox-fix"]');
  1039. if (el) {
  1040. window.open(el.href);
  1041. return false;
  1042. }
  1043. el = ev.target.closest('.item.share > a[href="POST"]');
  1044. if (el) { // Share by POST
  1045. const f = el.parentElement.querySelector('form');
  1046. f.disabled = false;
  1047. f.submit();
  1048. return false;
  1049. }
  1050. el = ev.target.closest('.flux_header, .flux_content');
  1051. if (el) { // flux_toggle
  1052. if (ev.target.closest('.reader, .content, .item.website, .item.link, .dropdown')) {
  1053. return true;
  1054. }
  1055. if (!context.sides_close_article && ev.target.matches('.flux_content')) {
  1056. // setting for not-closing after clicking outside article area
  1057. return false;
  1058. }
  1059. const old_active = document.querySelector('.flux.current');
  1060. const new_active = el.parentNode;
  1061. if (ev.target.tagName.toUpperCase() === 'A') { // Leave real links alone (but does not catch img in a link)
  1062. if (context.auto_mark_article) {
  1063. mark_read(new_active, true, false);
  1064. }
  1065. return true;
  1066. }
  1067. toggleContent(new_active, old_active, false);
  1068. return false;
  1069. }
  1070. };
  1071. stream.onmouseup = function (ev) { // Mouseup enables us to catch middle click, and control+click in IE/Edge
  1072. if (ev.altKey || ev.metaKey || ev.shiftKey) {
  1073. return;
  1074. }
  1075. let el = ev.target.closest('.item.title > a');
  1076. if (el) {
  1077. if (ev.which == 1) {
  1078. if (ev.ctrlKey) { // Control+click
  1079. if (context.auto_mark_site) {
  1080. mark_read(el.closest('.flux'), true, false);
  1081. }
  1082. } else {
  1083. el.parentElement.click(); // Normal click, just toggle article.
  1084. }
  1085. } else if (ev.which == 2 && !ev.ctrlKey) { // Simple middle click: same behaviour as CTRL+click
  1086. if (context.auto_mark_article) {
  1087. const new_active = el.closest('.flux');
  1088. mark_read(new_active, true, false);
  1089. }
  1090. }
  1091. return;
  1092. }
  1093. if (context.auto_mark_site) {
  1094. // catch mouseup instead of click so we can have the correct behaviour
  1095. // with middle button click (scroll button).
  1096. el = ev.target.closest('.flux .link > a');
  1097. if (el) {
  1098. if (ev.which == 3) {
  1099. return;
  1100. }
  1101. mark_read(el.closest('.flux'), true, false);
  1102. }
  1103. }
  1104. };
  1105. stream.onchange = function (ev) {
  1106. const checkboxTag = ev.target.closest('.checkboxTag');
  1107. if (checkboxTag) { // Dynamic tags
  1108. ev.stopPropagation();
  1109. const tagId = checkboxTag.name.replace(/^t_/, '');
  1110. const tagName = checkboxTag.nextElementSibling ? checkboxTag.nextElementSibling.childNodes[0].value : '';
  1111. if ((tagId == 0 && tagName.length > 0) || tagId != 0) {
  1112. const isChecked = checkboxTag.checked;
  1113. const entry = checkboxTag.closest('div.flux');
  1114. const entryId = entry.id.replace(/^flux_/, '');
  1115. checkboxTag.disabled = true;
  1116. const req = new XMLHttpRequest();
  1117. req.open('POST', './?c=tag&a=tagEntry&ajax=1', true);
  1118. req.responseType = 'json';
  1119. req.onerror = function (e) {
  1120. checkboxTag.checked = !isChecked;
  1121. badAjax(this.status == 403);
  1122. };
  1123. req.onload = function (e) {
  1124. if (this.status != 200) {
  1125. return req.onerror(e);
  1126. }
  1127. if (entry.classList.contains('not_read')) {
  1128. incUnreadsTag('t_' + tagId, isChecked ? 1 : -1);
  1129. }
  1130. };
  1131. req.onloadend = function (e) {
  1132. checkboxTag.disabled = false;
  1133. if (tagId == 0) {
  1134. loadDynamicTags(checkboxTag.closest('div.dropdown'));
  1135. }
  1136. };
  1137. req.setRequestHeader('Content-Type', 'application/json');
  1138. req.send(JSON.stringify({
  1139. _csrf: context.csrf,
  1140. id_tag: tagId,
  1141. name_tag: tagId == 0 ? tagName : '',
  1142. id_entry: entryId,
  1143. checked: isChecked,
  1144. ajax: 1,
  1145. }));
  1146. }
  1147. }
  1148. };
  1149. }
  1150. function toggleClass(el, cssclass) {
  1151. el.classList.remove(cssclass);
  1152. el.dataset.foo = el.offsetWidth; // it does nothing, but it is needed. See https://github.com/FreshRSS/FreshRSS/pull/5295
  1153. el.classList.add(cssclass);
  1154. }
  1155. function init_nav_entries() {
  1156. const nav_entries = document.getElementById('nav_entries');
  1157. if (nav_entries) {
  1158. nav_entries.querySelector('.previous_entry').onclick = function (e) {
  1159. prev_entry(false);
  1160. return false;
  1161. };
  1162. nav_entries.querySelector('.next_entry').onclick = function (e) {
  1163. next_entry(false);
  1164. return false;
  1165. };
  1166. nav_entries.querySelector('.up').onclick = function (e) {
  1167. const active_item = (document.querySelector('.flux.current') || document.querySelector('.flux'));
  1168. const windowTop = document.scrollingElement.scrollTop;
  1169. const item_top = active_item.offsetParent.offsetTop + active_item.offsetTop;
  1170. const nav_menu = document.querySelector('.nav_menu');
  1171. let nav_menu_height = 0;
  1172. if (getComputedStyle(nav_menu).position === 'fixed' || getComputedStyle(nav_menu).position === 'sticky') {
  1173. nav_menu_height = nav_menu.offsetHeight;
  1174. }
  1175. document.scrollingElement.scrollTop = windowTop > item_top ? item_top - nav_menu_height : 0 - nav_menu_height;
  1176. return false;
  1177. };
  1178. }
  1179. }
  1180. function loadDynamicTags(div) {
  1181. div.classList.remove('dynamictags');
  1182. div.querySelectorAll('li.item').forEach(function (li) { li.remove(); });
  1183. const entryId = div.closest('div.flux').id.replace(/^flux_/, '');
  1184. const req = new XMLHttpRequest();
  1185. req.open('GET', './?c=tag&a=getTagsForEntry&id_entry=' + entryId, true);
  1186. req.responseType = 'json';
  1187. req.onerror = function (e) {
  1188. div.querySelectorAll('li.item').forEach(function (li) { li.remove(); });
  1189. div.classList.add('dynamictags');
  1190. };
  1191. req.onload = function (e) {
  1192. if (this.status != 200) {
  1193. return req.onerror(e);
  1194. }
  1195. const json = xmlHttpRequestJson(this);
  1196. if (!json) {
  1197. return req.onerror(e);
  1198. }
  1199. const li_item0 = document.createElement('li');
  1200. li_item0.setAttribute('class', 'item addItem');
  1201. const label = document.createElement('label');
  1202. label.setAttribute('class', 'noHover');
  1203. const input_checkboxTag = document.createElement('input');
  1204. input_checkboxTag.setAttribute('class', 'checkboxTag checkboxNewTag');
  1205. input_checkboxTag.setAttribute('name', 't_0');
  1206. input_checkboxTag.setAttribute('type', 'checkbox');
  1207. const input_newTag = document.createElement('input');
  1208. input_newTag.setAttribute('type', 'text');
  1209. input_newTag.setAttribute('name', 'newTag');
  1210. input_newTag.addEventListener('keydown', function (ev) { if (ev.key.toUpperCase() == 'ENTER') { this.parentNode.previousSibling.click(); } });
  1211. const button_btn = document.createElement('button');
  1212. button_btn.setAttribute('type', 'button');
  1213. button_btn.setAttribute('class', 'btn');
  1214. button_btn.addEventListener('click', function () { this.parentNode.parentNode.click(); });
  1215. const text_plus = document.createTextNode('+');
  1216. const div_stick = document.createElement('div');
  1217. div_stick.setAttribute('class', 'stick');
  1218. button_btn.appendChild(text_plus);
  1219. div_stick.appendChild(input_newTag);
  1220. div_stick.appendChild(button_btn);
  1221. label.appendChild(input_checkboxTag);
  1222. label.appendChild(div_stick);
  1223. li_item0.appendChild(label);
  1224. div.querySelector('.dropdown-menu').appendChild(li_item0);
  1225. let html = '';
  1226. if (json && json.length) {
  1227. for (let i = 0; i < json.length; i++) {
  1228. const tag = json[i];
  1229. html += '<li class="item"><label><input class="checkboxTag" name="t_' + tag.id + '" type="checkbox"' +
  1230. (tag.checked ? ' checked="checked"' : '') + '> ' + tag.name + '</label></li>';
  1231. }
  1232. }
  1233. div.querySelector('.dropdown-menu').insertAdjacentHTML('beforeend', html);
  1234. };
  1235. req.send();
  1236. }
  1237. // <actualize>
  1238. let feeds_processed = 0;
  1239. let categories_processed = 0;
  1240. let to_process = 0;
  1241. function refreshFeed(feeds, feeds_count) {
  1242. const feed = feeds.pop();
  1243. if (!feed) {
  1244. return;
  1245. }
  1246. const req = new XMLHttpRequest();
  1247. req.open('POST', feed.url, true);
  1248. req.onloadend = function (e) {
  1249. feeds_processed++;
  1250. if (this.status != 200) {
  1251. badAjax(false);
  1252. } else {
  1253. const div = document.getElementById('actualizeProgress');
  1254. div.querySelector('.progress').innerHTML = (categories_processed + feeds_processed) + ' / ' + to_process;
  1255. div.querySelector('.title').innerHTML = feed.title;
  1256. }
  1257. if (feeds_processed === feeds_count) {
  1258. // Empty request to commit new articles
  1259. const req2 = new XMLHttpRequest();
  1260. req2.open('POST', './?c=feed&a=actualize&id=-1&ajax=1', true);
  1261. req2.onloadend = function (e) {
  1262. delayedFunction(function () { location.reload(); });
  1263. };
  1264. req2.setRequestHeader('Content-Type', 'application/json');
  1265. req2.send(JSON.stringify({
  1266. _csrf: context.csrf,
  1267. noCommit: 0,
  1268. }));
  1269. } else {
  1270. refreshFeed(feeds, feeds_count);
  1271. }
  1272. };
  1273. req.setRequestHeader('Content-Type', 'application/json');
  1274. req.send(JSON.stringify({
  1275. _csrf: context.csrf,
  1276. noCommit: 1,
  1277. }));
  1278. }
  1279. function refreshFeeds(json) {
  1280. feeds_processed = 0;
  1281. if (!json.feeds || json.feeds.length === 0) {
  1282. // Empty request to commit new articles
  1283. const req2 = new XMLHttpRequest();
  1284. req2.open('POST', './?c=feed&a=actualize&id=-1&ajax=1', true);
  1285. req2.onloadend = function (e) {
  1286. context.ajax_loading = false;
  1287. };
  1288. req2.setRequestHeader('Content-Type', 'application/json');
  1289. req2.send(JSON.stringify({
  1290. _csrf: context.csrf,
  1291. noCommit: 0,
  1292. }));
  1293. } else {
  1294. const feeds_count = json.feeds.length;
  1295. for (let i = 10; i > 0; i--) {
  1296. refreshFeed(json.feeds, feeds_count);
  1297. }
  1298. }
  1299. }
  1300. function refreshDynamicOpml(categories, categories_count, next) {
  1301. const category = categories.pop();
  1302. if (!category) {
  1303. return;
  1304. }
  1305. const req = new XMLHttpRequest();
  1306. req.open('POST', category.url, true);
  1307. req.onloadend = function (e) {
  1308. categories_processed++;
  1309. if (this.status != 200) {
  1310. badAjax(false);
  1311. } else {
  1312. const div = document.getElementById('actualizeProgress');
  1313. div.querySelector('.progress').innerHTML = (categories_processed + feeds_processed) + ' / ' + to_process;
  1314. div.querySelector('.title').innerHTML = category.title;
  1315. }
  1316. if (categories_processed === categories_count) {
  1317. if (next) { next(); }
  1318. } else {
  1319. refreshDynamicOpml(categories, categories_count, next);
  1320. }
  1321. };
  1322. req.setRequestHeader('Content-Type', 'application/json');
  1323. req.send(JSON.stringify({
  1324. _csrf: context.csrf,
  1325. noCommit: 1,
  1326. }));
  1327. }
  1328. function refreshDynamicOpmls(json, next) {
  1329. categories_processed = 0;
  1330. if (json.categories && json.categories.length > 0) {
  1331. const categories_count = json.categories.length;
  1332. for (let i = 10; i > 0; i--) {
  1333. refreshDynamicOpml(json.categories, categories_count, next);
  1334. }
  1335. } else {
  1336. if (next) { next(); }
  1337. }
  1338. }
  1339. function init_actualize() {
  1340. let auto = false;
  1341. let nbCategoriesFirstRound = 0;
  1342. let skipCategories = false;
  1343. const actualize = document.getElementById('actualize');
  1344. if (!actualize) {
  1345. return;
  1346. }
  1347. actualize.onclick = function () {
  1348. if (context.ajax_loading) {
  1349. return false;
  1350. }
  1351. context.ajax_loading = true;
  1352. const req = new XMLHttpRequest();
  1353. req.open('POST', './?c=javascript&a=actualize', true);
  1354. req.responseType = 'json';
  1355. req.onload = function (e) {
  1356. if (this.status != 200) {
  1357. return badAjax(false);
  1358. }
  1359. const json = xmlHttpRequestJson(this);
  1360. if (!json) {
  1361. return badAjax(false);
  1362. }
  1363. if (auto && json.categories.length < 1 && json.feeds.length < 1) {
  1364. auto = false;
  1365. context.ajax_loading = false;
  1366. return false;
  1367. }
  1368. to_process = json.categories.length + json.feeds.length + nbCategoriesFirstRound;
  1369. if (json.categories.length + json.feeds.length > 0 && !document.getElementById('actualizeProgress')) {
  1370. document.body.insertAdjacentHTML('beforeend', '<div id="actualizeProgress" class="notification good">' +
  1371. json.feedback_actualize + '<br /><span class="title">/</span><br /><span class="progress">0 / ' +
  1372. to_process + '</span></div>');
  1373. } else {
  1374. openNotification(json.feedback_no_refresh, 'good');
  1375. }
  1376. if (json.categories.length > 0 && !skipCategories) {
  1377. skipCategories = true; // To avoid risk of infinite loop
  1378. nbCategoriesFirstRound = json.categories.length;
  1379. // If some dynamic OPML categories are refreshed, need to reload the list of feeds before updating them
  1380. refreshDynamicOpmls(json, () => {
  1381. context.ajax_loading = false;
  1382. actualize.click();
  1383. });
  1384. } else {
  1385. refreshFeeds(json);
  1386. }
  1387. };
  1388. req.setRequestHeader('Content-Type', 'application/json');
  1389. req.send(JSON.stringify({
  1390. _csrf: context.csrf,
  1391. }));
  1392. return false;
  1393. };
  1394. if (context.auto_actualize_feeds) {
  1395. auto = true;
  1396. actualize.click();
  1397. }
  1398. }
  1399. // </actualize>
  1400. // <notification>
  1401. let notification = null;
  1402. let notification_interval = null;
  1403. let notification_working = false;
  1404. function openNotification(msg, status) {
  1405. if (notification_working === true) {
  1406. return false;
  1407. }
  1408. notification_working = true;
  1409. notification.querySelector('.msg').innerHTML = msg;
  1410. notification.className = 'notification';
  1411. notification.classList.add(status);
  1412. if (status == 'good') {
  1413. notification_interval = setTimeout(closeNotification, 4000);
  1414. } else {
  1415. // no status or f.e. status = 'bad', give some more time to read
  1416. notification_interval = setTimeout(closeNotification, 8000);
  1417. }
  1418. }
  1419. function closeNotification() {
  1420. notification.classList.add('closed');
  1421. clearInterval(notification_interval);
  1422. notification_working = false;
  1423. }
  1424. function init_notifications() {
  1425. notification = document.getElementById('notification');
  1426. notification.querySelector('a.close').addEventListener('click', function (ev) {
  1427. closeNotification();
  1428. ev.preventDefault();
  1429. return false;
  1430. });
  1431. notification.addEventListener('mouseenter', function () {
  1432. clearInterval(notification_interval);
  1433. });
  1434. notification.addEventListener('mouseleave', function () {
  1435. notification_interval = setTimeout(closeNotification, 3000);
  1436. });
  1437. if (notification.querySelector('.msg').innerHTML.length > 0) {
  1438. notification_working = true;
  1439. if (notification.classList.contains('good')) {
  1440. notification_interval = setTimeout(closeNotification, 4000);
  1441. } else {
  1442. // no status or f.e. status = 'bad', give some more time to read
  1443. notification_interval = setTimeout(closeNotification, 8000);
  1444. }
  1445. }
  1446. }
  1447. // </notification>
  1448. // <notifs html5>
  1449. let notifs_html5_permission = 'denied';
  1450. function notifs_html5_is_supported() {
  1451. return window.Notification !== undefined;
  1452. }
  1453. function notifs_html5_ask_permission() {
  1454. window.Notification.requestPermission(function () {
  1455. notifs_html5_permission = window.Notification.permission;
  1456. });
  1457. }
  1458. function notifs_html5_show(nb, nb_new) {
  1459. if (notifs_html5_permission !== 'granted') {
  1460. return;
  1461. }
  1462. const notification = new window.Notification(context.i18n.notif_title_articles, {
  1463. icon: '../themes/icons/favicon-256-padding.png',
  1464. body: context.i18n.notif_body_new_articles.replace('%%d', nb_new) + ' ' + context.i18n.notif_body_unread_articles.replace('%%d', nb),
  1465. tag: 'freshRssNewArticles',
  1466. });
  1467. notification.onclick = function () {
  1468. delayedFunction(function () {
  1469. location.reload();
  1470. window.focus();
  1471. notification.close();
  1472. });
  1473. };
  1474. if (context.html5_notif_timeout !== 0) {
  1475. setTimeout(function () {
  1476. notification.close();
  1477. }, context.html5_notif_timeout * 1000);
  1478. }
  1479. }
  1480. function init_notifs_html5() {
  1481. if (!notifs_html5_is_supported()) {
  1482. return;
  1483. }
  1484. notifs_html5_permission = notifs_html5_ask_permission();
  1485. }
  1486. // </notifs html5>
  1487. function refreshUnreads() {
  1488. const req = new XMLHttpRequest();
  1489. req.open('GET', './?c=javascript&a=nbUnreadsPerFeed', true);
  1490. req.responseType = 'json';
  1491. req.onload = function (e) {
  1492. const json = xmlHttpRequestJson(this);
  1493. if (!json) {
  1494. return badAjax(false);
  1495. }
  1496. const isAll = document.querySelector('.category.all.active');
  1497. let new_articles = false;
  1498. let nbUnreadFeeds = 0;
  1499. const title = document.querySelector('.category.all .title');
  1500. const nb_unreads_before = title ? str2int(title.getAttribute('data-unread')) : 0;
  1501. Object.keys(json.feeds).forEach(function (feed_id) {
  1502. const nbUnreads = json.feeds[feed_id];
  1503. nbUnreadFeeds += nbUnreads;
  1504. feed_id = 'f_' + feed_id;
  1505. const elem = document.getElementById(feed_id);
  1506. const feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  1507. if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && // Update of current view?
  1508. (nbUnreads - feed_unreads > 0)) {
  1509. const newArticle = document.getElementById('new-article');
  1510. newArticle.setAttribute('aria-hidden', 'false');
  1511. newArticle.style.display = 'block';
  1512. new_articles = true;
  1513. }
  1514. });
  1515. const noArticlesToShow_div = document.getElementById('noArticlesToShow');
  1516. if (nbUnreadFeeds > 0 && noArticlesToShow_div) {
  1517. noArticlesToShow_div.classList.add('hide');
  1518. }
  1519. let nbUnreadTags = 0;
  1520. Object.keys(json.tags).forEach(function (tag_id) {
  1521. const nbUnreads = json.tags[tag_id];
  1522. nbUnreadTags += nbUnreads;
  1523. const tag = document.getElementById('t_' + tag_id);
  1524. if (tag) {
  1525. tag.setAttribute('data-unread', nbUnreads);
  1526. tag.querySelector('.item-title').setAttribute('data-unread', numberFormat(nbUnreads));
  1527. }
  1528. });
  1529. const tags = document.querySelector('.category.tags');
  1530. if (tags) {
  1531. tags.setAttribute('data-unread', nbUnreadTags);
  1532. tags.querySelector('.title').setAttribute('data-unread', numberFormat(nbUnreadTags));
  1533. }
  1534. const nb_unreads = title ? str2int(title.getAttribute('data-unread')) : 0;
  1535. if (nb_unreads > 0 && new_articles) {
  1536. faviconNbUnread(nb_unreads);
  1537. const nb_new = nb_unreads - nb_unreads_before;
  1538. notifs_html5_show(nb_unreads, nb_new);
  1539. }
  1540. };
  1541. req.send();
  1542. }
  1543. function toggle_bigMarkAsRead_button() {
  1544. const bigMarkAsRead_button = document.getElementById('bigMarkAsRead');
  1545. if (bigMarkAsRead_button) {
  1546. if (document.querySelector('.flux.not_read') != null) {
  1547. bigMarkAsRead_button.style = '';
  1548. bigMarkAsRead_button.querySelector('.markAllRead').style.visibility = '';
  1549. } else {
  1550. if (bigMarkAsRead_button.querySelector('.jumpNext')) {
  1551. bigMarkAsRead_button.querySelector('.markAllRead').style.visibility = 'hidden';
  1552. } else {
  1553. bigMarkAsRead_button.querySelector('.markAllRead').style.visibility = '';
  1554. bigMarkAsRead_button.style.visibility = 'hidden';
  1555. }
  1556. }
  1557. }
  1558. }
  1559. // <endless_mode>
  1560. let url_load_more = '';
  1561. let load_more = false;
  1562. let box_load_more = null;
  1563. function load_more_posts() {
  1564. if (load_more || !url_load_more || !box_load_more) {
  1565. return;
  1566. }
  1567. load_more = true;
  1568. document.getElementById('load_more').classList.add('loading');
  1569. const req = new XMLHttpRequest();
  1570. req.open('GET', url_load_more, true);
  1571. req.responseType = 'document';
  1572. req.onload = function (e) {
  1573. const html = this.response;
  1574. const streamFooter = document.getElementById('stream-footer');
  1575. const streamAdopted = document.adoptNode(html.getElementById('stream'));
  1576. streamAdopted.querySelectorAll('.flux, .day').forEach(function (div) {
  1577. box_load_more.insertBefore(div, streamFooter);
  1578. });
  1579. const streamFooterOld = streamFooter.querySelector('.stream-footer-inner');
  1580. const streamFooterNew = streamAdopted.querySelector('.stream-footer-inner');
  1581. streamFooter.replaceChild(streamFooterNew, streamFooterOld);
  1582. const bigMarkAsRead = document.getElementById('bigMarkAsRead');
  1583. const readAll = document.querySelector('#nav_menu_read_all .read_all');
  1584. if (readAll && bigMarkAsRead && bigMarkAsRead.formAction) {
  1585. if (context.display_order === 'ASC') {
  1586. readAll.formAction = bigMarkAsRead.formAction;
  1587. } else {
  1588. bigMarkAsRead.formAction = readAll.formAction;
  1589. }
  1590. toggle_bigMarkAsRead_button();
  1591. }
  1592. document.querySelectorAll('[id^=day_]').forEach(function (div) {
  1593. const ids = document.querySelectorAll('[id="' + div.id + '"]');
  1594. for (let i = ids.length - 1; i > 0; i--) { // Keep only the first
  1595. ids[i].remove();
  1596. }
  1597. });
  1598. init_load_more(box_load_more);
  1599. const div_load_more = document.getElementById('load_more');
  1600. if (bigMarkAsRead) {
  1601. bigMarkAsRead.removeAttribute('disabled');
  1602. }
  1603. if (div_load_more) {
  1604. div_load_more.classList.remove('loading');
  1605. }
  1606. load_more = false;
  1607. };
  1608. req.send();
  1609. }
  1610. const freshrssLoadMoreEvent = document.createEvent('Event');
  1611. freshrssLoadMoreEvent.initEvent('freshrss:load-more', true, true);
  1612. function init_load_more(box) {
  1613. box_load_more = box;
  1614. document.body.dispatchEvent(freshrssLoadMoreEvent);
  1615. const next_button = document.getElementById('load_more');
  1616. if (!next_button) {
  1617. // no more article to load
  1618. url_load_more = '';
  1619. return;
  1620. }
  1621. url_load_more = next_button.getAttribute('formaction');
  1622. next_button.onclick = function (e) {
  1623. load_more_posts();
  1624. return false;
  1625. };
  1626. }
  1627. // </endless_mode>
  1628. function init_confirm_action() {
  1629. document.body.onclick = function (ev) {
  1630. const b = ev.target.closest('.confirm');
  1631. if (b) {
  1632. let str_confirmation = this.getAttribute('data-str-confirm');
  1633. if (!str_confirmation) {
  1634. str_confirmation = context.i18n.confirmation_default;
  1635. }
  1636. return confirm(str_confirmation);
  1637. }
  1638. };
  1639. document.querySelectorAll('button.confirm').forEach(function (b) { b.disabled = false; });
  1640. }
  1641. function faviconNbUnread(n) {
  1642. if (typeof n === 'undefined') {
  1643. const t = document.querySelector('.category.all .title');
  1644. n = t ? str2int(t.getAttribute('data-unread')) : 0;
  1645. }
  1646. // http://remysharp.com/2010/08/24/dynamic-favicons/
  1647. const canvas = document.createElement('canvas');
  1648. const link = document.getElementById('favicon').cloneNode(true);
  1649. const ratio = window.devicePixelRatio;
  1650. if (canvas.getContext && link) {
  1651. canvas.height = canvas.width = 16 * ratio;
  1652. const img = document.createElement('img');
  1653. img.onload = function () {
  1654. const ctx = canvas.getContext('2d');
  1655. ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
  1656. if (n > 0) {
  1657. let text = '';
  1658. if (n < 1000) {
  1659. text = n;
  1660. } else if (n < 100000) {
  1661. text = Math.floor(n / 1000) + 'k';
  1662. } else {
  1663. text = 'E' + Math.floor(Math.log10(n));
  1664. }
  1665. ctx.font = 'bold ' + 9 * ratio + 'px "Arial", sans-serif';
  1666. ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
  1667. ctx.fillRect(0, 7 * ratio, ctx.measureText(text).width, 9 * ratio);
  1668. ctx.fillStyle = '#F00';
  1669. ctx.fillText(text, 0, canvas.height - 1);
  1670. }
  1671. link.href = canvas.toDataURL('image/png');
  1672. // Check if data URI has generated a real favicon and if not, fallback to standard icon
  1673. if (link.href.length > 180) {
  1674. document.querySelector('link[rel~=icon]').remove();
  1675. document.head.appendChild(link);
  1676. }
  1677. };
  1678. img.src = '../favicon.ico';
  1679. }
  1680. }
  1681. function removeFirstLoadSpinner() {
  1682. const first_load = document.getElementById('first_load');
  1683. if (first_load) {
  1684. first_load.remove();
  1685. }
  1686. }
  1687. function init_normal() {
  1688. const stream = document.getElementById('stream');
  1689. if (!stream) {
  1690. if (window.console) {
  1691. console.log('FreshRSS waiting for content…');
  1692. }
  1693. setTimeout(init_normal, 100);
  1694. return;
  1695. }
  1696. init_column_categories();
  1697. init_stream(stream);
  1698. init_actualize();
  1699. faviconNbUnread();
  1700. window.onbeforeunload = function (e) {
  1701. const sidebar = document.getElementById('sidebar');
  1702. if (sidebar) { // Save sidebar scroll position
  1703. sessionStorage.setItem('FreshRSS_sidebar_scrollTop', sidebar.scrollTop);
  1704. }
  1705. if (mark_read_queue && mark_read_queue.length > 0) {
  1706. return false;
  1707. }
  1708. };
  1709. }
  1710. function init_main_beforeDOM() {
  1711. document.scrollingElement.scrollTop = 0;
  1712. init_shortcuts();
  1713. if (['normal', 'reader', 'global'].indexOf(context.current_view) >= 0) {
  1714. init_normal();
  1715. }
  1716. }
  1717. function init_main_afterDOM() {
  1718. removeFirstLoadSpinner();
  1719. init_notifications();
  1720. init_confirm_action();
  1721. const stream = document.getElementById('stream');
  1722. if (stream) {
  1723. init_load_more(stream);
  1724. init_posts();
  1725. init_nav_entries();
  1726. init_notifs_html5();
  1727. toggle_bigMarkAsRead_button();
  1728. setTimeout(faviconNbUnread, 1000);
  1729. setInterval(refreshUnreads, 120000);
  1730. }
  1731. if (window.console) {
  1732. console.log('FreshRSS main init done.');
  1733. }
  1734. }
  1735. init_main_beforeDOM(); // Can be called before DOM is fully loaded
  1736. if (document.readyState && document.readyState !== 'loading') {
  1737. init_main_afterDOM();
  1738. } else {
  1739. if (window.console) {
  1740. console.log('FreshRSS waiting for DOMContentLoaded…');
  1741. }
  1742. document.addEventListener('DOMContentLoaded', init_main_afterDOM, false);
  1743. }
  1744. // @license-end