InoReader Filter

Highlight or remove articles in InoReader. / InoReaderの記事を消去もしくは強調表示します。

当前为 2017-07-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name InoReader Filter
  3. // @description Highlight or remove articles in InoReader. / InoReaderの記事を消去もしくは強調表示します。
  4. // @description:en Highlight or remove articles in InoReader.
  5. // @description:ja InoReaderの記事を消去もしくは強調表示します。
  6. // @id InoReaderFilter
  7. // @namespace https://userscripts.org/scripts/show/352673
  8. // @homepage https://greasyfork.org/scripts/895-inoreader-filter
  9. // @include http://inoreader.com/*
  10. // @include https://inoreader.com/*
  11. // @include http://www.inoreader.com/*
  12. // @include https://www.inoreader.com/*
  13. // @include http://jp.inoreader.com/*
  14. // @include https://jp.inoreader.com/*
  15. // @include http://us.inoreader.com/*
  16. // @include https://us.inoreader.com/*
  17. // @exclude *inoreader.com/stream*
  18. // @exclude *inoreader.com/m/*
  19. // @grant GM_addStyle
  20. // @version 1.22
  21. // ==/UserScript==
  22.  
  23. (function() {
  24. 'use strict';
  25.  
  26. if (!/Ino\s?Reader/i.test(document.title)) return;
  27. var aNgTextarea = [],
  28. aNg = [],
  29. aNgId = [],
  30. aHiTextarea = [],
  31. aHi = [],
  32. aHiId = [],
  33. aAd = [],
  34. aAdId = [],
  35. aAdTemp,
  36. bExclude = false,
  37. nArticles = 0,
  38. nExcludes = 0,
  39. nUnread = 0,
  40. nUnreadEx = 0,
  41. st = {},
  42. reAd = '^\\s*(?:ad|pr|広告)\\s*[::]|^\\s*[\\[[【](?:ad|pr|広告)[\\]]】]|[\\[[【](?:ad|pr|広告)[\\]]】]\\s*$|[::]\\s*(?:ad|pr|広告)\\s*$',
  43. $id = function(id) {
  44. return document.getElementById(id);
  45. },
  46. notType = function(t, a) {
  47. return (Object.prototype.toString.call(a).slice(8, 11) !== t) ? true : false;
  48. },
  49. target = $id('subscriptions_articles') || $id('reader_pane'),
  50. config = {
  51. childList: true
  52. },
  53. iInit, LOC;
  54.  
  55. var convertRules = function() {
  56. aNg = [];
  57. aHi = [];
  58. aNgTextarea = (st.ngdata) ? st.ngdata.split(/\r\n|\n|\r/) : [];
  59. aHiTextarea = (st.hidata) ? st.hidata.split(/\r\n|\n|\r/) : [];
  60. var wildcardToRegexp = function(s) {
  61. return s.replace(/~\*/g, '<InoReaderFilterAM>')
  62. .replace(/~\?/g, '<InoReaderFilterQM>')
  63. .replace(/[.+\^=!:${}()|\[\]\/\\]/g, '\\$&')
  64. .replace(/\*/g, '.*')
  65. .replace(/\?/g, '.')
  66. .replace(/<InoReaderFilterAM>/g, '\\*')
  67. .replace(/<InoReaderFilterQM>/g, '\\?');
  68. },
  69. a = [aNg, aNgTextarea, aHi, aHiTextarea];
  70. for (var n = 0, m = a.length; n < m; n = n + 2) {
  71. for (var i = 0, j = a[n + 1].length; i < j; i++) {
  72. var str = a[n + 1][i],
  73. sFeed = '',
  74. sTitle = '',
  75. sText = '';
  76. a[n][i] = {};
  77. a[n][i].feedPattern = '';
  78. a[n][i].feedFlag = '';
  79. a[n][i].titlePattern = '';
  80. a[n][i].titleFlag = '';
  81. a[n][i].textPattern = '';
  82. a[n][i].textFlag = '';
  83. a[n][i].task = '';
  84. if (str.indexOf(st.delimiter) !== -1) {
  85. var arr = str.split(st.delimiter);
  86. sFeed = arr[0];
  87. if (arr.length === 2) sText = arr[1];
  88. else if (arr.length > 2) {
  89. sTitle = arr[1];
  90. sText = str.slice(arr[0].length + arr[1].length + (st.delimiter.length * 2));
  91. if (!arr[1]) a[n][i].task = 'text';
  92. }
  93. } else sText = str;
  94. if (sFeed) {
  95. if (/^\/.+\/g?i?y?$/.test(sFeed)) {
  96. a[n][i].feedPattern = sFeed.slice(sFeed.indexOf('/') + 1, sFeed.lastIndexOf('/'));
  97. a[n][i].feedFlag = sFeed.slice(sFeed.lastIndexOf('/') + 1);
  98. } else a[n][i].feedPattern = wildcardToRegexp(sFeed);
  99. }
  100. if (sTitle) {
  101. if (/^\/.+\/g?i?y?$/.test(sTitle)) {
  102. a[n][i].titlePattern = sTitle.slice(sTitle.indexOf('/') + 1, sTitle.lastIndexOf('/'));
  103. a[n][i].titleFlag = sTitle.slice(sTitle.lastIndexOf('/') + 1);
  104. } else a[n][i].titlePattern = wildcardToRegexp(sTitle);
  105. }
  106. if (sText) {
  107. if (/^\/.+\/g?i?y?$/.test(sText)) {
  108. a[n][i].textPattern = sText.slice(sText.indexOf('/') + 1, sText.lastIndexOf('/'));
  109. a[n][i].textFlag = sText.slice(sText.lastIndexOf('/') + 1);
  110. } else a[n][i].textPattern = wildcardToRegexp(sText);
  111. }
  112. }
  113. }
  114. };
  115.  
  116. var checkArticle = function(a, ft, at, du, tdu) {
  117. var feed = a.feedPattern,
  118. title = a.titlePattern,
  119. text = a.textPattern,
  120. task = a.task;
  121. if ((!title && !text) || /^\s+$/.test(title + text)) return false;
  122. var bFeed = new RegExp(feed, a.feedFlag + 'm').test(ft),
  123. bTitle = new RegExp(title, a.titleFlag).test(at),
  124. bDU = new RegExp(text, a.textFlag + 'm').test(du),
  125. bTDU = new RegExp(text, a.textFlag + 'm').test(tdu);
  126. if (!feed) {
  127. if (!title && bDU && task === 'text') return 'DU: ' + text;
  128. if (!title && bTDU && !task) return 'TDU: ' + text;
  129. if (bTitle && !text) return 'T: ' + title;
  130. if (bTitle && bDU) return 'T: ' + title + ' DU: ' + text;
  131. }
  132. if (bFeed) {
  133. if (!title && bDU && task === 'text') return 'F: ' + feed + ' DU: ' + text;
  134. if (!title && bTDU && !task) return 'F: ' + feed + ' TDU: ' + text;
  135. if (bTitle && !text) return 'F: ' + feed + ' T: ' + title;
  136. if (bTitle && bDU) return 'F: ' + feed + ' T: ' + title + ' DU: ' + text;
  137. }
  138. return '';
  139. };
  140.  
  141. var currentArticle = function() {
  142. if (target) return target.getElementsByClassName('article_current');
  143. return [];
  144. };
  145.  
  146. var currentExpandedArticle = function() {
  147. if (target) return target.getElementsByClassName('article_current article_expanded');
  148. return [];
  149. };
  150.  
  151. var currentTreeName = function() {
  152. var tlf = document.getElementById('tree').getElementsByClassName('selected');
  153. if (tlf.length && tlf[0] && tlf[0].textContent) return tlf[0].textContent;
  154. return '';
  155. };
  156.  
  157. var articleData = function(e) {
  158. var o = {};
  159. o.sId = '';
  160. o.sFeed = '';
  161. o.sTitle = '';
  162. o.sDesc = '';
  163. o.sUrl = '';
  164. o.sDate = '';
  165. o.bUnread = false;
  166. o.sId = (e && e.id) ? e.id.slice(e.id.lastIndexOf('_') + 1) : '';
  167. if (!o.sId) return o;
  168. var eArticleFeed = $id('article_feed_info_link_' + o.sId) || e.getElementsByClassName('article_feed_title')[0] || document.evaluate('//div[@class="article_tile_footer_feed_title"]/a', e.cloneNode(true), null, 9, null).singleNodeValue,
  169. eArticleTitle = $id('at_' + o.sId) || $id('article_title_link_' + o.sId) || e.getElementsByClassName('article_title_link')[0],
  170. eArticleDesc = e.getElementsByClassName('article_short_contents')[0] || e.getElementsByClassName('article_tile_content')[0],
  171. eArticleUrl = $id('aurl_' + o.sId),
  172. eArticleDate = $id('header_date_' + o.sId);
  173. o.sFeed = (eArticleFeed) ? eArticleFeed.textContent : currentTreeName();
  174. o.sTitle = (eArticleTitle) ? eArticleTitle.textContent : '';
  175. o.sDesc = (eArticleDesc) ? eArticleDesc.textContent : '';
  176. o.sUrl = (eArticleUrl && eArticleUrl.hasAttribute('href')) ? eArticleUrl.getAttribute('href') : '';
  177. o.sDate = (eArticleDate && eArticleDate.hasAttribute('title')) ? eArticleDate.getAttribute('title') : '';
  178. if (/^\s+$/.test(o.sFeed)) o.sFeed = '';
  179. if (/^\s+$/.test(o.sTitle)) o.sTitle = '';
  180. if (/^\s+$/.test(o.sDesc)) o.sDesc = '';
  181. if (/^\s+$/.test(o.sUrl)) o.sUrl = '';
  182. if (/^\s+$/.test(o.sDate)) o.sDate = '';
  183. if (o.sDesc) o.sDesc = o.sDesc.replace(/^\s+-\s+(.+)/, '$1').replace(/(.+)\s+$/, '$1');
  184. if (o.sDate) o.sDate = o.sDate.slice(o.sDate.lastIndexOf(': ') + 2);
  185. if (e.classList.contains('article_unreaded')) o.bUnread = true;
  186. return o;
  187. };
  188.  
  189. var changedArticles = function() {
  190. if (!target) return;
  191. var articles = target.getElementsByClassName('ar'),
  192. bFoundCurrentArticle = false,
  193. eExpandedCurrentArticle,
  194. treeTitle = currentTreeName(),
  195. eAc = currentExpandedArticle(),
  196. eUct = $id('unread_cnt_top'),
  197. nCnt = 0,
  198. aCnt;
  199. if (!articles.length || (nArticles > articles.length + nExcludes + 3)) {
  200. aHiId = [];
  201. aNgId = [];
  202. aAdId = [];
  203. bExclude = false;
  204. nArticles = 0;
  205. nExcludes = 0;
  206. nUnread = 0;
  207. nUnreadEx = 0;
  208. return;
  209. }
  210. if (eAc.length) eExpandedCurrentArticle = eAc[0];
  211. if (eUct && eUct.textContent && articles.length + nExcludes/* && !nUnread*/) {
  212. aCnt = eUct.textContent.match(/\d+/);
  213. if (aCnt && aCnt.length) {
  214. nCnt = Number(aCnt[0]);
  215. if (nCnt !== 1000 && nCnt !== 10000 && (!nUnread || nCnt !== nUnread - nUnreadEx)) {
  216. nUnread = nCnt;
  217. }
  218. }
  219. }
  220. nArticles = articles.length + nExcludes;
  221. loop1: for (var n1 = 0, l1 = articles.length; n1 < l1; n1++) {
  222. if (n1 === 0 && !st.hi && !st.ng) break;
  223. var eArticle = articles[n1],
  224. oA = articleData(eArticle);
  225. if (!oA.sId) continue;
  226. if (eArticle === eExpandedCurrentArticle) bFoundCurrentArticle = true;
  227. if (st.hi) {
  228. for (var n2 = 0, l2 = aHiId.length; n2 < l2; n2++) {
  229. if (oA.sId === aHiId[n2]) continue loop1;
  230. }
  231. }
  232. if (st.ng) {
  233. for (var n3 = 0, l3 = aNgId.length; n3 < l3; n3++) {
  234. if (oA.sId === aNgId[n3]) {
  235. if (oA.bUnread) nUnreadEx++;
  236. nExcludes++;
  237. continue loop1;
  238. }
  239. }
  240. }
  241. if (st.ad) {
  242. for (var n4 = 0, l4 = aAdId.length; n4 < l4; n4++) {
  243. if (oA.sId === aAdId[n4]) {
  244. if (oA.bUnread) nUnreadEx++;
  245. nExcludes++;
  246. continue loop1;
  247. }
  248. }
  249. }
  250. if (treeTitle) oA.sFeed += '\n' + treeTitle;
  251. var sArticleDU = oA.sDesc + '\n' + oA.sUrl,
  252. sArticleTDU = oA.sTitle + '\n' + oA.sDesc + '\n' + oA.sUrl,
  253. sCa = '';
  254. if (st.hi) {
  255. for (var i1 = 0, j1 = aHi.length; i1 < j1; i1++) {
  256. sCa = checkArticle(aHi[i1], oA.sFeed, oA.sTitle, sArticleDU, sArticleTDU);
  257. if (sCa) {
  258. if (st.log) console.log('highlight: ', oA.sTitle, ' / matching rule ', sCa);
  259. $id('article_' + oA.sId).classList.add('inoreader_filter_highlight');
  260. aHiId.push(oA.sId);
  261. continue loop1;
  262. }
  263. }
  264. }
  265. if (bExclude) break;
  266. if (st.ad) {
  267. var sT = oA.sTitle.replace(/^\s*(?:ad|pr|広告)\s?[::]\s*(.+)$/i, '$1')
  268. .replace(/^\s*[\[[【](?:ad|pr|広告)[\]]】]\s*(.+)$/i, '$1')
  269. .replace(/^(.+)\s*[\[[【](?:ad|pr|広告)[\]]】]\s*$/i, '$1');
  270. for (var i2 = 0, j2 = aAd.length, a; i2 < j2; i2++) {
  271. if (!aAd[i2] || notType('Str', aAd[i2]) || aAd[i2].indexOf('<>') === -1) continue;
  272. else if (aAd[i2].slice(0, aAd[i2].lastIndexOf('<>')).indexOf(sT) !== -1) {
  273. a = aAd[i2].slice(aAd[i2].lastIndexOf('<>') + 2).split('@');
  274. if ((!eAc.length || bFoundCurrentArticle) && a.length === 2 && Number(a[1]) && $id('article_' + oA.sId) !== eExpandedCurrentArticle) {
  275. if (st.log) console.log('remove ad: ', oA.sTitle);
  276. target.removeChild($id('article_' + oA.sId));
  277. aAdId.push(oA.sId);
  278. if (oA.bUnread) nUnreadEx++;
  279. nExcludes++;
  280. n1--;
  281. l1--;
  282. continue loop1;
  283. }
  284. }
  285. }
  286. }
  287. if (st.ng) {
  288. if (st.ad && new RegExp(st.adfilter, 'im').test(oA.sTitle + '\n' + oA.sDesc) && oA.sDate && (oA.sDate.length <= 5 || (oA.sDate.length > 5 && new Date(oA.sDate).getTime() + 86400000 * 60 > Date.now()))) continue;
  289. for (var i3 = 0, j3 = aNg.length; i3 < j3; i3++) {
  290. sCa = checkArticle(aNg[i3], oA.sFeed, oA.sTitle, sArticleDU, sArticleTDU);
  291. if (sCa) {
  292. if (st.log) console.log('remove: ', oA.sTitle, ' / matching rule ', sCa);
  293. target.removeChild($id('article_' + oA.sId));
  294. aNgId.push(oA.sId);
  295. if (oA.bUnread) nUnreadEx++;
  296. nExcludes++;
  297. n1--;
  298. l1--;
  299. continue loop1;
  300. }
  301. }
  302. }
  303. }
  304. if (!eUct.hasAttribute('data-irf_ngcheck')) changedNumberOfUnreadArticles();
  305. observer2.observe($id('unread_cnt_top'), config);
  306. };
  307. var observer1 = new MutationObserver(changedArticles);
  308.  
  309. var changedNumberOfUnreadArticles = function() {
  310. if (st.ngcount === 2) return;
  311. observer2.disconnect();
  312. var eUct = $id('unread_cnt_top');
  313. if (!eUct) return;
  314. var nDeduct = (nUnread) ? nUnread - nUnreadEx : 0,
  315. nCnt = 0,
  316. bModify = false,
  317. aCnt;
  318. eUct.removeAttribute('data-irf_ngcount');
  319. if (st.ngcount === 0) {
  320. if (nUnreadEx) eUct.setAttribute('data-irf_ngcount', '(' + nUnreadEx + ')');
  321. } else if (st.ngcount === 1) {
  322. aCnt = eUct.textContent.match(/\d+/);
  323. if (aCnt && aCnt.length) {
  324. nCnt = Number(aCnt[0]);
  325. if (nCnt !== 1000 && nCnt !== 10000) {
  326. nUnread = nCnt;
  327. nDeduct = (nUnread) ? nUnread - nUnreadEx : 0;
  328. if (nDeduct < 0) nDeduct = 0;
  329. eUct.textContent = eUct.textContent.replace(/([^\d]*)\d+([^\d]*)/, '$1' + nDeduct + '$2');
  330. bModify = true;
  331. }
  332. }
  333. }
  334. if (nArticles >= 50 && nExcludes / nArticles >= 0.8) {
  335. if (!bExclude) window.alert(LOC.t30);
  336. bExclude = true;
  337. }
  338. observer2.observe(eUct, config);
  339. eUct.setAttribute('data-irf_ngcheck', '1');
  340. };
  341. var observer2 = new MutationObserver(changedNumberOfUnreadArticles);
  342.  
  343. var createAdtable = function(type, flag) {
  344. var html = '',
  345. at = (aAdTemp || flag) ? aAdTemp.concat() : aAd.concat();
  346. switch (Number(type)) {
  347. case 0:
  348. at.sort(function(a, b) {
  349. var tA = a.slice(0, a.lastIndexOf('<>')),
  350. tB = b.slice(0, b.lastIndexOf('<>'));
  351. if (tA > tB) return 1;
  352. if (tA < tB) return -1;
  353. return 0;
  354. });
  355. break;
  356. case 1:
  357. at.sort(function(a, b) {
  358. var tA = a.slice(0, a.lastIndexOf('<>')),
  359. tB = b.slice(0, b.lastIndexOf('<>'));
  360. if (tA < tB) return 1;
  361. if (tA > tB) return -1;
  362. return 0;
  363. });
  364. break;
  365. case 2:
  366. at.sort(function(a, b) {
  367. var nA = a.slice(a.lastIndexOf('<>') + 2, -2),
  368. nB = b.slice(b.lastIndexOf('<>') + 2, -2);
  369. return Number(nB) - Number(nA);
  370. });
  371. break;
  372. case 3:
  373. at.sort(function(a, b) {
  374. var nA = a.slice(a.lastIndexOf('<>') + 2, -2),
  375. nB = b.slice(b.lastIndexOf('<>') + 2, -2);
  376. return Number(nA) - Number(nB);
  377. });
  378. break;
  379. }
  380. for (var i = 0, j = at.length, a, t, d; i < j; i++) {
  381. if (!at[i] || notType('Str', at[i]) || at[i].indexOf('<>') === -1) continue;
  382. t = at[i].slice(0, at[i].lastIndexOf('<>'));
  383. a = at[i].slice(at[i].lastIndexOf('<>') + 2).split('@');
  384. d = (a.length === 2 && Number(a[0]) >= 0) ? a[0] : '';
  385. if (!d) continue;
  386. html += '<div class="irf_tr"><div class="irf_ad_td1"><label><input id="irf_ad_switch_' + d + '" type="checkbox"' + (Number(a[1]) ? ' checked' : '') + ' value="' + a[1] + '" /><span title="' + LOC.t22 + ' : ' + new Date(Number(a[0])).toLocaleString() + '">' + t + '</span></label></div><div class="irf_ad_td2"><input id="irf_ad_remove_' + d + '" type="button" value="' + LOC.t12 + '" /></div></div>';
  387. }
  388. $id('irf_ad_table').innerHTML = html;
  389. };
  390.  
  391. var setSettingsTab = function(s) {
  392. for (var t = ['ng', 'hi', 'ad', 'etc'], i = 0; i < 4; i++) {
  393. $id('irf_tab_' + t[i]).classList.remove('irf_tab_selected');
  394. $id('irf_form_' + t[i]).style.display = 'none';
  395. }
  396. $id('irf_tab_' + s).classList.add('irf_tab_selected');
  397. $id('irf_form_' + s).style.display = 'block';
  398. if (s === 'ng' || s === 'hi') {
  399. if ($id('irf_' + s + '_add_word').getBoundingClientRect().left > 0)
  400. $id('irf_' + s + '_add_word').focus();
  401. else if ($id('irf_' + s + '_ta').getBoundingClientRect().left > 0)
  402. $id('irf_' + s + '_ta').focus();
  403. }
  404. };
  405.  
  406. var settingsMode = function(s) {
  407. var e = $id('irf_settings').getElementsByClassName('irf_advance');
  408. for (var i = 0, j = e.length; i < j; i++) {
  409. if (s === 'simple') e[i].classList.add('inoreader_filter_hide');
  410. else if (s === 'advance') e[i].classList.remove('inoreader_filter_hide');
  411. }
  412. };
  413.  
  414. var viewSettings = function() {
  415. var se = $id('irf_settings');
  416. if (!se) return;
  417. if (se.style.display !== 'block') {
  418. setSettingsTab('ng');
  419. $id('irf_ng_add_bt').classList.add('inoreader_filter_hide');
  420. $id('irf_hi_add_bt').classList.add('inoreader_filter_hide');
  421. $id('irf_ng_fill_bt').classList.remove('inoreader_filter_hide');
  422. $id('irf_hi_fill_bt').classList.remove('inoreader_filter_hide');
  423. $id('irf_ng_cb').checked = st.ng;
  424. $id('irf_hi_cb').checked = st.hi;
  425. $id('irf_ad_cb').checked = st.ad;
  426. if (st.ng) $id('irf_ng_fs').removeAttribute('disabled');
  427. else $id('irf_ng_fs').setAttribute('disabled', '');
  428. if (st.hi) $id('irf_hi_fs').removeAttribute('disabled');
  429. else $id('irf_hi_fs').setAttribute('disabled', '');
  430. $id('irf_ng_add_word').value = '';
  431. $id('irf_hi_add_word').value = '';
  432. $id('irf_ng_add_feed').value = '';
  433. $id('irf_hi_add_feed').value = '';
  434. $id('irf_ng_add_title').value = '';
  435. $id('irf_hi_add_title').value = '';
  436. $id('irf_ng_ta').value = st.ngdata;
  437. $id('irf_hi_ta').value = st.hidata;
  438. $id('irf_ad_filter').value = st.adfilter;
  439. $id('irf_ad_sort_type')[Number(st.adsort)].selected = true;
  440. if (st.mode === 'simple') $id('irf_etc_mode-s').checked = true;
  441. else if (st.mode === 'advance') $id('irf_etc_mode-a').checked = true;
  442. $id('irf_etc_key_settings').value = st.keywindow;
  443. $id('irf_etc_delimiter').value = st.delimiter;
  444. $id('irf_etc_ngcount')[Number(st.ngcount)].selected = true;
  445. $id('irf_etc_log').checked = st.log;
  446. aAdTemp = null;
  447. createAdtable(st.adsort);
  448. settingsMode(st.mode);
  449. se.style.display = 'block';
  450. if ($id('irf_ng_add_word').getBoundingClientRect().left > 0) $id('irf_ng_add_word').focus();
  451. else if ($id('irf_ng_ta').getBoundingClientRect().left > 0) $id('irf_ng_ta').focus();
  452. } else {
  453. se.style.display = 'none';
  454. $id('irf_ok').removeAttribute('disabled');
  455. }
  456. };
  457.  
  458. var loadSettings = function() {
  459. st = {};
  460. try {
  461. st = JSON.parse(localStorage.getItem('InoReaderFilter_settings')) || {};
  462. } catch (er) {
  463. alert('InoReaderFilter Error: Load Settings');
  464. }
  465. if (notType('Num', st.format)) st.format = 1;
  466. if (notType('Boo', st.ng)) st.ng = true;
  467. if (notType('Boo', st.hi)) st.hi = true;
  468. if (notType('Boo', st.ad)) st.ad = true;
  469. if (notType('Str', st.ngdata)) st.ngdata = '';
  470. if (notType('Str', st.hidata)) st.hidata = '';
  471. if (notType('Str', st.adfilter)) st.adfilter = reAd;
  472. if (notType('Num', st.adcount)) st.adcount = 0;
  473. if (notType('Num', st.adsort)) st.adsort = 0;
  474. if (notType('Str', st.mode)) st.mode = 'simple';
  475. if (notType('Str', st.keywindow)) st.keywindow = 'F';
  476. if (notType('Str', st.delimiter)) st.delimiter = '<>';
  477. if (notType('Num', st.ngcount)) st.ngcount = 0;
  478. if (notType('Boo', st.log)) st.log = false;
  479. convertRules();
  480. };
  481.  
  482. var saveSettings = function(flag) {
  483. try {
  484. localStorage.setItem('InoReaderFilter_settings', JSON.stringify(st));
  485. } catch (er) {
  486. alert('InoReaderFilter Error: Save Settings');
  487. }
  488. if (!flag) convertRules();
  489. };
  490.  
  491. var loadAddata = function() {
  492. try {
  493. aAd = JSON.parse(localStorage.getItem('InoReaderFilter_addata')) || [];
  494. } catch (er) {}
  495. };
  496.  
  497. var saveAddata = function(a) {
  498. if (aAdTemp) {
  499. aAd = aAdTemp.concat();
  500. aAdTemp = null;
  501. }
  502. try {
  503. localStorage.setItem('InoReaderFilter_addata', JSON.stringify(a));
  504. } catch (er) {
  505. alert('InoReaderFilter Error: Save AdData');
  506. }
  507. loadAddata();
  508. };
  509.  
  510. var init = function() {
  511. if (!target) return;
  512. loadSettings();
  513. loadAddata();
  514. var CSS =
  515. '#unread_cnt_top:after { content: attr(data-irf_ngcount); margin-left: 2px; opacity: 0.75; }' +
  516. '.inoreader_filter_highlight span[id^="at_"], .inoreader_filter_highlight a[id^="article_title_link_"], .inoreader_filter_highlight .article_title_link, .inoreader_filter_highlight.article_unreaded .article_header_title, .inoreader_filter_highlight.article_tile.article_unreaded .article_title_link { color: #B65F06; }' +
  517. '.high_contrast .inoreader_filter_highlight span[id^="at_"], .high_contrast .inoreader_filter_highlight a[id^="article_title_link_"], .high_contrast .inoreader_filter_highlight .article_title_link, .high_contrast .inoreader_filter_highlight.article_unreaded .article_header_title, .high_contrast .inoreader_filter_highlight.article_tile.article_unreaded .article_title_link { color: #D66F16; }' +
  518. '.inoreader_filter_hide { display: none; }' +
  519. '#irf_settings { display: none; color: black; padding: 0; position: absolute; top: 48px; left: 48px; z-index: 90300; background: rgba(255, 255, 255, 0.98); border: 1px solid #999999; border-radius: 4px; box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2); min-width: 20em; -moz-user-select: none; -webkit-user-select: none; }' +
  520. '#irf_settings input[type="text"], #irf_settings textarea { padding: 0 2px; }' +
  521. '#irf_settings input[type="button"] { font-size: 90%; height: 2em; }' +
  522. '#irf_settings select { font-size: 100%; padding: 1px 2px; }' +
  523. '#irf_settings fieldset, #irf_settings input[type="text"], #irf_settings input[type="number"], #irf_settings textarea { color: black; background-color: transparent; }' +
  524. '#irf_titlebar { background-color: #666666; border-radius: 4px 4px 0 0; padding: 2px 0 0 4px; height: 2em; }' +
  525. '#irf_title a { font-weight: bold; color: white; text-decoration: none; }' +
  526. '#irf_title a:hover { color: #FF9; }' +
  527. '#irf_title_btn { position: absolute; top: 2px; right: 4px; }' +
  528. '#irf_desc { padding: 0 0.5em; margin: 0.5em 0 1em 0; }' +
  529. '#irf_tab { padding: 0 0.5em; margin-top: 1em; }' +
  530. '#irf_tab span { background-color: #E9E9E9; background-image: -webkit-linear-gradient(#F9F9F9, #E9E9E9); background-image: linear-gradient(#F9F9F9, #E9E9E9); border: 1px solid #999999; padding: 3px 16px; border-radius: 4px 4px 0 0; cursor: pointer; }' +
  531. '#irf_tab span:hover { background-color: #F3F3F3; }' +
  532. '#irf_tab .irf_tab_selected, #irf_tab .irf_tab_selected:hover { background-color: #FFFFFF; background-image: none; border-bottom-color: #FFFFFF; }' +
  533. '#irf_form { padding: 8px 4px 4px 4px; border-top: 1px solid #999999; margin-top: 2px; }' +
  534. '#irf_form input[type="checkbox"], #irf_form input[type="radio"] { vertical-align: inherit; }' +
  535. '#irf_form input[type="checkbox"] { margin: 2px 4px 2px 0; }' +
  536. '#irf_form label { vertical-align: top; }' +
  537. '#irf_form textarea { margin: 0; width: 100%; height: 200px; }' +
  538. '#irf_form input, #irf_form textarea { color: black; }' +
  539. '#irf_form fieldset { padding: 4px; margin: 0 0 0.5em 0; border-color: #999; min-width: 490px; }' +
  540. '#irf_form fieldset:disabled > label { color: gray; }' +
  541. '#irf_form fieldset:disabled input, #irf_form fieldset:disabled textarea { color: #666666; background-color: #EEEEEE; }' +
  542. '#irf_form fieldset + fieldset { margin: 0.5em auto; }' +
  543. '#irf_form_hi, #irf_form_ad, #irf_form_etc { display: none; }' +
  544. '#irf_form_etc input[type="checkbox"] { margin: 2px 4px 2px 2px; }' +
  545. '.irf_form_add-row-button { text-align: right; }' +
  546. '.irf_form_add-row-input + .irf_form_add-row-caption, .irf_form_add-row-input + .irf_form_add-row-button { margin-top: 0.5em; }' +
  547. '.irf_form_add-row-textarea { margin-top: 1em; }' +
  548. '.inoreader_filter_hide + .irf_form_add-row-textarea { margin-top: 0; }' +
  549. '.irf_form_add-input { width: 95%; }' +
  550. '.irf_form_add-button:active { position:relative; top:1px; }' +
  551. '.irf_table_wrapper { max-height: 400px; overflow-y: scroll; }' +
  552. '.irf_table { display: table; width: 100%; }' +
  553. '.irf_tr { display: table-row; border: 1px solid red; }' +
  554. '.irf_tr:hover div { background-color: #EFEFEF; }' +
  555. '#irf_ad_sort { margin-left: 2em; font-weight: normal; }' +
  556. '#irf_ad_sort_type { padding: 0; margin-top: -4px; }' +
  557. '.irf_ad_td1, .irf_ad_td2 { display: table-cell; padding: 4px 2px; }' +
  558. '.irf_ad_td1 { max-width: 50em; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }' +
  559. '.irf_ad_td2 { width: 5em; }' +
  560. '.irf_ad_td2 input { width: 4.8em; }' +
  561. '#irf_etc_key_settings { width: 7ex; text-align: center; margin: 0 0.5em; }' +
  562. '#irf_ok { margin-right: 0.5em; padding: 0 2em; }' +
  563. '#irf_cancel { padding: 0 1ex; }' +
  564. '#irf_ok, #irf_cancel { width: 8em; }' +
  565. '.irf_form_add-button { width: 12em; }' +
  566. '#irf_form textarea, .irf_form_add-input { width: -moz-available; width: -webkit-fill-available; width: available; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }';
  567. if ($id('sb_rp_settings_menu')) {
  568. CSS += '.inoreader_filter_adarticle:before { font-family: "InoReader-UI-Icons-Font"; content: "\\e684"; padding-right: 5px; }';
  569. } else if ($id('read_articles_button')) {
  570. var img = $id('read_articles_button').firstChild;
  571. if (img && img.hasAttribute('src')) {
  572. CSS += '.inoreader_filter_adarticle:before { background: url("' + img.getAttribute('src') + '") no-repeat; content: " "; padding: 0 10px; }';
  573. }
  574. }
  575. GM_addStyle(CSS);
  576. var LOCALE_JA = {
  577. t00: '設定',
  578. t01: 'OK',
  579. t02: 'キャンセル',
  580. t03: 'NGワード',
  581. t04: 'ハイライト',
  582. t05: '広告記事',
  583. t06: 'その他',
  584. t07: 'フィード・フォルダ・タグ',
  585. t08: '記事タイトル',
  586. t09: '記事タイトル・記事概要・記事URL',
  587. t10: '記事概要・記事URL',
  588. t11: 'ルールを追加',
  589. t12: '削除',
  590. t13: '設定モード',
  591. t14: 'シンプル',
  592. t15: 'アドバンス',
  593. t16: '区切り文字',
  594. t17: 'コンソールにログを表示',
  595. t18: '選択記事をフォームに記入',
  596. t19: '累計',
  597. t20: 'ソート',
  598. t21: 'タイトル',
  599. t22: '登録日時',
  600. t23: '昇順',
  601. t24: '降順',
  602. t25: '新しい順',
  603. t26: '古い順',
  604. t27: 'ショートカットキー',
  605. t28: '設定欄の開閉',
  606. t29: 'キー',
  607. t30: '消去した記事が多すぎるので、InoReader Filterは記事を消去する機能を一時的に無効化しました。NGワードの設定を確認して下さい。',
  608. t31: 'ルール',
  609. t32: '正規表現',
  610. t33: 'NG記事数',
  611. t34: '未読記事数の後にNG記事数を表示する',
  612. t35: '未読記事数からNG記事数を差し引く',
  613. t36: 'NG記事数は表示しない'
  614. };
  615. var LOCALE_EN = {
  616. t00: 'Settings',
  617. t01: 'OK',
  618. t02: 'Cancel',
  619. t03: 'Exclude words',
  620. t04: 'Highlight words',
  621. t05: 'Advertising articles',
  622. t06: 'Etc',
  623. t07: 'Feed, folder, tag',
  624. t08: 'Article title',
  625. t09: 'Article title, summary, url',
  626. t10: 'Article summary, url',
  627. t11: 'Add rule',
  628. t12: 'Remove',
  629. t13: 'Settings mode',
  630. t14: 'Simple',
  631. t15: 'Advanced',
  632. t16: 'Delimiter',
  633. t17: 'Logging to console',
  634. t18: 'Fill in the selected article',
  635. t19: 'cumulative total',
  636. t20: 'Sort by',
  637. t21: 'Title',
  638. t22: 'Registered date',
  639. t23: 'A-Z',
  640. t24: 'Z-A',
  641. t25: 'newest',
  642. t26: 'oldest',
  643. t27: 'Shortcut keys',
  644. t28: 'Open/close the settings',
  645. t29: 'key',
  646. t30: 'Articles that was removed is too many. InoReader Filter has temporarily disabled the ability to remove the articles. Please check the settings of the exclude words.',
  647. t31: 'Rule',
  648. t32: 'regular expression',
  649. t33: 'The number of remove articles',
  650. t34: 'Show the number of remove articles after the number of unread articles',
  651. t35: 'Subtracting the number of remove articles from the number of unread articles',
  652. t36: 'Do not show the number of remove articles'
  653. };
  654. LOC = (window.navigator.language === 'ja') ? LOCALE_JA : LOCALE_EN;
  655.  
  656. var div = document.createElement('div');
  657. var html = '<div id="irf_titlebar"><div id="irf_title"><a href="https://greasyfork.org/scripts/895-inoreader-filter" target="_blank">InoReader Filter ' + LOC.t00 + '</a></div><div id="irf_title_btn"><input id="irf_ok" type="button" value="' + LOC.t01 + '" /><input id="irf_cancel" type="button" value="' + LOC.t02 + '" /></div></div><div id="irf_tab"><span id="irf_tab_ng" class="irf_tab_selected">' + LOC.t03 + '</span><span id="irf_tab_hi">' + LOC.t04 + '</span><span id="irf_tab_ad" class="irf_advance">' + LOC.t05 + '</span><span id="irf_tab_etc">' + LOC.t06 + '</span></div><div id="irf_form">';
  658. html += '<div id="irf_form_ng"><fieldset id="irf_ng_fs"><legend><label><input id="irf_ng_cb" type="checkbox" />' + LOC.t03 + '</label></legend><div class="irf_advance"><div class="irf_form_add-row-caption">' + LOC.t07 + ' :</div><div class="irf_form_add-row-input"><input id="irf_ng_add_feed" class="irf_form_add-input" type="input" /></div><div class="irf_form_add-row-caption">' + LOC.t08 + ' :</div><div class="irf_form_add-row-input"><input id="irf_ng_add_title" class="irf_form_add-input" type="input" /></div><div id="irf_ng_add_word-caption" class="irf_form_add-row-caption">' + LOC.t09 + ' :</div><div class="irf_form_add-row-input"><input id="irf_ng_add_word" class="irf_form_add-input" type="input" /></div><div class="irf_form_add-row-button"><input id="irf_ng_fill_bt" class="irf_form_fill-button" value="' + LOC.t18 + '" type="button" /><input id="irf_ng_add_bt" class="irf_form_add-button" value="' + LOC.t11 + '" type="button" /></div></div><div class="irf_form_add-row-textarea"><textarea id="irf_ng_ta"></textarea></div></fieldset></div>';
  659. html += '<div id="irf_form_hi"><fieldset id="irf_hi_fs"><legend><label><input id="irf_hi_cb" type="checkbox" />' + LOC.t04 + '</label></legend><div class="irf_advance"><div class="irf_form_add-row-caption">' + LOC.t07 + ' :</div><div class="irf_form_add-row-input"><input id="irf_hi_add_feed" class="irf_form_add-input" type="input" /></div><div class="irf_form_add-row-caption">' + LOC.t08 + ' :</div><div class="irf_form_add-row-input"><input id="irf_hi_add_title" class="irf_form_add-input" type="input" /></div><div id="irf_hi_add_word-caption" class="irf_form_add-row-caption">' + LOC.t09 + ' :</div><div class="irf_form_add-row-input"><input id="irf_hi_add_word" class="irf_form_add-input" type="input" /></div><div class="irf_form_add-row-button"><input id="irf_hi_fill_bt" class="irf_form_fill-button" value="' + LOC.t18 + '" type="button" /><input id="irf_hi_add_bt" class="irf_form_add-button" value="' + LOC.t11 + '" type="button" /></div></div><div class="irf_form_add-row-textarea"><textarea id="irf_hi_ta"></textarea></div></fieldset></div>';
  660. html += '<div id="irf_form_ad" class="irf_advance"><fieldset id="irf_ad_filter_fs"><legend>' + LOC.t31 + ' (' + LOC.t32 + ')</legend><input id="irf_ad_filter" class="irf_form_add-input" type="text"></fieldset><fieldset id="irf_ad_fs"><legend id="irf_ad_legend" title="' + LOC.t19 + ' : ' + st.adcount + '"><label><input id="irf_ad_cb" type="checkbox" />' + LOC.t05 + '</label><span id="irf_ad_sort">( ' + LOC.t20 + ' : <select id="irf_ad_sort_type"><option value="0">' + LOC.t21 + ' ( ' + LOC.t23 + ' )</option><option value="1">' + LOC.t21 + ' ( ' + LOC.t24 + ' )</option><option value="2">' + LOC.t22 + ' ( ' + LOC.t25 + ' )</option><option value="3">' + LOC.t22 + ' ( ' + LOC.t26 + ' )</option></select> )</span></legend><div id="irf_ad_table_wrapper" class="irf_table_wrapper"><div id="irf_ad_table" class="irf_table"></div></div></fieldset></div>';
  661. html += '<div id="irf_form_etc"><fieldset id="irf_etc_mode_fs"><legend>' + LOC.t13 + '</legend><label><input id="irf_etc_mode-s" name="irf_etc_mode_r" type="radio" value="simple" />' + LOC.t14 + '</label><label><input id="irf_etc_mode-a" name="irf_etc_mode_r" type="radio" value="advance" />' + LOC.t15 + '</label></fieldset><div class="irf_advance"><fieldset><legend>' + LOC.t27 + '</legend><label>' + LOC.t28 + ' : Ctrl+Shift+<input id="irf_etc_key_settings" type="text" maxlength="1" />' + LOC.t29 + '</label></fieldset><fieldset id="irf_etc_delimiter_fs"><legend>' + LOC.t16 + '</legend><input id="irf_etc_delimiter" type="input" /></fieldset><fieldset><legend>' + LOC.t33 + '</legend><select id="irf_etc_ngcount"><option value="0">' + LOC.t34 + '</option><option value="1">' + LOC.t35 + '</option><option value="2">' + LOC.t36 + '</option></select></fieldset><label><input id="irf_etc_log" type="checkbox">' + LOC.t17 + '</label></div></div>';
  662. html += '</div>';
  663. div.innerHTML = html;
  664. div.id = 'irf_settings';
  665. document.body.appendChild(div);
  666.  
  667. var menu = $id('sb_rp_settings_menu'),
  668. pqm = $id('preferences_quick_main'),
  669. item = document.createElement('div');
  670. item.id = 'irf_settings-menu';
  671. item.innerHTML = 'Filter ' + LOC.t00;
  672. if (menu) {
  673. item.className = 'inno_toolbar_button_menu_item';
  674. var menuList = menu.children;
  675. if (!menuList[menuList.length - 1].id) {
  676. var line = document.createElement('div');
  677. line.className = 'inno_toolbar_button_menu_line';
  678. menu.insertBefore(line, menu.lastChild.nextSibling);
  679. }
  680. menu.insertBefore(item, menu.lastChild.nextSibling);
  681. } else if ($id('quick_options') && pqm) {
  682. item.className = 'quick_options_link';
  683. pqm.insertBefore(item, pqm.lastChild.nextSibling);
  684. }
  685. if ($id('irf_settings-menu')) {
  686. $id('irf_settings-menu').addEventListener('click', function() {
  687. viewSettings();
  688. }, false);
  689. }
  690.  
  691. for (var i = 0, a; i < aAd.length; i++) {
  692. if (!aAd[i] || notType('Str', aAd[i]) || aAd[i].indexOf('<>') === -1) continue;
  693. a = aAd[i].slice(aAd[i].lastIndexOf('<>') + 2).split('@');
  694. if (a.length === 2 && (Date.now() > new Date(Number(a[0]) + (86400000 * 60)).getTime())) {
  695. if (st.log) console.log('unregister ad: ', aAd[i].slice(0, aAd[i].lastIndexOf('<>')));
  696. aAd.splice(i, 1);
  697. }
  698. }
  699. saveAddata(aAd);
  700.  
  701. var addRule = function(f, t, w) {
  702. var word = '';
  703. if (f) {
  704. word = f + st.delimiter;
  705. if (t) {
  706. word += t + st.delimiter;
  707. if (w) word += w;
  708. } else if (w) word += st.delimiter + w;
  709. } else if (t) {
  710. word = st.delimiter + t + st.delimiter;
  711. if (w) word += w;
  712. } else if (w) word = w;
  713. return word + '\n';
  714. };
  715.  
  716. var clickAddButton = function(s) {
  717. var sF = $id('irf_' + s + '_add_feed').value,
  718. sT = $id('irf_' + s + '_add_title').value,
  719. sW = $id('irf_' + s + '_add_word').value;
  720. if (!sT && !sW) return;
  721. var sData = $id('irf_' + s + '_ta').value,
  722. sRule = addRule(sF, sT, sW);
  723. if (sData.indexOf(sRule) === -1) {
  724. $id('irf_' + s + '_ta').value += (!sData || /(?:\r\n|\n|\r)$/.test(sData)) ? sRule : '\n' + sRule;
  725. }
  726. $id('irf_' + s + '_add_feed').value = '';
  727. $id('irf_' + s + '_add_title').value = '';
  728. $id('irf_' + s + '_add_word').value = '';
  729. $id('irf_' + s + '_add_word-caption').textContent = LOC.t09 + ' :';
  730. if (s === 'ng') {
  731. $id('irf_ng_add_bt').classList.add('inoreader_filter_hide');
  732. $id('irf_ng_fill_bt').classList.remove('inoreader_filter_hide');
  733. } else if (s === 'hi') {
  734. $id('irf_hi_add_bt').classList.add('inoreader_filter_hide');
  735. $id('irf_hi_fill_bt').classList.remove('inoreader_filter_hide');
  736. }
  737. };
  738.  
  739. var checkAd = function() {
  740. if (!target) return;
  741. var eAc = currentExpandedArticle();
  742. if (!eAc.length) return;
  743. var sId = (eAc[0].id) ? eAc[0].id.slice(eAc[0].id.lastIndexOf('_') + 1) : '';
  744. if (!sId) return;
  745. var eTitle = $id('at_' + sId) || $id('article_title_link_' + sId),
  746. sTitle = (eTitle) ? eTitle.textContent : '',
  747. bUnregistered = true;
  748. if (!sTitle) return;
  749. for (var i = 0, j = aAd.length; i < j; i++) {
  750. if (!aAd[i] || notType('Str', aAd[i]) || aAd[i].indexOf('<>') === -1) continue;
  751. if (sTitle === aAd[i].slice(0, aAd[i].lastIndexOf('<>'))) {
  752. bUnregistered = false;
  753. break;
  754. }
  755. }
  756. if (bUnregistered && new RegExp(st.adfilter, 'im').test(sTitle)) {
  757. aAd.push(sTitle + '<>' + Date.now() + '@1');
  758. aAd.sort(function(a, b) {
  759. return a - b;
  760. });
  761. if ($id('at_' + sId)) $id('at_' + sId).classList.add('inoreader_filter_adarticle');
  762. if ($id('article_title_link_' + sId)) $id('article_title_link_' + sId).classList.add('inoreader_filter_adarticle');
  763. if (st.log) console.log('register ad: ', sTitle);
  764. saveAddata(aAd);
  765. st.adcount++;
  766. saveSettings(true);
  767. $id('irf_ad_legend').setAttribute('title', LOC.t19 + ' : ' + st.adcount);
  768. changedArticles();
  769. }
  770. };
  771.  
  772. var escRe = function(s) {
  773. return s.replace(/[.+\^=!:${}()|\[\]\/\\]/g, '\\$&');
  774. };
  775.  
  776. $id('irf_settings').addEventListener('click', function(e) {
  777. var tId = e.target.id;
  778. if (!tId) return;
  779. if (e.target.nodeName === 'INPUT' && e.target.getAttribute('type') === 'button') {
  780. e.target.blur();
  781. }
  782. if (tId === 'irf_ok') {
  783. var problem = false,
  784. adfilter = $id('irf_ad_filter').value,
  785. delim = $id('irf_etc_delimiter').value,
  786. keyWin = $id('irf_etc_key_settings').value;
  787. st.ng = $id('irf_ng_cb').checked;
  788. st.ngdata = $id('irf_ng_ta').value;
  789. st.hi = $id('irf_hi_cb').checked;
  790. st.hidata = $id('irf_hi_ta').value;
  791. st.ad = $id('irf_ad_cb').checked;
  792. st.adfilter = adfilter ? adfilter : reAd;
  793. st.adsort = $id('irf_ad_sort_type').selectedIndex;
  794. st.ngcount = $id('irf_etc_ngcount').selectedIndex;
  795. if ($id('irf_etc_mode-s').checked) st.mode = 'simple';
  796. else if ($id('irf_etc_mode-a').checked) st.mode = 'advance';
  797. if (keyWin.length === 1) {
  798. if (/^[A-Za-z0-9]$/.test(keyWin)) st.keywindow = keyWin.toUpperCase();
  799. else {
  800. problem = true;
  801. setSettingsTab('etc');
  802. $id('irf_etc_key_settings').focus();
  803. }
  804. } else {
  805. $id('irf_etc_key_settings').value = 'F';
  806. st.keywindow = 'F';
  807. }
  808. if (delim) {
  809. if (/[.+\^=!:${}()|\[\]\/\\]/.test(delim)) {
  810. problem = true;
  811. setSettingsTab('etc');
  812. $id('irf_etc_delimiter').focus();
  813. } else st.delimiter = $id('irf_etc_delimiter').value;
  814. } else st.delimiter = '<>';
  815. st.log = $id('irf_etc_log').checked;
  816. if (!problem) {
  817. viewSettings();
  818. saveSettings();
  819. saveAddata((aAdTemp) ? aAdTemp : aAd);
  820. }
  821. } else if (tId === 'irf_cancel') {
  822. viewSettings();
  823. } else if (tId.indexOf('irf_tab_') !== -1) {
  824. var sId = tId.slice(tId.indexOf('irf_tab_') + 8);
  825. if (sId) setSettingsTab(sId);
  826. } else if (tId.indexOf('irf_etc_mode-') !== -1) {
  827. if (tId === 'irf_etc_mode-s') settingsMode('simple');
  828. else if (tId === 'irf_etc_mode-a') settingsMode('advance');
  829. } else if (/^irf_(?:ng|hi)_fill_bt$/.test(tId)) {
  830. var eAc = currentArticle(),
  831. sT = currentTreeName(),
  832. sF = '',
  833. sW = '';
  834. if (!eAc.length) return;
  835. var oA = articleData(eAc[0]);
  836. if (sT && oA.sFeed && sT !== oA.sFeed) sF = '/^' + escRe(sT) + '$|^' + escRe(oA.sFeed) + '$/';
  837. else if (sT) sF = sT;
  838. else if (oA.sFeed) sF = oA.sFeed;
  839. if (oA.sDesc) sW = '/^' + escRe(oA.sDesc) + '$|^' + escRe(oA.sUrl) + '$/';
  840. else sW = oA.sUrl;
  841. if (tId === 'irf_ng_fill_bt') {
  842. $id('irf_ng_add_feed').value = sF;
  843. $id('irf_ng_add_title').value = oA.sTitle;
  844. $id('irf_ng_add_word').value = sW;
  845. $id('irf_ng_add_bt').classList.remove('inoreader_filter_hide');
  846. $id('irf_ng_fill_bt').classList.add('inoreader_filter_hide');
  847. } else if (tId === 'irf_hi_fill_bt') {
  848. $id('irf_hi_add_feed').value = sF;
  849. $id('irf_hi_add_title').value = oA.sTitle;
  850. $id('irf_hi_add_word').value = sW;
  851. $id('irf_hi_add_bt').classList.remove('inoreader_filter_hide');
  852. $id('irf_hi_fill_bt').classList.add('inoreader_filter_hide');
  853. }
  854. } else if (tId === 'irf_ng_add_bt') {
  855. clickAddButton('ng');
  856. } else if (tId === 'irf_hi_add_bt') {
  857. clickAddButton('hi');
  858. } else if (/^irf_ad_switch_|^irf_ad_remove_/.test(tId)) {
  859. if (!aAdTemp) aAdTemp = aAd.concat();
  860. for (var i = 0, j = aAdTemp.length, a, t, d; i < j; i++) {
  861. if (!aAdTemp[i] || notType('Str', aAdTemp[i]) || aAdTemp[i].indexOf('<>') === -1) continue;
  862. t = aAdTemp[i].slice(0, aAdTemp[i].lastIndexOf('<>'));
  863. a = aAdTemp[i].slice(aAdTemp[i].lastIndexOf('<>') + 2).split('@');
  864. d = (a.length === 2 && Number(a[0]) >= 0) ? a[0] : '';
  865. if (d && tId.slice(14) === d) {
  866. if (/^irf_ad_switch_/.test(tId)) {
  867. aAdTemp[i] = aAdTemp[i].replace(/@\d$/, '@' + (a[1] === '1' ? '0' : '1'));
  868. } else if (/^irf_ad_remove_/.test(tId)) {
  869. aAdTemp.splice(i, 1);
  870. }
  871. createAdtable($id('irf_ad_sort_type').selectedIndex, true);
  872. break;
  873. }
  874. }
  875. }
  876. }, false);
  877.  
  878. $id('irf_ng_cb').addEventListener('click', function(e) {
  879. if (e.target.checked) $id('irf_ng_fs').removeAttribute('disabled');
  880. else $id('irf_ng_fs').setAttribute('disabled', '');
  881. }, false);
  882.  
  883. $id('irf_hi_cb').addEventListener('click', function(e) {
  884. if (e.target.checked) $id('irf_hi_fs').removeAttribute('disabled');
  885. else $id('irf_hi_fs').setAttribute('disabled', '');
  886. }, false);
  887.  
  888. $id('irf_titlebar').addEventListener('dblclick', function(e) {
  889. if (e.target.nodeName === 'DIV') {
  890. $id('irf_tab').classList.toggle('inoreader_filter_hide');
  891. $id('irf_form').classList.toggle('inoreader_filter_hide');
  892. $id('irf_title_btn').classList.toggle('inoreader_filter_hide');
  893. }
  894. }, false);
  895.  
  896. $id('irf_settings').addEventListener('input', function(e) {
  897. if (e.target.id === 'irf_ng_add_title') {
  898. if (e.target.value) $id('irf_ng_add_word-caption').textContent = LOC.t10 + ' :';
  899. else $id('irf_ng_add_word-caption').textContent = LOC.t09 + ' :';
  900. } else if (e.target.id === 'irf_hi_add_title') {
  901. if (e.target.value) $id('irf_hi_add_word-caption').textContent = LOC.t10 + ' :';
  902. else $id('irf_hi_add_word-caption').textContent = LOC.t09 + ' :';
  903. }
  904. if ($id('irf_tab_ng').classList.contains('irf_tab_selected')) {
  905. if ($id('irf_ng_add_feed').value || $id('irf_ng_add_title').value || $id('irf_ng_add_word').value) {
  906. $id('irf_ng_add_bt').classList.remove('inoreader_filter_hide');
  907. $id('irf_ng_fill_bt').classList.add('inoreader_filter_hide');
  908. } else {
  909. $id('irf_ng_add_bt').classList.add('inoreader_filter_hide');
  910. $id('irf_ng_fill_bt').classList.remove('inoreader_filter_hide');
  911. }
  912. } else if ($id('irf_tab_hi').classList.contains('irf_tab_selected')) {
  913. if ($id('irf_hi_add_feed').value || $id('irf_hi_add_title').value || $id('irf_hi_add_word').value) {
  914. $id('irf_hi_add_bt').classList.remove('inoreader_filter_hide');
  915. $id('irf_hi_fill_bt').classList.add('inoreader_filter_hide');
  916. } else {
  917. $id('irf_hi_add_bt').classList.add('inoreader_filter_hide');
  918. $id('irf_hi_fill_bt').classList.remove('inoreader_filter_hide');
  919. }
  920. }
  921. }, false);
  922.  
  923. $id('irf_ad_sort_type').addEventListener('change', function() {
  924. createAdtable($id('irf_ad_sort_type').selectedIndex);
  925. }, false);
  926.  
  927. $id('reader_pane').addEventListener('click', function() {
  928. checkAd();
  929. }, true);
  930.  
  931. document.addEventListener('keyup', function(e) {
  932. if (e.ctrlKey && e.shiftKey && e.keyCode === st.keywindow.charCodeAt()) viewSettings();
  933. else if (/input|textarea/i.test(e.target.tagName)) return;
  934. checkAd();
  935. }, true);
  936.  
  937. changedArticles();
  938. changedNumberOfUnreadArticles();
  939. observer1.observe(target, config);
  940. observer2.observe($id('unread_cnt_top'), config);
  941. };
  942.  
  943. iInit = window.setInterval(function() {
  944. if ($id('tree') && $id('tree').innerHTML && $id('unread_cnt_top')) {
  945. window.clearInterval(iInit);
  946. init();
  947. }
  948. }, 500);
  949.  
  950. })();