天涯读帖UI重修版(原ch620天涯读帖)

天涯帖子脱水,纯净阅读体验,支持按人名及长度过滤内容,允许自定义过滤规则

  1. // ==UserScript==
  2. // @name 天涯读帖UI重修版(原ch620天涯读帖)
  3. // @namespace tianya_ff2
  4. // @author ch620(原作者) motiam(UI重修)
  5. // @description 天涯帖子脱水,纯净阅读体验,支持按人名及长度过滤内容,允许自定义过滤规则
  6. // @version 2.1.3.2
  7. // @include http://*.tianya.cn/post*
  8. // @exclude http://bbs.tianya.cn/list*
  9. // @grant none
  10. // ==/UserScript==
  11. /*jshint -W004,-W008,-W009,-W014,-W030,-W032,-W033,-W041,-W043,-W051,-W054,-W058,-W075,-W084,-W086,-W107,-W116*/
  12.  
  13. function GM_addStyle(aCss) {
  14. 'use strict';
  15.  
  16. var head = document.getElementsByTagName('head')[0];
  17. if (head) {
  18. var style = document.createElement('style');
  19. style.setAttribute('type', 'text/css');
  20. style.textContent = aCss;
  21. head.appendChild(style);
  22. return style;
  23. }
  24. return null;
  25. }
  26.  
  27. var GM_log = console.log;
  28.  
  29. // This naive implementation will simply fail to do cross-domain requests,
  30. // just like any javascript in any page would.
  31. function GM_xmlhttpRequest(aOpts) {
  32. 'use strict';
  33. var req = new XMLHttpRequest();
  34.  
  35. __setupRequestEvent(aOpts, req, 'abort');
  36. __setupRequestEvent(aOpts, req, 'error');
  37. __setupRequestEvent(aOpts, req, 'load');
  38. __setupRequestEvent(aOpts, req, 'progress');
  39. __setupRequestEvent(aOpts, req, 'readystatechange');
  40.  
  41. req.open(aOpts.method, aOpts.url, !aOpts.synchronous,
  42. aOpts.user || '', aOpts.password || '');
  43. if (aOpts.overrideMimeType) {
  44. req.overrideMimeType(aOpts.overrideMimeType);
  45. }
  46. if (aOpts.headers) {
  47. for (var prop in aOpts.headers) {
  48. if (Object.prototype.hasOwnProperty.call(aOpts.headers, prop)) {
  49. req.setRequestHeader(prop, aOpts.headers[prop]);
  50. }
  51. }
  52. }
  53. var body = aOpts.data ? aOpts.data : null;
  54. if (aOpts.binary) {
  55. return req.sendAsBinary(body);
  56. } else {
  57. return req.send(body);
  58. }
  59. }
  60.  
  61. function __setupRequestEvent(aOpts, aReq, aEventName) {
  62. 'use strict';
  63. if (!aOpts['on' + aEventName]) return;
  64.  
  65. aReq.addEventListener(aEventName, function(aEvent) {
  66. var responseState = {
  67. responseText: aReq.responseText,
  68. responseXML: aReq.responseXML,
  69. readyState: aReq.readyState,
  70. responseHeaders: null,
  71. status: null,
  72. statusText: null,
  73. finalUrl: null
  74. };
  75. switch (aEventName) {
  76. case "progress":
  77. responseState.lengthComputable = aEvent.lengthComputable;
  78. responseState.loaded = aEvent.loaded;
  79. responseState.total = aEvent.total;
  80. break;
  81. case "error":
  82. break;
  83. default:
  84. if (4 != aReq.readyState) break;
  85. responseState.responseHeaders = aReq.getAllResponseHeaders();
  86. responseState.status = aReq.status;
  87. responseState.statusText = aReq.statusText;
  88. break;
  89. }
  90. aOpts['on' + aEventName](responseState);
  91. });
  92. }
  93.  
  94. var __GM_STORAGE_PREFIX = [
  95. '', GM_info.script.namespace, GM_info.script.name, ''].join('***');
  96.  
  97. // All of the GM_*Value methods rely on DOM Storage's localStorage facility.
  98. // They work like always, but the values are scoped to a domain, unlike the
  99. // original functions. The content page's scripts can access, set, and
  100. // remove these values. A
  101. function GM_deleteValue(aKey) {
  102. 'use strict';
  103. localStorage.removeItem(__GM_STORAGE_PREFIX + aKey);
  104. }
  105.  
  106. function GM_getValue(aKey, aDefault) {
  107. 'use strict';
  108. var val = localStorage.getItem(__GM_STORAGE_PREFIX + aKey);
  109. if (null === val && 'undefined' != typeof aDefault) return aDefault;
  110. return val;
  111. }
  112.  
  113. function GM_listValues() {
  114. 'use strict';
  115. var prefixLen = __GM_STORAGE_PREFIX.length;
  116. var values = [];
  117. var i = 0;
  118. for (i = 0; i < localStorage.length; i++) {
  119. var k = localStorage.key(i);
  120. if (k.substr(0, prefixLen) === __GM_STORAGE_PREFIX) {
  121. values.push(k.substr(prefixLen));
  122. }
  123. }
  124. return values;
  125. }
  126.  
  127. function GM_setValue(aKey, aVal) {
  128. 'use strict';
  129. localStorage.setItem(__GM_STORAGE_PREFIX + aKey, aVal);
  130. }
  131.  
  132. function GM_getResourceURL(aName) {
  133. 'use strict';
  134. return 'greasemonkey-script:' + GM_info.uuid + '/' + aName;
  135. }
  136. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  137.  
  138. function matchesSelector(element,selector){
  139. if(element.mozMatchesSelector){
  140. return element.mozMatchesSelector(selector);//firefox
  141. } else if(element.webkitMatchesSelector){
  142. return element.webkitMatchesSelector(selector);//chrome
  143. }
  144. }
  145.  
  146. var css_black;
  147.  
  148. function _func(f) {
  149. return (typeof f == 'function') ? f: new Function('$_', f.replace(/^=/, 'return '))
  150. }
  151.  
  152. var proto = {
  153. toString: function() {
  154. return 'Array[' + (this._map(function(x) { return x.toString() }).join(', ')) + ']';
  155. },
  156.  
  157. app: function(x) {
  158. if (typeof x == 'object')
  159. for (var i = 0; i < x.length; i++)
  160. this.push(x[i]);
  161. else
  162. this.push(x);
  163. return this;
  164. },
  165.  
  166. grep: function(f, not) {
  167. f = _func(f);
  168.  
  169. var r = [];
  170. for (var j = 0; j < this.length; j++)
  171. if ( f(this[j]) )
  172. r.push(this[j]);
  173. else if (not)
  174. not.push(this[j]);
  175. return r;
  176. },
  177.  
  178. _map: function(f) {
  179. f = _func(f);
  180.  
  181. var r = [];
  182. for (var j = 0; j < this.length; j++) {
  183. var x = f(this[j]);
  184. if (x === undefined || x === null)
  185. continue;
  186. r.push(x);
  187. }
  188. return r;
  189. },
  190.  
  191. a: function(x) {
  192. if (!this[0] || !x) return this;
  193. if (x._map) {
  194. var t = this;
  195. x.forEach(function(c) { t.a(c) });
  196. } else {
  197. if (x) this[0].appendChild(x);
  198. }
  199. return this;
  200. },
  201.  
  202. at: function(n, v) {
  203. if (typeof n == 'string') {
  204. if (n == 'style') {
  205. var l = v.split(';');
  206. for (var i = 0; i < l.length; i++) {
  207. var k = l[i].split(':');
  208. var imp = null;
  209. if (k[1] && k[1].match(/!\s*important/)) {
  210. k[1] = k[1].replace(/!\s*important/, '');
  211. imp = 'important';
  212. }
  213. k = k._map(function(x) {
  214. return x.replace(/^\s*/, '').replace(/\s*$/, '');
  215. });
  216. if (!k[1])
  217. this._map(function(x) {
  218. x.style.removeProperty(k[0]);
  219. });
  220. else
  221. this._map(function(x) {
  222. x.style.setProperty(k[0], k[1], imp);
  223. });
  224. }
  225. return this;
  226. }
  227. if (n[0] == '!') {
  228. var a = n.substr(1);
  229. this._map(function(x) {
  230. var k = (x.getAttribute(a) != 1);
  231. if (k) x.setAttribute(a, 1);
  232. else x.removeAttribute(a);
  233. });
  234. return this;
  235. }
  236. switch(v) {
  237. case undefined:
  238. return this.length ? this[0].getAttribute(n) : null;
  239. case '':
  240. case null:
  241. this._map(function(x) { x.removeAttribute(n) });
  242. break;
  243. default:
  244. this._map(function(x) { x.setAttribute(n, v) });
  245. }
  246. } else for (var i in n) this.at(i, n[i]);
  247.  
  248. return this;
  249. },
  250.  
  251. e: function(evt, f, tf) {
  252. if (f) switch(evt[0]) {
  253. case '-':
  254. evt = evt.substr(1);
  255. this._map(function(x) { x.removeEventListener(evt, f, tf? true : false) });
  256. break;
  257. case '+':
  258. evt = evt.substr(1);
  259. default:
  260. this._map(function(x) {x.addEventListener(evt, f, tf ? true: false)});
  261. }
  262. return this;
  263. },
  264.  
  265. f: function(x) {
  266. var s = x.substr(1);
  267. var ret = [];
  268. switch(x[0]) {
  269. case '>':
  270. this._map(function(e) {
  271. var x = e.childNodes;
  272. for (var i = 0; i < x.length; i++)
  273. ret.push(x[i]);
  274. });
  275. ret = (s ? ret.f('=' + s) : ret);
  276. break;
  277. case '<':
  278. if (!s) {
  279. ret = this._map(function(e) {
  280. e = e.parentNode;
  281. if (e) return e;
  282. });
  283. } else
  284. ret = this._map(function(e) {
  285. while (e && !matchesSelector(e, s))
  286. e = e.parentNode;
  287. if (e && (e.mozMatchesSelector || e.webkitMatchesSelector))
  288. return e;
  289. });
  290. break;
  291. case '=':
  292. ret = this.grep(function(e) { return matchesSelector(e, s) });
  293. break;
  294. case '@':
  295. ret = this._map(function(e) { return e.querySelector(s) });
  296. break;
  297. case '&':
  298. ret = this.f(s);
  299. if (!ret.length) {
  300. ret = $('+' + s);
  301. this.a(ret);
  302. }
  303. break;
  304. default:
  305. this._map(function(e) {
  306. ret.app(e.querySelectorAll(x));
  307. });
  308. }
  309. return ret._map(function(x) { return x.wrappedJSObject ? x.wrappedJSObject : x });
  310. },
  311.  
  312. i: function(a, f) {
  313. var x = this[0];
  314. if (f === 0)
  315. f = x.firstChild;
  316. if (!f) {
  317. this.a(a);
  318. return this;
  319. } else if (f[0])
  320. f = f[0];
  321.  
  322. if (a.constructor == Array) {
  323. for (var i = 0; i < a.length; i++)
  324. x.insertBefore(a[i], f);
  325. } else
  326. x.insertBefore(a, f);
  327. return this;
  328. },
  329.  
  330. item: function(x) {
  331. if (x < 0) x += this.length;
  332. if (x < 0 || x >= this.length) return [];
  333. return [this[x]];
  334. },
  335.  
  336. r: function() {
  337. this._map(function(c) {if (c) { var p = c.parentNode; if (p) p.removeChild(c) }});
  338. return this;
  339. },
  340.  
  341. txt: function(t) {
  342. if (t === undefined)
  343. return this._map('=$_.textContent').join('');
  344. else
  345. this._map(function(x) {x.textContent = t});
  346. return this;
  347. },
  348. };
  349.  
  350. for (var i in proto)
  351. Array.prototype[i] = proto[i];
  352.  
  353. function err(p) {
  354. var e = new Error;
  355. if (typeof p == 'string') {
  356. e.message = 'Error: ' + p;
  357. return e;
  358. }
  359. for (var i in p) {
  360. e[i] = p[i];
  361. }
  362. return e;
  363. };
  364.  
  365. function s2p(a) {
  366. var h, r = {};
  367. if (h = a.match(/^(\w[\w\d]*)/))
  368. r.tag = h[1];
  369.  
  370. if (h = a.match(/#(\w[\w\d\-]+)/))
  371. r.id = h[1];
  372.  
  373. if (h = a.match(/\.\w[\w\d\-]*/g))
  374. r.classes = h._map('=$_.substr(1)');
  375.  
  376. if (h = a.match(/\[.*?\]/g)) {
  377. r.attr = {};
  378. for (var i = 0; i < h.length; i++) {
  379. var t = h[i].substr(1, h[i].length - 2)
  380. .split('=');
  381. r.attr[t[0]] = t[1];
  382. }
  383. }
  384.  
  385. return r;
  386. };
  387.  
  388. function new_header(tag, text) {
  389. $('head').i($('+' +tag, text));
  390. };
  391.  
  392. var $ = window.$ = function(x) {
  393. function ce(tag, txt, attr) {
  394. if (typeof tag == 'object') {
  395. tag = arguments[0];
  396. content = arguments[1];
  397. attr = arguments[2];
  398. }
  399.  
  400. var r = s2p(tag);
  401. var s;
  402. if (r.tag == 'text')
  403. s = document.createTextNode(txt);
  404. else {
  405. s = document.createElement(r.tag);
  406. if (txt) s.textContent = txt;
  407. }
  408. if (r.id) s.id = r.id;
  409. if (r.classes) s.className = r.classes.join(' ');
  410.  
  411. if (r.attr) [s].at(r.attr);
  412. if (attr) [s].at(attr);
  413.  
  414. if (s.wrappedJSObject) s = s.wrappedJSObject;
  415. return s;
  416. }
  417.  
  418. if (typeof x == 'string') {
  419. if (x[0] == '+')
  420. return new Array(ce(x.substr(1), arguments[1], arguments[2]));
  421. else
  422. return new Array(document).f(x);
  423. } else {
  424. var ret = [];
  425. for (var i = 0; i < arguments.length; i++) {
  426. var e = arguments[i];
  427. if (e.wrappedJSObject) ret.push(e.wrappedJSObject);
  428. else ret.push(e);
  429. }
  430. return ret;
  431. }
  432. };
  433.  
  434. function keys(obj) {
  435. var ret = [];
  436. for (var x in obj) ret.push(x);
  437. return ret;
  438. }
  439.  
  440. var pref = window.pref = {
  441. _rec: {},
  442. _nocache: {},
  443. _proc: {},
  444. _handles: {
  445. load_bool: function(name) {
  446. pref._rec[name] = (GM_getValue(name) == 1);
  447. },
  448. load_int: function(name) {
  449. var v = parseInt(GM_getValue(name));
  450. if (v != v) v = 0;
  451. pref._rec[name] = v;
  452. },
  453. load_str: function(name) {
  454. var v = GM_getValue(name);
  455. if (v == null) v = '';
  456. pref._rec[name] = v;
  457. },
  458. load_obj: function(name) {
  459. var v;
  460. try { v = JSON.parse(GM_getValue(name)); }
  461. catch(e) { v = null; }
  462. pref._rec[name] = v;
  463. },
  464. save_str: function(name, v) {
  465. pref._rec[name] = v;
  466. GM_setValue(name, v);
  467. },
  468. save_int: function(name, v) {
  469. var nv = parseInt(v);
  470. if (nv != nv) nv = 0;
  471. pref._rec[name] = nv;
  472. GM_setValue(name, nv);
  473. },
  474. save_bool: function(name, v) {
  475. v = (v == 1);
  476. pref._rec[name] = v;
  477. GM_setValue(name, v ? 1 : 0);
  478. },
  479. save_obj: function(name, v) {
  480. pref._rec[name] = v;
  481. GM_setValue(name, JSON.stringify(v));
  482. },
  483. },
  484.  
  485. decl: function(name, type, def_v, func, nocache) {
  486. var f = pref._handles['save_' + type];
  487. if (!f) {
  488. console.error('bad pref type: ' + type);
  489. return;
  490. }
  491. if (func) pref._proc[name] = func;
  492. if (nocache) pref._nocache[name] = 1;
  493.  
  494. var x = GM_getValue(name);
  495. if (x === null || x === undefined)
  496. f(name, def_v);
  497.  
  498. pref.__defineGetter__(name, function() {
  499. if (this._rec[name] === undefined || (this._nocache[name]))
  500. this._handles['load_' + type](name);
  501. return this._rec[name];
  502. });
  503. pref.__defineSetter__(name, function(v) {
  504. this._handles['save_' + type](name, v);
  505. if (this._proc[name])
  506. this._proc[name](v);
  507. });
  508. },
  509. }
  510.  
  511. var ui = {
  512. panel_button: function(parm) {
  513. var btn = $('+span.panel-button' + parm.tag + '-toggle',
  514. parm.icon, {title: parm.title});
  515. parm.btn = btn[0];
  516.  
  517. btn.e('click', function(e) {ui.panel_show(parm)});
  518. $('@#panel-btns').a(btn);
  519. return btn;
  520. },
  521.  
  522. panel_create: function(parm) {
  523. var p = $('+div.panel' + parm.tag);
  524. p.a($('+div.panel-inside')
  525. .a($('+div.panel-head', parm.title)
  526. .a($('+span.panel-close', '✗', {
  527. title: '关闭'
  528. }).e('click',
  529. function() {
  530. ui.panel_hide(p[0], parm.btn);
  531. $(document.body).at('style', 'text-align:');
  532. }
  533. ))
  534. )
  535. .a(parm.func())
  536. );
  537. p[0].btn = parm.btn;
  538. if (parm.auto_del)
  539. p[0].auto_del = true;
  540. p[0]._shown = false;
  541. $('@body').a(p);
  542. return p;
  543. },
  544.  
  545. panel_hide: function(p, btn) {
  546. if (p.auto_del) $(p).r();
  547. else {
  548. $(p).at('style', 'display:none');
  549. p._shown = null;
  550. }
  551. $(btn).at('active', '');
  552. },
  553.  
  554. panel_show: function(parm) {
  555. $('.panel')._map(function(x) {
  556. if (x.btn != parm.btn) {
  557. ui.panel_hide(x, x.btn);
  558. }
  559. });
  560.  
  561. var p = $(parm.tag);
  562. if (!p.length)
  563. p = ui.panel_create(parm);
  564. if (p[0]._shown) {
  565. p[0]._shown = false;
  566. ui.panel_hide(p[0], parm.btn);
  567. } else {
  568. p[0]._shown = true;
  569. p.at('style', 'display: block');
  570. ui.set_panel_pos(p);
  571. ui.panel_fix(p);
  572. $(parm.btn).at('active', 1);
  573. }
  574. },
  575.  
  576. set_panel_pos: function(p) {
  577. var bar = $('#bar-wrapper');
  578. if (pref.bar_on_top)
  579. p.at('style', 'top:' + bar[0].offsetHeight + 'px;bottom:0');
  580. else
  581. p.at('style', 'top: 0; bottom:'+bar[0].offsetHeight+'px');
  582. },
  583.  
  584. panel_fix: function(p) {
  585. var pi = p.f('@.panel-inside');
  586. var s = pi.f('@.flex').at('style', 'height:');
  587. if (!s.length) return;
  588.  
  589. var diff = pi[0].clientHeight - p[0].clientHeight + 4;
  590. s.at('style', 'height:' + (s[0].clientHeight - diff) + 'px');
  591. if (diff > 0) {
  592. p.f('.td:last-child, .th:last-child').at('style', 'padding-right: 20px');
  593. } else {
  594. p.f('.td:last-child, .th:last-child').at('style', 'padding-right:');
  595. }
  596. },
  597.  
  598. single_select: function(e) {
  599. var t = [e.target];
  600. if (!t.f('=.sel-item').length)
  601. t = t.f('<.sel-item');
  602. if (!t.length) return;
  603.  
  604. t.f('<').f('>.sel-item[selected]').at('selected', '');
  605. t.at('selected', 1);
  606. },
  607.  
  608. multi_select: function(e) {
  609. var t = [e.target];
  610. var s = 'selected';
  611. var ls = '_last_sel';
  612. if (!t.f('=.sel-item').length)
  613. t = t.f('<.sel-item');
  614.  
  615. if (!t.length) return;
  616.  
  617. var tb = t.f('<');
  618. var l = tb.f('>.sel-item');
  619. var last = tb[0][ls];
  620.  
  621. function between() {
  622. var sel = [];
  623. var on = 0;
  624. if (last == t[0]) return [last];
  625.  
  626. for (var i = 0; i < l.length; i++) {
  627. switch(on) {
  628. case 0:
  629. if (l[i] == last || l[i] == t[0]) {
  630. on = 1;
  631. sel.push(l[i]);
  632. }
  633. break;
  634. case 1:
  635. sel.push(l[i]);
  636. if (l[i] == last || l[i] == t[0])
  637. on = 2;
  638. break;
  639. case 2:
  640. return sel;
  641. }
  642. }
  643. return sel;
  644. }
  645.  
  646. if (!e.ctrlKey) l.at(s, '');
  647.  
  648. if (!e.shiftKey || !last || !last.parentNode) {
  649. if (e.ctrlKey)
  650. t.at('!' + s);
  651. else
  652. t.at(s, 1);
  653.  
  654. tb[0][ls] = t[0].getAttribute(s) ? t[0] : null;
  655. } else {
  656. between().at(s, 1);
  657. }
  658. },
  659.  
  660. check_ctrl: function(e) {
  661. if (!e.ctrlKey) {
  662. ui.info_box('按住 Ctrl 鍵');
  663. return false;
  664. }
  665. return true;
  666. },
  667.  
  668. text_button: function(tag, text, func, attr) {
  669. var x = $('+span.text-button'+tag, text);
  670. if (func)
  671. x.e('+click', func);
  672. if (attr) x.at(attr);
  673. return x;
  674. },
  675.  
  676. toggle_button: function(tag, text, func, value) {
  677. return $('+span.toggle-button' + tag, text)
  678. .at('on', value ? 1 : '')
  679. .e('+click', function(e) {
  680. $(e.target).at('!on');
  681. func(e.target, e.target.getAttribute('on'))
  682. });
  683. },
  684.  
  685. goto_item: function(a) {
  686. if (!a) return;
  687. a.scrollIntoView();
  688. $(a).at('goto', 1);
  689. setTimeout(function() {
  690. $(a).at('goto', '');
  691. }, 3000);
  692. },
  693.  
  694. info_box: function(txt, attr) {
  695. $('@#info-box').r();
  696. var b = $('+div#info-box', txt)
  697. .at(attr)
  698. .e('click', function() {b.r()});
  699. $('@body').a(b);
  700. setTimeout(function() { b.r() }, 5000);
  701. },
  702.  
  703. menu_item: function(x) {
  704. var m, icon = $('+span.menu-icon'),
  705. label = $('+span.menu-label');
  706. if (x.icon) {
  707. icon.txt(x.icon);
  708. if (x.icon_attr) icon.at(x.icon_attr);
  709. }
  710. label.txt(x.label);
  711. if (x.label_attr)
  712. label.at(x.label_attr);
  713.  
  714. if (x.href)
  715. m = $('+a.menu-item', '', {href: x.href});
  716. else
  717. m = $('+div.menu-item');
  718.  
  719. if (x.func)
  720. m.e('+click', x.func);
  721.  
  722. return m.a(icon).a(label);
  723. },
  724.  
  725. popup_menu: function(menus, anchor, fixed) {
  726. ui.unpop();
  727. var m = $('+div.menu-popup.popup');
  728. for (var i = 0; i < menus.length; i++) {
  729. menus[i]._map(function(x) {
  730. m.a(ui.menu_item(x));
  731. });
  732. if (i < menus.length - 1)
  733. m.f('>').item(-1).at('menuend', 1);
  734. }
  735. m.at('style', 'position: fixed');
  736. $('@body').a(m);
  737. ui.set_anchor(m, anchor, fixed);
  738. $(window).e('+click', ui.unpop);
  739. return m;
  740. },
  741.  
  742. unpop: function() {
  743. $(window).e('-click', ui.unpop);
  744. $('.popup').r();
  745. },
  746.  
  747. cancel_event: function(e) {
  748. e.preventDefault();
  749. e.stopPropagation();
  750. },
  751.  
  752. pos: function(e, fixed) {
  753. var xy;
  754. if (fixed) {
  755. xy = [0, 0];
  756. if (e.offsetParent) {
  757. xy = ui.pos(e.offsetParent, true);
  758. xy[0] -= e.offsetParent.scrollLeft;
  759. xy[1] -= e.offsetParent.scrollTop;
  760. }
  761.  
  762. xy[0] += e.offsetLeft;
  763. xy[1] += e.offsetTop;
  764. } else {
  765. xy = e.offsetParent ? ui.pos(e.offsetParent) : [0, 0];
  766. xy[0] += e.offsetLeft;
  767. xy[1] += e.offsetTop;
  768. }
  769.  
  770. return xy;
  771. },
  772.  
  773. set_anchor: function(m, a, fixed) {
  774. var xy = ui.pos(a);
  775. m.at('style', 'position:' + (fixed ? 'fixed' : 'absolute'));
  776. m.at('style', 'top:' + (xy[1] + a.clientHeight) + 'px; '
  777. + 'left:' + xy[0] + 'px;');
  778. if (fixed &&
  779. (xy[1] + a.clientHeight + m[0].clientHeight > window.innerHeight))
  780. {
  781. m.at('style', 'top:' + (xy[1] - m[0].clientHeight - 4) + 'px');
  782. }
  783. },
  784.  
  785. text_box: function(a) {
  786. var m = $('+label'), txt;
  787. if (a.before) m.a($('+text', a.before));
  788. m.a(txt = $('+input[type=text]' + a.tag));
  789. if (a.after) m.a($('+text', a.after));
  790. if (a.value !== undefined)
  791. txt[0].value = a.value;
  792. if (a.func)
  793. txt.e('change', a.func);
  794. if (a.size)
  795. txt[0].size = a.size;
  796. return a.block ? $('+div').a(m) : m;
  797. },
  798.  
  799. check_box: function(a) {
  800. var m = $('+label');
  801. var c = $('+input[type=checkbox]');
  802. m.a(c).a($('+text', a.label));
  803. if (a.value) c.at('checked', 1);
  804. if (a.func) c.e('click', a.func);
  805. return a.block ? $('+div').a(m) : m;
  806. },
  807.  
  808. popup_window: function(a, anchor, fixed) {
  809. ui.unpop();
  810. var w;
  811. if (a.perm) {
  812. w = $(a.tag);
  813. if (w.length)
  814. return w.f('<.popup-window');
  815. }
  816. w = $('+div.popup-window' + (a.perm ? '' : '.popup'));
  817. var t = [];
  818. if (a.title) {
  819. w.a(t = $('+div.panel-head', a.title).at({
  820. style: 'text-align: left'
  821. }));
  822. }
  823. w.at(a.attr).a($('+div.popup-inside' + a.tag)
  824. .a(a.func())
  825. );
  826. $('@body').a(w);
  827. if (anchor)
  828. ui.set_anchor(w, anchor, fixed);
  829. if (a.perm)
  830. t.a($('+span.panel-close', '✗').e('click', function() {
  831. w.r()
  832. }));
  833. else
  834. $(window).e('+click', ui.unpop);
  835.  
  836. return w;
  837. },
  838.  
  839. prefs_group: function(title, items) {
  840. var g = $('+div.prefs-group');
  841. g.a($('+div.prefs-title', title));
  842. g.a($('+div.prefs-body').a(items));
  843. return g;
  844. },
  845.  
  846. click: function(t) {
  847. var e = document.createEvent('MouseEvent');
  848. e.target = t;
  849. e.initEvent('click', true, true, window, 0, 0, 0, 0, 0,
  850. false, false, false, false, 1, null);
  851. t.dispatchEvent(e);
  852. },
  853. }
  854.  
  855. function wjo(a) {
  856. return a.wrappedJSObject ? a.wrappedJSObject : a;
  857. }
  858.  
  859. var ff = window.ff = {
  860. n_pages: 0,
  861. pages: {},
  862. visits: 0,
  863. replies: 0,
  864. lz_list: {},
  865.  
  866. prefs_hook: [],
  867.  
  868. cols: [ ['show', '.n', '☼' ],
  869. ['hl', '.n', '♥'],
  870. ['lz', '.n', '♛'],
  871. ['author', '', '作者', '.l'],
  872. ['idx', '.n', '#'],
  873. ['len', '.n', '长度', '.r'],
  874. ['imgs', '.n', '图', '.r']
  875. ],
  876.  
  877. url_gen: null,
  878. go_page: null,
  879.  
  880. get_vars: function () { // get vars
  881. var metas = document.getElementsByTagName('meta');
  882. for (i=0; i<metas.length; i++) {
  883. if (metas[i].getAttribute("name") == "author") {
  884. ff.first_author = metas[i].getAttribute("content");
  885. break;
  886. }
  887. }
  888. if (ff.first_author)
  889. ff.lz_list[ff.first_author] = 1;
  890.  
  891. ff.stupid_form = (window.jumpPage != null);
  892. },
  893.  
  894. // process DOM
  895. get_current_page: function (div) {
  896. if (!div) div = [document.body];
  897.  
  898. var pg = {id: null, ids: null, n_pages: 0, idx: 0};
  899. ff.get_vars('author', 'jumpPage');
  900. pg.n_pages = 0;
  901. var body = $('@body');
  902.  
  903. var href = 'http://' + location.host + location.pathname;
  904. var flat = [];
  905.  
  906. function parse_item(a) {
  907. var n = a.nodeName.toLowerCase();
  908. switch(n) {
  909. case '#text':
  910. var h;
  911. a = a.textContent.replace(/^[\s ]*/, '').replace(/。{3,}/g, '……');
  912.  
  913. if (a.match(/^[\-—_=\+\.。\*-_=,,;;::、~~+]{8,}.*?分割.*?[\-—_=\+\.。\*-_=,,;;::、~~+]{8,}$/)) {
  914. flat.app($('+hr'));
  915. return;
  916. }
  917.  
  918. if (h = a.match(/^[\-—_=\+\.。\*-_=,,;;::、~~+]{8,}/)) {
  919. a = a.replace(h[0], '');
  920. flat.app($('+hr'));
  921. }
  922.  
  923. if (h = a.match(/[\-—_=\+\.。\*-_=,,;;::、~~+]{8,}$/)) {
  924. a = a.replace(h[0], '');
  925. if (a.length) flat.app($('+p', a));
  926. flat.app($('+hr'));
  927. return;
  928. }
  929. if (a.length)
  930. flat.app($('+p', a))
  931.  
  932. return;
  933. case 'div':
  934. if(matchesSelector(a, 'div.read-menu')) {
  935. return;
  936. }
  937. if (!matchesSelector(a, 'div.atl-info') ) {
  938. [a].r().f('>')._map(parse_item);
  939. return;
  940. }
  941. break;
  942. case 'table':
  943. var h, aulink, time, post_idx;
  944. (a = $(a).r()).f('a[onclick]').r();
  945.  
  946. aulink = a.f('a')._map(function(x) {
  947. return $('+a.author', x.textContent,
  948. {href:'http://my.tianya.cn/name/'+x.textContent});
  949. });
  950.  
  951. if (h = a.f('.floor').txt().match(/(\d+)/)) {
  952. post_idx = h[1];
  953. }
  954.  
  955. var t = a.txt().replace(/^\s*/, '')
  956. .replace(/\s*$/, '')
  957. .replace(/ +/g, ' ');
  958.  
  959. if (!t) {
  960. console.log('got table, but no author link');
  961. return;
  962. }
  963.  
  964. if (!(h = t.match(/日期:(\d+-\d+-\d+ \d+:\d+:\d+)/)))
  965. return;
  966. time = h[1];
  967.  
  968. if (h = t.match(/访问:(\d+).*?回复:(\d+)/)) {
  969. pg.visits = h[1];
  970. pg.replies = h[2];
  971. }
  972.  
  973. flat.app(h = $('+div.post-head')
  974. .a($('+span.post-idx'))
  975. .a(aulink)
  976. .a($('+span.timestamp', time)));
  977. h.post_idx = post_idx;
  978. return;
  979.  
  980. case 'img':
  981. a.setAttribute("src", a.getAttribute('original'));
  982. $(a).r().at({height:'', width:'', onclick:'', onerror:'', onload:'', id:'',
  983. alt:'', style:'cursor:',loaded:'1'});
  984. case 'embed':
  985. case 'label':
  986. break;
  987.  
  988. case 'br':
  989. var x = flat[flat.length - 1];
  990. if (x && (x.nodeName) && x.nodeName.toLowerCase() == 'br')
  991. x.multi = 1;
  992. else
  993. flat.push(a);
  994. return;
  995. case 'a':
  996. a = $(a).r();
  997. if (!a[0].href) {
  998. a.f('>')._map(parse_item);
  999. return;
  1000. }
  1001. if (a[0].href.match(/wap\.tianya/)) return;
  1002.  
  1003. if (!a.f('img').length)
  1004. {
  1005. a = $('+a', a[0].textContent, {href: a[0].href});
  1006. }
  1007. if (a instanceof Array && a[0].href.indexOf('void') > -1)
  1008. {
  1009. return;
  1010. }
  1011. a = $('+p').a(a)[0];
  1012. break;
  1013.  
  1014. default:
  1015. [a].f('>')._map(parse_item);
  1016. return;
  1017. }
  1018. flat.push(a);
  1019. }
  1020.  
  1021. function get_posts() {
  1022. var h;
  1023. if (h = div.f('div.atl-info').txt()
  1024. .match(/点击:(\d+)/))
  1025. {
  1026. pg.visits = h[1];
  1027. }
  1028. if (h = div.f('div.atl-info').txt()
  1029. .match(/回复:(\d+)/))
  1030. {
  1031. pg.replies = h[1];
  1032. }
  1033. var l = cleanup();
  1034. l._map(parse_item);
  1035. }
  1036.  
  1037. function unflatten() {
  1038. var unflat = [];
  1039. var idx = 0;
  1040. var p = [], pb = [];
  1041. for (var i = 0; i < flat.length; i++) {
  1042. var t = flat[i];
  1043. var n = t.nodeName.toLowerCase();
  1044.  
  1045. if (n == 'p') {
  1046. if (p[0]) pb.a(t);
  1047. } else if (n == 'div') {
  1048. p = $('+div.post').a(t = $(t));
  1049.  
  1050. p.a(pb = $('+div.post-body'));
  1051.  
  1052. p[0].info = p.info = {
  1053. author: t.f('@a').txt(),
  1054. show: 0,
  1055. len: 0,
  1056. imgs: 0,
  1057. hl: 0,
  1058. page: pg.idx,
  1059. };
  1060.  
  1061. if (!p[0].info.author)
  1062. continue;
  1063. p[0].info.idx = t.post_idx ? t.post_idx : idx ++,
  1064.  
  1065. unflat.app(p);
  1066. t.f('.post-idx').txt(pg.idx + '-' + p.info.idx);
  1067.  
  1068. } else if (n == 'br') {
  1069. if (t.multi && pb[0]) {
  1070. var lastp = pb[0].lastChild;
  1071. if (lastp && matchesSelector(lastp, 'p')) {
  1072. lastp.className += ' gap';
  1073. }
  1074. }
  1075. } else
  1076. pb.a(t);
  1077. }
  1078. return unflat;
  1079. }
  1080. function cleanup() {
  1081. var t = div.f('title');
  1082. div.f('@head').f('>').r();
  1083. div.f('@head').a(t);
  1084. div.f('p#my_tomy_p, p.fromwap').r();
  1085. div.f('div').grep('=$_.id && $_.id.match(/^(adsp_|tianyaBrand)/)').r();
  1086. $('@body').at({style: 'background-color:', id: ''});
  1087.  
  1088. var l = [];
  1089. //if (!l.length)
  1090. // l = div.f('#firstAuthor, #pContentDiv.allpost');
  1091. //if (l.length <= 1)
  1092. // l = div.f('div#pContentDiv.mcon');
  1093. //if (!l.length)
  1094. // l = div.f('div.vcard, div.post');
  1095. //if (!l.length)
  1096. // l = div.f('#firstAuthor, #pContentDiv');
  1097.  
  1098. if (!l.length && 1 == pg.idx)
  1099. l = div.f('.atl-menu, .atl-item');
  1100. else if (!l.length)
  1101. l = div.f('.atl-item');
  1102. return l;
  1103. }
  1104. function guess_pages() {
  1105. var h, c = div.f('@div.pages, td#pageDivTop');
  1106. if (!c.length) return;
  1107.  
  1108. if (h = c.txt().match(/共(\d+)页/))
  1109. pg.n_pages = h[1];
  1110. if (h = href.match(/(\.s?html)$/))
  1111. h = h[1];
  1112. else {
  1113. console.log('not html file? ' + h[1]);
  1114. return;
  1115. }
  1116.  
  1117. var parts = href.replace(/\.s?html$/, '').split('/');
  1118.  
  1119. if (!pg.n_pages) pg.n_pages = 1;
  1120.  
  1121. c.f('a')._map(function(a) {
  1122. var is_last = a.textContent.match(/末页/);
  1123. var r = a.href.replace(/\.s?html$/, '').split('/');
  1124. for (var i = 0; i < r.length; i++)
  1125. if (parts[i].match(/^\d+$/) && (r[i] != parts[i])) {
  1126. var d = r[i];
  1127. parts[i] = '%';
  1128. if (is_last || d > pg.n_pages)
  1129. pg.n_pages = d;
  1130. }
  1131. });
  1132.  
  1133. pg.url_gen = function(x) {
  1134. if (x < 1 || x > ff.n_pages) return null;
  1135. var r = [];
  1136. for (var i = 0; i < parts.length; i++)
  1137. r.push((parts[i] == '%') ? x : parts[i]);
  1138. return r.join('/') + h;
  1139. };
  1140.  
  1141. if (pg.n_pages > 10000) {
  1142. pg.n_pages = 1;
  1143. return;
  1144. }
  1145.  
  1146. if (!pg.idx)
  1147. for (var i = 1; i <= pg.n_pages; i++)
  1148. if (pg.url_gen(i) == href) {
  1149. pg.idx = i;
  1150. break;
  1151. }
  1152. }
  1153.  
  1154. function get_reply_form() {
  1155. var r = div.f('#bbsPost');
  1156. if (r.length) {
  1157. ff.reply = $('+div#reply').a(r);
  1158. ff.add_reply_button();
  1159. }
  1160. console.log('reply: ' + r);
  1161. }
  1162.  
  1163. function get_pages() {
  1164.  
  1165. var pageinfo = [];
  1166. pageinfo = div.f('.atl-pages');
  1167. if (!pageinfo.length){
  1168. pg.idx = 1;
  1169. }
  1170. else{
  1171. var stronginfo = pageinfo.f('strong');
  1172. if(stronginfo.length)
  1173. pg.idx = stronginfo[0].textContent;
  1174. else
  1175. pg.idx = 1;
  1176. }
  1177. if (!ff.id) {
  1178. ff.id = pg.idx;//unsafeWindow.bbsGlobal['page'];
  1179. }
  1180. do {
  1181. if (ff.stupid_form) {
  1182. var apn = div.f('@input[name="apn"]');
  1183. if (!apn.length || !div.f('form[id="pageForm"]').length) {
  1184. console.log('Cannot find pageForm, assuming no replies');
  1185. break;
  1186. }
  1187. pg.ids = apn[0].value.split(',');
  1188. pg.n_pages = pg.ids.length;
  1189. ff.pageform = $('+form#pageform', '', {method: 'post'})
  1190. .a(div.f('form[id="pageForm"]').f('input[type="hidden"]'));
  1191.  
  1192. if (!pg.go_page) pg.go_page = function(x) {
  1193. if (x < 1 || x > ff.n_pages) return;
  1194. ff.pageform[0].pID.value = x;
  1195. $('@body').a(ff.pageform);
  1196. ff.pageform[0].submit();
  1197. }
  1198. if (!pg.url_gen) pg.url_gen = function(x) {
  1199. return 'javascript:ff.go_page(' + x + ');';
  1200. }
  1201. console.log(pg.n_pages);
  1202. } else {
  1203. a = div.f('.atl-pages').f('a');
  1204. b = 0;
  1205. if(a.length > 1){
  1206. if(a[a.length-1].textContent == '下页')
  1207. b = a[a.length-2].textContent;
  1208. else
  1209. b = div.f('.atl-pages').f('strong')[0].textContent
  1210. }
  1211. else{
  1212. b = 1;
  1213. }
  1214. if (b) {
  1215. //pg.ids = a[0].value.replace(/,$/, '').split(',');
  1216. if(!pg.ids){
  1217. pg.ids = new Array();
  1218. }
  1219.  
  1220. for(var i = 0; i < b; i ++){
  1221. pg.ids[i] = i+1;
  1222. }
  1223. pg.n_pages = pg.ids.length;
  1224.  
  1225. if (!pg.idx && ff.id) {
  1226. for (var i = 0; i < pg.ids.length; i++)
  1227. if (pg.ids[i] == ff.id) {
  1228. pg.idx = i + 1;
  1229. break;
  1230. }
  1231. }
  1232. }
  1233. if (!pg.ids) break;
  1234.  
  1235. pg.url_gen = function(x) {
  1236. var ids = ff.ids;
  1237. if (!ids) {
  1238. console.log('expecting to gen page link, but ids is null');
  1239. return null;
  1240. }
  1241. return href.replace('-'+ff.id+'.', '-'+ids[x - 1]+'.');
  1242. }
  1243. }
  1244. } while(0);
  1245. if (pg.n_pages > 10000) { // guessed wrong
  1246. console.log('too many pages: ' + pg.n_pages);
  1247. pg.n_pages = 1;
  1248. }
  1249.  
  1250. if (!pg.n_pages || !pg.idx) {
  1251. console.log('will guess pages');
  1252. guess_pages();
  1253. }
  1254. if (!pg.idx) pg.idx = 1;
  1255. if (!pg.n_pages) pg.n_pages = 1;
  1256. if (!ff.url_gen) ff.url_gen = pg.url_gen;
  1257. if (!pg.go_page) {
  1258. pg.go_page = function(x) { location.href = ff.url_gen(x) };
  1259. }
  1260. }
  1261.  
  1262. get_reply_form();
  1263.  
  1264. div.f('style, script, link, meta').r();
  1265. ff.board_links =
  1266. div.f('@div.guide, div.myplace').f('a')
  1267. ._map(function(a) {
  1268. return $('+a.board', a.textContent.replace(/\s+/g, ''),
  1269. {href: a.href})[0]
  1270. });
  1271.  
  1272. ff.title = $('@#adsp_content_title_banner, h1').txt()
  1273. .replace(/\s/g, '')
  1274. .replace(/『.*』/, '');
  1275.  
  1276. get_pages();
  1277. get_posts();
  1278.  
  1279. pg.page = $('+div.page').at('page_idx', pg.idx)
  1280. .a($('+div.page-no', '第' + pg.idx + '页'))
  1281. .a(unflatten());
  1282.  
  1283. pg.page.f('.post')._map(function(p) {
  1284. p.info.len = p.lastChild.textContent.length;
  1285. p.info.imgs = $(p).f('img').length;
  1286. });
  1287. return pg;
  1288. },
  1289.  
  1290. add_reply_button: function() {
  1291. $('@#reply-panel-toggle').r();
  1292. var pbtns = $('@span#panel-btns');
  1293. if (pbtns.length) {
  1294. pbtns.a(ui.panel_button({
  1295. tag: '#reply-panel',
  1296. icon: '❞',
  1297. title: '回复',
  1298. func: ff.reply_panel
  1299. }))
  1300. }
  1301. },
  1302.  
  1303. // UI items
  1304. main_toolbar: function() {
  1305. var bar = $('@#bar-wrapper');
  1306. var tbtns, pbtns;
  1307. if (!bar.length) {
  1308. $('body')
  1309. .a($('+div#bar-wrapper').a(
  1310. bar = $('+div#main-tools')
  1311. .a(ff.board_links)
  1312. .a($('+span#page-links'))
  1313. .a(tbtns = $('+span#toggle-btns'))
  1314. .a(pbtns = $('+span#panel-btns'))
  1315. .a(ui.text_box({
  1316. tag: '#leng-limit',
  1317. before: '限长>',
  1318. value: pref.length_limit,
  1319. size: 4,
  1320. func: function(e) {
  1321. var x = e.target;
  1322. if (! x.value.match(/^\d+$/)) {
  1323. x.value = pref.length_limit;
  1324. return;
  1325. }
  1326. pref.length_limit = x.value;
  1327. ff.all_posts()._map(function(p){
  1328. ff.post_set_state(p);
  1329. });
  1330. }
  1331. })))
  1332. );
  1333. tbtns.a(ui.toggle_button(
  1334. '#hl-lz-button',
  1335. '♛',
  1336. function(b, on) {
  1337. b.title = (on ? '':'不') + '高亮楼主';
  1338. pref.hl_lz = on;
  1339. ff.post_update_all();
  1340. },
  1341. pref.hl_lz));
  1342.  
  1343. tbtns.a(ui.toggle_button(
  1344. '#show-all-button',
  1345. '☀',
  1346. function(b, on) {
  1347. b.title = on ? '全显示':'全隐藏';
  1348. pref.show_all = on;
  1349. ff.post_update_all();
  1350. },
  1351. pref.show_all));
  1352.  
  1353. if (ff.reply)
  1354. ff.add_reply_button()
  1355.  
  1356.  
  1357. pbtns.a(ui.panel_button({
  1358. tag: '#prefs-panel',
  1359. icon: '⚙',
  1360. title: '选项',
  1361. func: ff.prefs_panel
  1362. }))
  1363. .a(ui.panel_button({
  1364. tag: '#post-panel',
  1365. icon: '▤',
  1366. title: '帖子',
  1367. func: ff.post_panel
  1368. }))
  1369. }
  1370. return bar;
  1371. },
  1372.  
  1373. reply_panel: function() {
  1374. return ff.reply;
  1375. },
  1376.  
  1377. page_nav: function() {
  1378. var pl = $('#page-links');
  1379. if (!pl.length){
  1380. return;
  1381. }
  1382. pl.f('>').r();
  1383.  
  1384. var first = 100000, last = -1, loaded = 0;
  1385. for (var i in ff.pages) {
  1386. if (i < first) first = i;
  1387. if (i > last) last = i;
  1388. loaded ++;
  1389. }
  1390. var ret = [];
  1391. if (first > 1)
  1392. ret.app($('+a#prev-page', '«', {href: ff.url_gen(first - 1)})
  1393. .e('click', function(e) { ui.cancel_event(e); ff.go_page(first - 1) }, true)
  1394. );
  1395. ret.app($('+span#all-pages', (loaded > 1
  1396. ? '共' + ff.n_pages + '页 看' + loaded + '页'
  1397. : '第' + last + '/' + ff.n_pages + '页')
  1398. ).e('click', ff.page_link_window, true)
  1399. );
  1400. if (last < ff.n_pages)
  1401. ret.app($('+a#next-page', '»', {href: ff.url_gen(last * 1+ 1)})
  1402. .e('click', function(e) { ui.cancel_event(e); ff.go_page(last * 1 + 1) }, true)
  1403. );
  1404. pl.a(ret);
  1405. },
  1406.  
  1407. more_ui: [],
  1408.  
  1409. make_ui: function () {
  1410. var b = ff.main_toolbar();
  1411. ff.page_nav();
  1412.  
  1413. ['post_width', 'bar_on_top', 'bar_fixed', 'use_black'].forEach(function(x) {
  1414. pref[x] = pref[x];
  1415. });
  1416.  
  1417. ff.more_ui._map(function(f) { f() });
  1418. },
  1419.  
  1420. set_post_width: function(v) {
  1421. if (!v.toString().match(/^\d+$/) ) return null;
  1422. if (v - 10 < 0 ) v = 10;
  1423. ff.add_opt_css('post-width', '#content { max-width:' + v + 'em}');
  1424. return v;
  1425. },
  1426.  
  1427. get_content: function() {
  1428. var content = $('@#content');
  1429. if (!content.length) {
  1430. document.documentElement.lang = 'zh-CN';
  1431. content = $('+div#content')
  1432. .a($('+h1', ff.title))
  1433. .a($('+div#stats'));
  1434. $('body').a(content);
  1435. }
  1436. return content;
  1437. },
  1438.  
  1439. pre_insert: [function(page) {
  1440. page.page.f('div.post')._map (function(p){
  1441. p.innerHTML = p.innerHTML.replace(/&amp;/g, '&');
  1442. })
  1443. }],
  1444. post_insert: [],
  1445.  
  1446. add_page: function(page) {
  1447. function max(a, b) {
  1448. if (b && !a) return b;
  1449. if (a && !b) return a;
  1450. return Math.max(a, b);
  1451. }
  1452.  
  1453. var pg = page.page;
  1454. //hack. sometimes we don't get the first post right...
  1455.  
  1456. ff.visits = max(page.visits, ff.visits);
  1457. ff.replies = max(page.replies, ff.replies);
  1458.  
  1459. if (!ff.n_pages || (ff.n_pages < page.n_pages)) {
  1460. ff.n_pages = page.n_pages;
  1461. ff.ids = page.ids;
  1462. if (!ff.url_gen)
  1463. ff.url_gen = page.url_gen;
  1464. if (!ff.go_page) {
  1465. ff.go_page = page.go_page;
  1466. }
  1467. }
  1468.  
  1469. pg.f('>.post')._map(ff.post_set_lz_info);
  1470.  
  1471. if (ff.pages[page.idx])
  1472. ff.remove_page(page.idx);
  1473.  
  1474. try {
  1475. ff.pre_insert._map(function(x) { x(page) });
  1476. } catch(e) { // insert no matter what
  1477. }
  1478.  
  1479. var ps = pg.f('>.post');
  1480. pg[0]._posts = ps.length;
  1481.  
  1482. ps._map(function(p) {
  1483. ff.post_row(p);
  1484. ff.post_set_state(p);
  1485. });
  1486.  
  1487. pg.e('click', ff.page_click, true);
  1488. var ins = null, have = [];
  1489.  
  1490. for (var i in ff.pages){
  1491. have.push(i);
  1492. }
  1493. have.sort(function(a,b) { return a - b });
  1494.  
  1495. for (var i = 0; i < have.length; i ++) {
  1496. if (have[i] - page.idx > 0) {
  1497. ins = ff.pages[have[i]].page[0];
  1498. break;
  1499. }
  1500. }
  1501. ff.get_content().i(page.page, ins);
  1502. ff.pages[page.idx] = page;
  1503.  
  1504. try {
  1505. ff.post_insert._map(function(x) { x(page) });
  1506. } catch(e) { // insert no matter what
  1507. }
  1508.  
  1509. var tbl = $('@#post-table').f('>.tbody');
  1510. if (tbl.length)
  1511. tbl.a(ps._map('=$_._link'));
  1512.  
  1513. if (ff.visits && ff.replies)
  1514. $('@#stats').txt('访问:'+ff.visits + ' 回复:'+ff.replies);
  1515. ff.page_nav();
  1516. },
  1517.  
  1518. remove_page: function(idx) {
  1519. var p = ff.pages[idx];
  1520. if (p) {
  1521. p.page.r();
  1522. p.page.f('>.post')._map(function(x) {
  1523. $(x, x._link).r();
  1524. });
  1525. }
  1526. delete ff.pages[idx];
  1527. ff.page_nav();
  1528. },
  1529.  
  1530. post_row: function(p) {
  1531. var tr = $('+div.tr.post-row.sel-item')[0];
  1532. tr.cell = {};
  1533. ff.cols._map(function(x) {
  1534. var cell;
  1535. $(tr).a(cell = $('+span.td.cell-' + x[0] + (x[3] ? x[3] :'')));
  1536. tr.cell[x[0]] = cell[0];
  1537. });
  1538. var i = p.info;
  1539. var ticks = ' ✓✗';
  1540. tr.cell.show.textContent = ticks[i.show];
  1541. //tr.cell.hl.textContent = ticks[i.hl];
  1542. tr.cell.lz.textContent = i.lz ? '♛':' ';
  1543. tr.cell.idx.textContent = $(p.firstChild).f('@.post-idx').txt();
  1544. ['author', 'len', 'imgs']._map(function(x) {
  1545. tr.cell[x].textContent = i[x];
  1546. });
  1547. p._link = tr;
  1548. tr._link = p;
  1549. tr.info = p.info;
  1550. return tr;
  1551. },
  1552.  
  1553. post_table: function() {
  1554. var thead, tbody;
  1555. var tbl = $('+div.table#post-table')
  1556. .a(thead = $('+div.thead#post-table-head'))
  1557. .a(tbody = $('+div.tbody.flex#post-table-body')
  1558. .e('click', ui.multi_select)
  1559. .e('dblclick', ff.table_dblclk)
  1560. ).e('click', ff.table_click);
  1561.  
  1562. ff.cols.forEach(function(x) {
  1563. var th = $('+span.th.cell-'+ x[0] + x[1], x[2]);
  1564. thead.a(th);
  1565. thead[0][x[0]] = th[0];
  1566. });
  1567. thead.f('.cell-show')[0].sort_v = function(r) {
  1568. return (r.getAttribute('show') ? 1 : 0) * 10000000 +
  1569. r.info.page * 10000 +
  1570. r.info.idx * 1;
  1571. };
  1572. thead.f('.cell-idx')[0].sort_v = function(r) {
  1573. return r.info.page * 10000 +
  1574. r.info.idx *1;
  1575. };
  1576. thead.f('.cell-hl')[0].sort_v = function(r) {
  1577. return r.info.hl * 1000000 +
  1578. r.info.page * 10000 +
  1579. r.info.idx * 1;
  1580. };
  1581. thead.f('.cell-lz')[0].sort_v = function(r) {
  1582. return (r.info.lz ? r.info.lz : 3) * 1000000
  1583. - r.info.page * 10000
  1584. - r.info.idx * 1;
  1585. };
  1586. thead.f('.cell-imgs')[0].sort_v = function(r) {
  1587. return r.info.imgs * 1000 + (r.info.lz? 1 : 0) * 1;
  1588. };
  1589. thead.f('.cell-author')[0].sort_v = function(r) {
  1590. return r.info.author
  1591. + (100000000 - r.info.page * 10000 - r.info.idx * 1);
  1592. };
  1593.  
  1594. tbody.a(ff.all_posts()._map(function(p) { return p._link }));
  1595. return tbl;
  1596. },
  1597.  
  1598. all_posts: function() {
  1599. var posts = [];
  1600. for (var pi in ff.pages)
  1601. posts.app(ff.pages[pi].page.f('>.post'));
  1602. return posts;
  1603. },
  1604.  
  1605. post_panel: function() {
  1606. function all_rows() {
  1607. var ret = [];
  1608. var t = $('@#post-table');
  1609. if (!t.length) return ret;
  1610. return t.f('.tr');
  1611. }
  1612. function sel_rows() {
  1613. var ret = [];
  1614. var t = $('@#post-table');
  1615. if (!t.length) return ret;
  1616. return t.f('.tr[selected]');
  1617. }
  1618. return [ ff.post_table(),
  1619. $('+div', '').a([
  1620. ui.text_button('#hl-button', '反选', function() {
  1621. all_rows().at('!selected');
  1622. }),
  1623. ui.text_button('#on-off-button', '开关', function() {
  1624. var s = sel_rows()._map('=$_._link');
  1625. if (!s.length) return;
  1626. var sh = 0, sum = 0;
  1627. s._map(function(p) { sum += p.info.show });
  1628. if (sum < s.length)
  1629. sh = 1;
  1630. else if (sum < s.length *2)
  1631. sh = 2;
  1632. s._map(function(p) {
  1633. p.info.show = sh;
  1634. ff.post_show(p);
  1635. });
  1636. }),
  1637. ui.text_button('#hl-button', '高亮', function() {
  1638. var s = sel_rows(), sum = 0;
  1639. s._map(function(r) { sum += r.info.hl });
  1640.  
  1641. var hl = sum < s.length ? 1 : 0;
  1642. s._map(function(r) { r.info.hl = hl; ff.post_hl(r._link) });
  1643. }),
  1644. ui.text_button('#delete-button', '删除', function(e) {
  1645. if (!ui.check_ctrl(e)) return;
  1646. var s = sel_rows();
  1647. if (!s.length) return;
  1648.  
  1649. var n = s.item(-1)[0].nextSibling;
  1650. s._map(function(r) {
  1651. ff.post_delete(r._link);
  1652. });
  1653. if (!n) n = $('#post-table').f('.sel-item').item(-1)[0];
  1654. if (n) ui.click(n);
  1655. }),
  1656. ])
  1657. ];
  1658. },
  1659.  
  1660. prefs_panel: function() {
  1661. var ret = [];
  1662. var x = ui.prefs_group('显示', [
  1663. ui.text_box({
  1664. tag: '#post-width',
  1665. before: '帖子宽度',
  1666. after: '字',
  1667. value: pref.post_width,
  1668. size: 3,
  1669. func: function(e) {
  1670. var x = e.target;
  1671. if (!x.value.match(/^\d+$/) || x.value < 10) {
  1672. x.value = pref.post_width;
  1673. return;
  1674. }
  1675. ff.set_post_width(pref.post_width = x.value);
  1676. },
  1677. block: 1
  1678. }),
  1679. ui.check_box({
  1680. value: pref.bar_on_top,
  1681. label: '工具条置顶',
  1682. func: function(e) {
  1683. pref.bar_on_top = e.target.checked ? 1 : 0;
  1684. },
  1685. block: 1
  1686. }),
  1687. ui.check_box({
  1688. value: pref.bar_fixed,
  1689. label: '固定工具条',
  1690. func: function(e) {
  1691. pref.bar_fixed = e.target.checked ? 1 : 0;
  1692. },
  1693. block: 1
  1694. }),
  1695. /*ui.check_box({
  1696. value: pref.use_black,
  1697. label: '黑色界面',
  1698. func: function(e) {
  1699. pref.use_black = e.target.checked ? 1 : 0;
  1700. },
  1701. block: 1
  1702. }),*/
  1703. ui.check_box({
  1704. value: pref.manual_start,
  1705. label: '手工启动脚本',
  1706. func: function(e) {
  1707. pref.manual_start = e.target.checked ? 1 : 0;
  1708. },
  1709. block: 1
  1710. }),
  1711. ]);
  1712. ret.push(x);
  1713. ff.prefs_hook.forEach(function(f) {
  1714. ret.push(f());
  1715. });
  1716. return $('+div.flex').a(ret);
  1717. },
  1718.  
  1719. page_click: function(e) {
  1720. var t = $(e.target);
  1721. if (t.f('=.post-idx').length) {
  1722. var post = t.f('<.post')[0];
  1723. ui.goto_item(post._link);
  1724. return;
  1725. } else if (t.f('<a[uname]').length) {
  1726. ui.cancel_event(e);
  1727. var m = ui.popup_menu([ff.post_menus, ff.author_menus],
  1728. e.target);
  1729. m[0]._post = t.f('<.post')[0];
  1730. m[0]._post.info = t.f('<.post')[0].info;
  1731. m[0]._post._link = t.f('<.post')[0]._link
  1732. return;
  1733. }
  1734. },
  1735.  
  1736. table_click: function(e) {
  1737. function cell_idx(x) {
  1738. var p = x.f('<');
  1739. var ch = p.f('>');
  1740. for (var i = 0; i < ch.length; i++) {
  1741. if (ch[i] == x[0]) return i;
  1742. }
  1743. }
  1744. function sort_by_header(th, rows) {
  1745. var func, idx, cmp;
  1746.  
  1747. function n(a, b) { return a._sort_by - b._sort_by }
  1748. function s(a, b) { return a._sort_by.localeCompare(b._sort_by) }
  1749. if (func = th[0].sort_v) {
  1750. rows._map(function(x) {
  1751. x._sort_by = func(x);
  1752. });
  1753. } else {
  1754. idx = cell_idx(th);
  1755. if (th.f('=.n').length) {
  1756. rows._map(function(x) {
  1757. x._sort_by = parseInt(x.children[idx].textContent);
  1758. });
  1759. } else {
  1760. rows._map(function(x) {
  1761. x._sort_by = '__' + x.children[idx].textContent;
  1762. });
  1763. }
  1764. }
  1765. rows.sort(th.f('=.n').length ? n : s);
  1766. var dir = !th[0].sor_dir;
  1767. th.f('<').f('>.th')._map(function(x) {delete x.sor_dir});
  1768. if (dir)
  1769. rows.reverse();
  1770. th[0].sor_dir = dir;
  1771. return rows;
  1772. }
  1773.  
  1774. var t = $(e.target).f('=.th');
  1775. if (t.length) {
  1776. var rows = sort_by_header(t, t.f('<.table').f('.tr'));
  1777. t.f('<.table').f('.tbody').a(rows);
  1778. return;
  1779. }
  1780.  
  1781. t = $(e.target).f('=.td');
  1782. if (t.length) {
  1783. var row = t.f('<.tr')[0];
  1784.  
  1785. var s = t.f('=.cell-idx');
  1786. if (s.length) {
  1787. ui.goto_item(row._link);
  1788. return;
  1789. }
  1790.  
  1791. s = t.f('=.cell-show');
  1792. if (s.length) {
  1793. p = row._link;
  1794. p.info.show ++;
  1795. if (p.info.show > 2) p.info.show = 0;
  1796. ff.post_show(p);
  1797. return;
  1798. }
  1799.  
  1800. s = t.f('=.cell-hl');
  1801. if (s.length) {
  1802. row.info.hl = row.info.hl ? 0 : 1;
  1803. ff.post_hl(row._link);
  1804. return;
  1805. }
  1806.  
  1807. s = t.f('=.cell-lz');
  1808. if (s.length) {
  1809. ff.author_toggle_lz(row.info.author);
  1810. return;
  1811. }
  1812. }
  1813. },
  1814.  
  1815. posts_by_author: function(a) {
  1816. return ff.all_posts().grep(function(p) {
  1817. return p.info.author == a
  1818. });
  1819. },
  1820.  
  1821. table_dblclk: function(e) {
  1822. var t = $(e.target).f('<.tr');
  1823. var tb = t.f('<.tbody');
  1824. var l = tb.f('>');
  1825. if (!e.ctrlKey)
  1826. l.at('selected', '');
  1827. l.grep(function(x) {
  1828. return x.info.author == t[0].info.author
  1829. }).at('selected', 1);
  1830. },
  1831.  
  1832. // functions for processing posts
  1833. post_filter: function(p) {
  1834. },
  1835.  
  1836. post_set_lz_info: function(p) {
  1837. p.info.lz = ff.lz_list[p.info.author];
  1838. },
  1839.  
  1840. post_set_state: function(p) {
  1841. ff.post_set_lz_info(p);
  1842. if (p.info.del) {
  1843. ff.post_delete(p);
  1844. return;
  1845. }
  1846. var lnk = wjo(p._link);
  1847. lnk.cell.lz.textContent = ' ♛'[p.info.lz ? 1 : 0];
  1848. switch (ff.lz_list[p.info.author]) {
  1849. case 1:
  1850. $(lnk.cell.lz).at('lz', 1);
  1851. ff.post_add_icon(p, '♛', '.lz-icon.fr', { title: '楼主' });
  1852. break;
  1853. case 2:
  1854. $(lnk.cell.lz).at('lz', 2);
  1855. ff.post_add_icon(p, '♛', '.lz-equiv.fr', { title: '准楼主' });
  1856. break;
  1857. default:
  1858. $(lnk.cell.lz).at('lz', '');
  1859. ff.post_remove_icon(p, '.lz-equiv');
  1860. }
  1861. ff.post_filter(p);
  1862. ff.post_show(p);
  1863. ff.post_hl(p);
  1864. },
  1865.  
  1866. post_show: function(p) {
  1867. var show = ((p.info.show == 1) || (
  1868. (p.info.len - pref.length_limit >= 0) &&
  1869. (p.info.show != 2) &&
  1870. ((pref.show_all == 1) || p.info.lz)
  1871. )) ? 1 : '';
  1872. var lnk = wjo(p._link);
  1873. lnk.cell.show.textContent = ' ✓✗'[p.info.show];
  1874. $(p, lnk).at('show', show);
  1875. },
  1876.  
  1877. post_hl: function(p) {
  1878. var hl = ((p.info.hl == 1) || (p.info.lz && (pref.hl_lz == 1))) ? 1 : '';
  1879. var lnk = wjo(p._link);
  1880. $(p, lnk).at('hl', hl);
  1881. lnk.cell.hl.textContent = (hl ? '♥':' ');
  1882. },
  1883.  
  1884. post_update_all: function() {
  1885. ff.all_posts()._map(function(p) { ff.post_set_state(p) });
  1886. },
  1887.  
  1888. post_delete: function(p) {
  1889. var pg = $(p).f('<');
  1890. var lnk = wjo(p._link);
  1891. $(p, lnk).r();
  1892. delete lnk._link;
  1893. delete p._link;
  1894. if (pg[0] &&! -- pg[0]._posts)
  1895. ff.remove_page(pg.at('page_idx'));
  1896. },
  1897.  
  1898. author_toggle_lz: function(a) {
  1899. try {
  1900. console.log('toggle lz of ' + a + ': ' + ff.lz_list[a]);
  1901. switch (ff.lz_list[a]) {
  1902. case 1:
  1903. return;
  1904. case 2:
  1905. delete ff.lz_list[a];
  1906. break;
  1907. default: ff.lz_list[a] = 2;
  1908. }
  1909.  
  1910. ff.posts_by_author(a)._map(function(p) {
  1911. ff.post_set_state(p);
  1912. });
  1913. } catch(e) { console.log(e) }
  1914. },
  1915.  
  1916. post_add_icon: function(p, icon, tag, attr) {
  1917. var h = $(p).f('>.post-head');
  1918. if (h.f(tag).length) return;
  1919. h.a($('+span.post-icon' + tag, icon, attr));
  1920. },
  1921.  
  1922. post_remove_icon: function(p, icon_tag) {
  1923. var h = $(p).f('>.post-head');
  1924. h.f('>' + icon_tag).r();
  1925. },
  1926.  
  1927. get_menu_post: function(e) {
  1928. return $(e.target).f('<.menu-popup')[0]._post;
  1929. },
  1930.  
  1931. post_menus: [{
  1932. icon: '✗',
  1933. icon_attr: {style: 'color: #faa' },
  1934. label: '隐藏帖子',
  1935. func: function(e) {
  1936. var p = ff.get_menu_post(e);
  1937. p.info.show = 2;
  1938. ff.post_show(p);
  1939. }
  1940. },
  1941. {
  1942. icon: '♥',
  1943. icon_attr: { style: 'color: purple' },
  1944. label: '高亮帖子',
  1945. func: function(e) {
  1946. var p = ff.get_menu_post(e);
  1947. p.info.hl = p.info.hl ? 0 : 1;
  1948. ff.post_hl(p);
  1949. }
  1950. },
  1951. {
  1952. icon: '✂',
  1953. label: '删除帖子',
  1954. label_attr: { style: 'color: #faa' },
  1955. func: function(e) {
  1956. if (ui.check_ctrl(e))
  1957. ff.post_delete(ff.get_menu_post(e));
  1958. }
  1959. },
  1960. ],
  1961.  
  1962. author_menus: [{
  1963. icon: '☠',
  1964. icon_attr: {style: 'color: #faa' },
  1965. label: '不看此人',
  1966. func: function(e) {
  1967. var p = ff.get_menu_post(e);
  1968. ff.posts_by_author(p.info.author)._map(function(x) {
  1969. x.info.show = 2;
  1970. ff.post_show(x);
  1971. });
  1972. }
  1973. },
  1974. {
  1975. icon: '❤',
  1976. icon_attr: { style: 'color: red; text-shadow: 0 0 1px black' },
  1977. label: '高亮作者',
  1978. func: function(e) {
  1979. var p = ff.get_menu_post(e), sum = 0, hl;
  1980. var ps = ff.posts_by_author(p.info.author);
  1981. ps._map(function(x) { sum += x.info.hl ? 1 : 0 });
  1982. hl = (sum < ps.length ? 1 : '');
  1983. ps._map(function(x) {
  1984. x.info.hl = hl;
  1985. ff.post_hl(x);
  1986. });
  1987. }
  1988. },
  1989. {
  1990. icon: '♛',
  1991. icon_attr: {style: 'color: #cfd'},
  1992. label: '楼主待遇',
  1993. func: function(e) {
  1994. var au = ff.get_menu_post(e).info.author;
  1995. ff.author_toggle_lz(au);
  1996. }
  1997. },
  1998. {
  1999. icon: '✄',
  2000. icon_attr: {style: 'color: red'},
  2001. label: '删除此人',
  2002. label_attr: { style: 'color: #faa' },
  2003. func: function(e) {
  2004. if (ui.check_ctrl(e)) {
  2005. var au = ff.get_menu_post(e).info.author;
  2006. ff.posts_by_author(au)._map(function(x) {
  2007. ff.post_delete(x);
  2008. });
  2009. }
  2010. }
  2011. },
  2012. ],
  2013.  
  2014. page_link_window: function(e) {
  2015. ui.cancel_event(e);
  2016. return ui.popup_window({
  2017. title: '分页',
  2018. tag: '#page-list',
  2019. attr: {
  2020. },
  2021. func: function() {
  2022. var l = [];
  2023. for (var i = 1; i <= ff.n_pages; i++) {
  2024. if (ff.pages[i])
  2025. l.push($('+span.subpage', i));
  2026. else
  2027. l.push($('+a.subpage', i, {
  2028. href: ff.url_gen(i)
  2029. }));
  2030. }
  2031. return l;
  2032. },
  2033. }, e.target, true).e('click', function(e) {
  2034. var t = $(e.target);
  2035. if (t.f('=a.subpage').length) {
  2036. ui.cancel_event(e);
  2037. ff.go_page(t.txt());
  2038. } else if (t.f('=span.subpage').length) {
  2039. ui.goto_item(ff.pages[t.txt()].page.f('@.page-no')[0]);
  2040. }
  2041. ui.unpop();
  2042. }, true);
  2043. },
  2044.  
  2045. option_css: {},
  2046. add_opt_css: function(name, content) {
  2047. ff.option_css[name] = content;
  2048. var t = [];
  2049. for (var i in ff.option_css) {
  2050. t.push(ff.option_css[i]);
  2051. }
  2052. $('@head').f('&style#opt-css').txt(t.join(''));
  2053. },
  2054. }
  2055.  
  2056. function ff_startup() {
  2057. ff.add_opt_css('img-css', 'img {max-width: 100% }');
  2058. pref.decl('post_width', 'int', 45, ff.set_post_width);
  2059. pref.decl('show_all', 'bool', true);
  2060. pref.decl('hl_lz', 'bool', false);
  2061. pref.decl('length_limit', 'int', 0);
  2062. pref.decl('bar_on_top', 'bool', false, function(v) {
  2063. $('#bar-wrapper').at('on_top', v ? 1 : '');
  2064. ui.set_panel_pos($('.panel'));
  2065. });
  2066.  
  2067. pref.decl('bar_fixed', 'bool', true, function(v) {
  2068. $('#main-tools').at('auto_hide', v ? '' : 1)
  2069. });
  2070. pref.decl('use_black', 'bool', false, function(v) {
  2071. ff.add_opt_css('#black-css', v ? css_black : '');
  2072. });
  2073. pref.post_width;
  2074. pref.show_all;
  2075. pref.hl_lz;
  2076. pref.length_limit;
  2077. pref.bar_on_top;
  2078. pref.bar_fixed;
  2079. pref.use_black;
  2080. }
  2081.  
  2082.  
  2083. // only go to bookmark ever once
  2084. var been_to_bookmark = false;
  2085.  
  2086. function checkstate(e) {
  2087. try {
  2088. var r = $(e.target)[0];
  2089. switch(r.readyState) {
  2090. case 0:
  2091. case 1: break;
  2092. case 2: r.content_len = r.getResponseHeader('Content-Length');
  2093. r.reset_timer();
  2094. break;
  2095. case 3: r.reset_timer();
  2096. r.set_progress(r.responseText.length);
  2097. break;
  2098. case 4: r.reset_timer(true);
  2099. r.finish_up();
  2100. }
  2101. } catch(ee) { console.trace(ee) }
  2102. }
  2103.  
  2104. // the class inheritance is very wrong
  2105. var bg_proto = {
  2106. finish_up: function() {
  2107. var r = $(this)[0];
  2108. if (r.progress_bar) {
  2109. r.progress_bar.r();
  2110. delete r.progress_bar;
  2111. }
  2112. if (! r._canceled) {
  2113. var s = r.responseText
  2114. .replace(/\n/g, ' ')
  2115. .replace(/^.*?<body[^>]*>/i, '')
  2116. .replace(/<\/body.*$/, '')
  2117. .replace(/<!--.*?-->/g, '');
  2118. var div = $('+div', '', {page_idx: r.page_idx});
  2119. div[0].innerHTML = s;
  2120. div.f('head, style, link, script').r();
  2121. var pg = ff.get_current_page(div);
  2122. pg.idx = r.page_idx;
  2123. delete ff.bg_loaders[r.page_idx];
  2124.  
  2125. if (pg.page.f('.post').length) {
  2126. ui.info_box('载入第'+r.page_idx +'页');
  2127. check_post_limit(pg);
  2128. } else {
  2129. console.log('载入第'+r.page_idx +'页不成功');
  2130. }
  2131. }
  2132. delete r;
  2133. },
  2134.  
  2135. start_loading: function() {
  2136. var r = $(this)[0];
  2137. var sendstr = null;
  2138.  
  2139. if (ff.stupid_form) {
  2140. var x = ff.pageform.f('#pID');
  2141. if (!x.length) {
  2142. ui.info_box("Don't know how to load page " + r.page_idx);
  2143. return;
  2144. }
  2145. x[0].value = r.page_idx;
  2146.  
  2147. sendstr = ff.pageform.f('input')._map(function(x) {
  2148. return x.name + '=' + encodeURIComponent(x.value)
  2149. }).join('&');
  2150.  
  2151. r.open('POST', location.href, true);
  2152. r.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  2153. r.setRequestHeader("Content-length", sendstr.length);
  2154. r.setRequestHeader("Connection", "close");
  2155. r.setRequestHeader("Cache-Control", "public");
  2156. } else {
  2157. r.open('GET', ff.url_gen(r.page_idx), true);
  2158. }
  2159.  
  2160. r.onreadystatechange = checkstate;
  2161.  
  2162. if (document.inputEncoding != 'UTF-8')
  2163. //They can't even do 18030, it's really GBK. Shame.
  2164. r.overrideMimeType("text/html; charset=GB18030");
  2165.  
  2166. r.set_progress(0);
  2167. r.reset_timer();
  2168. r.send(sendstr);
  2169. },
  2170.  
  2171. set_progress: function(p) {
  2172. var r = $(this)[0];
  2173. if (!r.progress_bar) {
  2174. var x = $('+div.loader');
  2175. $(document.body).f('&div#all-loaders').a(x);
  2176. var r = r;
  2177. x.a($('+div.progress-bar').a($('+div.progress-progress')))
  2178. .a($('+div.progress-ctrl')
  2179. .a($('+span.fr', '✗', {style: 'color: #faa', title: '取消'})
  2180. .e('click', function(e) { r.cancel() })
  2181. )
  2182. .a($('+span.fr', '♼', {style: 'color: #cfd', title: '重新载入'})
  2183. .e('click', function(e) { r.restart() })
  2184. )
  2185. .a($('+span', '第'+ r.page_idx + '页'))
  2186. );
  2187. r.progress_bar = x;
  2188. }
  2189. var bar = r.progress_bar.f('div.progress-progress');
  2190. if (p != 0) {
  2191. if (!r.content_len) p = 50;
  2192. else {
  2193. p /= (r.content_len / 100);
  2194. if (p > 100) p = 95;
  2195. }
  2196. }
  2197. bar.at('style', 'width: ' + p + 'px');
  2198. },
  2199. cancel: function() {
  2200. var r = $(this)[0];
  2201. r._canceled = 1;
  2202. r.reset_timer(true);
  2203. if (r.progress_bar)
  2204. r.progress_bar.r();
  2205. delete ff.bg_loaders[r.page_idx];
  2206. r.abort();
  2207. },
  2208. restart: function() {
  2209. var r = $(this)[0];
  2210. ui.info_box('重试页'+r.page_idx);
  2211. r.cancel();
  2212. load_page(r.page_idx);
  2213. },
  2214. reset_timer: function(norestart) {
  2215. var r = $(this)[0];
  2216. if (r._timer) {
  2217. clearTimeout(r._timer);
  2218. delete r._timer;
  2219. }
  2220. if (norestart || r._canceled) return;
  2221. r._timer = setTimeout(function() { r.restart() }, 3000);
  2222. },
  2223. }
  2224.  
  2225. XMLHttpRequest.prototype = {};
  2226.  
  2227. function bgLoader(idx) {
  2228. var r = (new XMLHttpRequest());
  2229. for (var f in bg_proto)
  2230. r[f] = bg_proto[f];
  2231. r.page_idx = idx;
  2232. r.start_loading();
  2233. }
  2234.  
  2235. function load_page(idx) {
  2236. console.log('load_page: ' + idx);
  2237. if (!ff.bg_loaders[idx])
  2238. ff.bg_loaders[idx] = new bgLoader(idx);
  2239. else
  2240. console.log('already loading');
  2241. }
  2242.  
  2243. function check_post_limit(new_pg) {
  2244. var l = $('@#content').f('>.page');
  2245. var sum = 0;
  2246. l._map(function(p) { sum += p._posts });
  2247. sum += new_pg.page.f('>.post').length;
  2248.  
  2249. var del = null;
  2250. if (sum > pref.max_posts) {
  2251. if (del = first_visible_post()) {
  2252. for (var i = 0; i < del.can.length && sum > pref.max_posts; i ++, sum --)
  2253. ff.post_delete(del.can[i]);
  2254. }
  2255. }
  2256. ff.add_page(new_pg);
  2257. if (del) {
  2258. var pos = document.documentElement.scrollTop - del.first.offsetTop;
  2259. document.documentElement.scrollTop += del.pos - pos;
  2260. }
  2261. check_load_bm();
  2262. }
  2263.  
  2264. function first_visible_post() {
  2265. var l = $('@#content').f('>.page').f('>.post');
  2266. var scroll = document.documentElement.scrollTop;
  2267. var can_del = [], pos = null, first;
  2268. for (var i = 0; i < l.length; i++) {
  2269. if (l[i].offsetTop + l[i].offsetHeight - scroll > 0) {
  2270. first = l[i];
  2271. pos = scroll - first.offsetTop;
  2272. break;
  2273. }
  2274. can_del.push(l[i]);
  2275. }
  2276. if (!first) return null;
  2277.  
  2278. var vis = [], invis = [];
  2279. vis = can_del.grep(function(p) { return p.getAttribute('show') }, invis);
  2280. invis.app(vis);
  2281. return {can:invis, first:first, pos: pos};
  2282. }
  2283.  
  2284. function add_page_control(pg) {
  2285. var h = pg.page.f('@.page-no');
  2286. h.a($('+span.page-disp', '☀', {title: '开关'}).e('click', function(e) {
  2287. $(e.target).f('<.page').at('!hide');
  2288. })
  2289. ).a($('+span.page-reload', '♻', {title: '重新加载'}).e('click', function(e){
  2290. load_page(pg.idx);
  2291. })
  2292. ).a($('+span.page-kill', '✘', {title: '删除分页'}).e('click', function(e) {
  2293. if (!ui.check_ctrl(e)) return;
  2294. ff.remove_page(pg.idx);
  2295. })
  2296. )
  2297. }
  2298.  
  2299. ff.bg_loaders = {};
  2300. var old_go_page = null;
  2301. pref.decl('use_one_page', 'bool', true, function(v) {
  2302. if (v) {
  2303. if (old_go_page) return;
  2304. old_go_page = ff.go_page;
  2305. ff.go_page = load_page;
  2306. } else {
  2307. if (ff.go_page != load_page) return;
  2308. ff.go_page = old_go_page;
  2309. old_go_page = null;
  2310. }
  2311. });
  2312. pref.use_one_page;
  2313. pref.decl('max_posts', 'int', 2000);
  2314. pref.max_posts;
  2315.  
  2316. function scroll_watch(e) {
  2317. var c = $('#content')[0];
  2318. if (!c) return;
  2319. var page = c.lastChild;
  2320. if (!page || !$(page).f('=.page')) return;
  2321. var scroll_top;
  2322. if (document.documentElement && document.documentElement.scrollTop)
  2323. scroll_top = document.documentElement.scrollTop;
  2324. else if (document.body)
  2325. scroll_top = document.body.scrollTop;
  2326. var y = scroll_top;
  2327. if (y == 0) return;
  2328. if (page.offsetTop < y + 2 * window.innerHeight) {
  2329. var idx = $(page).at('page_idx') * 1+ 1;
  2330. if (idx > 0 && idx <= ff.n_pages)
  2331. load_page(idx);
  2332. }
  2333. }
  2334.  
  2335. pref.decl('auto_load_page', 'bool', true, function(v) {
  2336. $(window).e((v ? '+' : '-') + 'scroll', scroll_watch, false);
  2337. });
  2338. pref.auto_load_page;
  2339.  
  2340. ff.prefs_hook.push(function() {
  2341. var x = ui.prefs_group('一页看帖', [
  2342. ui.check_box({
  2343. label: '启用一页看帖',
  2344. value: pref.use_one_page,
  2345. func: function(e) {
  2346. pref.use_one_page = e.target.checked ? 1 : 0;
  2347. },
  2348. block: 1
  2349. }),
  2350. ui.check_box({
  2351. label: '自动调入下页',
  2352. value: pref.auto_load_page,
  2353. func: function(e) {
  2354. pref.auto_load_page = e.target.checked ? 1 : 0;
  2355. },
  2356. block: 1
  2357. }),
  2358. ui.check_box({
  2359. label: '自动调入书签',
  2360. value: pref.auto_load_bookmark,
  2361. func: function(e) {
  2362. pref.auto_load_bookmark = e.target.checked ? 1 : 0;
  2363. },
  2364. block: 1
  2365. }),
  2366. ui.text_box({
  2367. tag: '#max-posts',
  2368. before: '最多保留',
  2369. after: '帖',
  2370. value: pref.max_posts,
  2371. size: 4,
  2372. func: function(e) {
  2373. var x = e.target;
  2374. if (! x.value.match(/^\d+$/)) {
  2375. x.value = pref.max_posts;
  2376. return;
  2377. }
  2378. pref.max_posts = x.value;
  2379. }
  2380. }),
  2381. ]);
  2382. return x;
  2383. });
  2384.  
  2385. // bookmark stuff
  2386. pref.decl('auto_load_bookmark', 'bool', true);
  2387. pref.auto_load_bookmark;
  2388. pref.decl('all_bookmarks', 'obj', {}, null, true);
  2389. pref.all_bookmarks;
  2390.  
  2391. ff.post_menus.push({
  2392. icon: '★',
  2393. icon_attr: { style: 'color: yellow; text-shadow: 0 0 1px black' },
  2394. label: '书签',
  2395. func: function(e) {
  2396. var p = ff.get_menu_post(e);
  2397. set_bookmark(p);
  2398. },
  2399. });
  2400. function get_bookmark_post() {
  2401. return $('.bookmark-icon').f('<.post');
  2402. }
  2403. function bm_title() {
  2404. return '[' + ff.board_links.item(-1).txt() + ']' + ff.title;
  2405. }
  2406. function set_bookmark(p) {
  2407. $('@#bookmarked').at('id', '')._map(function(x) {
  2408. ff.post_remove_icon(x, '.bookmark-icon');
  2409. });
  2410. p.id = 'bookmarked';
  2411. ff.post_add_icon(p, '★', '.bookmark-icon', {
  2412. style: 'color: yellow; text-shadow: 0 0 2px black',
  2413. title: '书签'
  2414. });
  2415. var bm = pref.all_bookmarks;
  2416. var title = bm_title();
  2417.  
  2418. if (! bm[title]) bm[title] = {};
  2419. bm[title].url = (ff.stupid_form ? location.href : ff.url_gen(p.info.page));
  2420. bm[title].page = p.info.page;
  2421. bm[title].post = p.info.idx;
  2422. bm[title].lz = ff.lz_list;
  2423.  
  2424. pref.all_bookmarks = bm;
  2425. update_bm_panel();
  2426. been_to_bookmark = true;
  2427. }
  2428. function remove_bookmark(title) {
  2429. var bm = pref.all_bookmarks;
  2430. delete bm[title];
  2431. pref.all_bookmarks = bm;
  2432. }
  2433. function bm_panel() {
  2434. var p = $('+div.flex#bm-list').e('click', ui.single_select);
  2435. update_bm_panel(p);
  2436. return p;
  2437. }
  2438. function update_bm_panel(p) {
  2439. if (!p) p = $('@#bm-list');
  2440. if (!p.length) return;
  2441. p.f('>').r();
  2442. var bm = pref.all_bookmarks;
  2443. var topics = [];
  2444. for (var title in bm) topics.push(title);
  2445. topics.sort();
  2446. var cur = bm_title();
  2447. topics._map(function(title) {
  2448. p.a($('+div.sel-item.bm-item' + (title == cur ? '#cur-bm' : ''),
  2449. title).a(bm_link(bm[title], title)));
  2450. })
  2451. }
  2452. function bm_link(x, title) {
  2453. return [$('+a', x.page + '-' + x.post, {href: x.url})
  2454. .e('click', function(e) { if (goto_bm(title, x.page, x.post)) ui.cancel_event(e) }, true),
  2455. $('+a', '删除').e('click', function(e) {
  2456. if (!ui.check_ctrl(e)) return;
  2457. var bm = pref.all_bookmarks;
  2458. delete bm[title];
  2459. pref.all_bookmarks = bm;
  2460. update_bm_panel();
  2461. })
  2462. ];
  2463. }
  2464. function goto_bm(title, page, post) {
  2465. console.log('goto bm(' + [title, page, post].join(', ') + ')');
  2466. if (title == bm_title()) { // same topic, just load sub page
  2467. if (!ff.pages[page]) {
  2468. ff.go_page(page);
  2469. return true;
  2470. }
  2471. var p = ff.pages[page].page.f('.post');
  2472. for (var i = 0; i < p.length; i++) {
  2473. if (p[i].info.idx == post) {
  2474. set_bookmark(p[i]);
  2475. ui.goto_item(p[i]);
  2476. break;
  2477. }
  2478. }
  2479. been_to_bookmark = true;
  2480. return true;
  2481. }
  2482. return false;
  2483. }
  2484. function check_load_bm() {
  2485. if (pref.auto_load_bookmark && !been_to_bookmark) {
  2486. var t = bm_title();
  2487. var bm = pref.all_bookmarks[t];
  2488. if (bm) {
  2489. var need_update = false;
  2490. if (bm.lz)
  2491. for (var a in bm.lz) {
  2492. if (! ff.lz_list[a]) {
  2493. need_update = true;
  2494. ff.lz_list[a] = bm.lz[a];
  2495. }
  2496. }
  2497. if (need_update)
  2498. ff.post_update_all();
  2499.  
  2500. goto_bm(t, bm.page, bm.post);
  2501. }
  2502. }
  2503. }
  2504. function bm_button() {
  2505. $('@#panel-btns').a(ui.panel_button({
  2506. tag: '#bm-panel',
  2507. icon: '★',
  2508. title: '书签',
  2509. func: bm_panel,
  2510. auto_del: 1
  2511. }));
  2512. }
  2513. // end bookmark stuff
  2514.  
  2515. // activate pref procs (and walk around stupidity of greasemonkey)
  2516.  
  2517. if (pref.use_one_page) {
  2518. (['use_one_page', 'auto_load_page', 'all_bookmarks']).forEach(function(x) { pref[x] = pref[x]; });
  2519. ff.add_opt_css('loader-progress', '#all-loaders { font-size: small; position: fixed; right: 1ex; top: 2em } .loader { text-align: left; padding: 4px; border: 1px solid transparent } .loader:hover{ background: white; border-color: gray } .progress-bar { border: 1px solid gray; height: 20px; width: 100px;background: rgba(128,128,128,.3) } .loader:not(:hover) .progress-ctrl { display: none; padding: .5ex 0 } .progress-ctrl > span.fr { padding-left: 1ex; cursor: pointer } .progress-progress { background: #cdf; border-right: 1px solid gray; height: 100%; display: inline-block; } .page-reload { color: #cfd } .page-kill { color: #faa } .page-disp { color: #ffa } .page-no > span { text-shadow: 0 0 1px black; padding-left: 1em; cursor: pointer } .page[hide] {/* for webkit */} .page[hide] > div.post, .page[hide] > div.post[show] { display: none } .page[hide] .page-disp { color: gray } #bm-panel {width: 20em; word-wrap: break-word} .bm-item { padding: 1ex; text-align: justify; border-bottom: 1px solid #aaa} #bm-panel-toggle {color: white; background-color: transparent; border:none;} #bm-panel-toggle:hover, #bm-panel-toggle[active] {color:#ffa; cursor:pointer;} .bm-item > a { padding: 0 1ex; text-decoration: underline; cursor:pointer} #cur-bm { background: #cfc }');
  2520. ff.pre_insert.push(add_page_control);
  2521. ff.post_insert.push(check_load_bm);
  2522. ff.more_ui.push(bm_button);
  2523. }
  2524.  
  2525. pref.decl('use_img_view', 'bool', false);
  2526. pref.use_img_view;
  2527. pref.decl('img_thumb_size', 'int', 160);
  2528. pref.img_thumb_size;
  2529.  
  2530. var nocontent = 0;
  2531. var img_seen = {};
  2532.  
  2533. function set_grid_btn(l) {
  2534. if (l) {
  2535. $('#img-grid-button').at({active: 1, title: '图片:' + l});
  2536. } else {
  2537. $('#img-grid-button').at({active: '', title: '图片:无'});
  2538. }
  2539. }
  2540.  
  2541. function thumb_load(e) {
  2542. var t = $(e.target);
  2543. var w = t[0].width, h = t[0].height;
  2544. t[0]._orig_w = w;
  2545. t[0]._orig_h = h;
  2546. var ts = pref.img_thumb_size;
  2547. t.at({style: 'max-width:' + ts + 'px; max-height:'+ts + 'px', 'class':'thumb',
  2548. title: w + ' × ' + h});
  2549. if ((w > ts || h > ts) && !img_seen[t[0].src]) {
  2550. img_seen[t[0].src] = 1;
  2551. t[0]._good = 1;
  2552. var a = t.f('<a');
  2553. a.at({href: t[0].src}).e('click', img_click, true);
  2554. set_grid_btn(good_imgs().length);
  2555. }
  2556. }
  2557.  
  2558. function schedule_thumbnail(x) {
  2559. var b;
  2560. var a = $('+div.img-frame').a(b = $('+a.img-thumb', '', { href: null }));
  2561. $(x).f('<').i(a, x);
  2562. var p = a[0].previousSibling;
  2563. var l;
  2564.  
  2565. if (p && $(p).f('=p:not(.sep)').length && ((l = p.textContent.length) < 240)) {
  2566. p.className = 'caption';
  2567. x._caption = p;
  2568. if (l > 64) {
  2569. [p, b[0]].at('style', 'display: inline-block; vertical-align: top');
  2570. [p].at('style', 'width:' + (l / 8) + 'em; margin-left: 1ex');
  2571. } else {
  2572. [p].at('style', 'margin-top: 1ex');
  2573. }
  2574. a.a(p);
  2575. }
  2576.  
  2577. b.a(x);
  2578.  
  2579. $(x).e('load', thumb_load);
  2580. x.src = x.src;
  2581. }
  2582.  
  2583. function replace_imgs(pg) {
  2584. pg.page.f('img')._map(schedule_thumbnail);
  2585. }
  2586.  
  2587.  
  2588. // img viewing stuff
  2589. function make_canvas(img) {
  2590. if (img._canvas) return img._canvas;
  2591. var c = $('+canvas');
  2592. var f = $('+a.img-frame', '', {href:img.src}).a(c);
  2593. img._canvas = f[0];
  2594.  
  2595. if (img._caption)
  2596. c.at('title', img._caption.textContent);
  2597. c[0]._img = img;
  2598.  
  2599. var s = pref.img_thumb_size;
  2600. var scale = s / img._orig_w;
  2601. if (scale * img._orig_h > s)
  2602. scale = s / img._orig_h;
  2603. var w = img._orig_w * scale, h = img._orig_h * scale;
  2604. c.at({height: h, width: w});
  2605.  
  2606. setTimeout(function() {c[0].getContext('2d').drawImage(img, 0, 0, w, h)}, 0);
  2607. return img._canvas;
  2608. }
  2609.  
  2610. function img_grid_click(e) {
  2611. var x = $(e.target);
  2612. if (x.f('=canvas').length) {
  2613. ui.cancel_event(e);
  2614. view_start([x[0]._img]);
  2615. }
  2616. else
  2617. img_grid_off();
  2618. }
  2619.  
  2620. function img_grid_on() {
  2621. if ($('#img-grid').length) return;
  2622. var l = good_imgs();
  2623. set_grid_btn(l.length);
  2624. if (!l.length) return;
  2625. hide_content(true);
  2626. var grid = $('+div#img-grid', '', {style: 'position: fixed; left: 0; right: 0; top: 0; bottom: 0; overflow-y: auto; background: #f8f8f8; text-align:center'})
  2627. .e('click', img_grid_click, true);
  2628. $('@body').a(grid);
  2629. grid.a(l._map(make_canvas));
  2630. }
  2631.  
  2632. function img_grid_off() {
  2633. $('@#img-grid').r();
  2634. hide_content(false);
  2635. }
  2636.  
  2637. function img_click(e) {
  2638. ui.cancel_event(e);
  2639. var t = [e.target].f('=a');
  2640. if (!t.length)
  2641. t = [e.target].f('<a');
  2642. view_start(t.f('>img'));
  2643. }
  2644.  
  2645. var content_scroll;
  2646. function hide_content(hide) {
  2647. if (hide)
  2648. nocontent ++;
  2649. else
  2650. nocontent --;
  2651. if (hide && (1 == nocontent)) {
  2652. content_scroll = document.documentElement.scrollTop;
  2653. $('@#content').at({style: 'display:none'});
  2654. } else if (!nocontent) {
  2655. $('@#content').at({style: 'display:'});
  2656. document.documentElement.scrollTop = content_scroll;
  2657. }
  2658. }
  2659.  
  2660. function view_start(im) {
  2661. if (!im.length) return;
  2662. var v = $('@#img-viewer');
  2663. if (!v.length) {
  2664. v = $('+div#img-viewer', '', {
  2665. style: 'position: fixed; top: 0; left: 0; bottom: 0; right: 0; background:#eee'
  2666. })
  2667. .e('click', view_click);
  2668. hide_content(true);
  2669. v.a($('+img#viewed', '',
  2670. {style: 'display: inline-block; max-height: 100%; max-width: 100%; position:fixed; top: 0; bottom: 0; left: 0; right: 0;margin: auto'}
  2671. ))
  2672. .a($('+div.img-desc'));
  2673. $('@body').a(v);
  2674. $(window)
  2675. .e('DOMMouseScroll', on_wheel, true)
  2676. .e('keydown', on_key, true);
  2677. }
  2678.  
  2679. v.f('.img-desc').txt(im[0]._caption ? im[0]._caption.textContent : '');
  2680. v.f('#viewed').at({src: im.at('src')});
  2681. }
  2682.  
  2683. function good_imgs() {
  2684. return $('@#content').f('img').grep(function(x) { return x._good });
  2685. }
  2686.  
  2687. function find_current_img(list) {
  2688. var im = $('@#viewed');
  2689. if (im.length)
  2690. for (var i = 0; i < list.length; i++)
  2691. if (list[i].src == im[0].src)
  2692. return i;
  2693. return null;
  2694. }
  2695.  
  2696. function next_img() {
  2697. var l = good_imgs();
  2698. var i = find_current_img(l);
  2699. if (i === null) return;
  2700. if (i < l.length)
  2701. view_start([l[i + 1]]);
  2702. }
  2703.  
  2704. function prev_img() {
  2705. var l = good_imgs();
  2706. var i = find_current_img(l);
  2707. if (i === null) return;
  2708. if (i > 0) view_start([l[i - 1]]);
  2709. }
  2710.  
  2711. function view_click(e) {
  2712. if (e.clientX < window.innerWidth * .2)
  2713. prev_img();
  2714. else if (e.clientX > window.innerWidth * .8)
  2715. next_img();
  2716. else
  2717. view_stop();
  2718. }
  2719.  
  2720. function on_wheel(e) {
  2721. ui.cancel_event(e);
  2722. if (e.detail < 0)
  2723. prev_img();
  2724. else
  2725. next_img();
  2726. }
  2727.  
  2728. function on_key(e) {
  2729. switch(e.which) {
  2730. case 37:
  2731. case 38:
  2732. ui.cancel_event(e);
  2733. prev_img();
  2734. break;
  2735. case 32:
  2736. case 39:
  2737. case 40:
  2738. ui.cancel_event(e);
  2739. next_img();
  2740. break;
  2741. case 27:
  2742. ui.cancel_event(e);
  2743. view_stop();
  2744. break;
  2745. }
  2746. }
  2747.  
  2748. function view_stop() {
  2749. $('@#img-viewer').r();
  2750. hide_content(false);
  2751. $(window)
  2752. .e('-DOMMouseScroll', on_wheel, true)
  2753. .e('-keydown', on_key, true);
  2754. }
  2755.  
  2756. function img_grid_button() {
  2757. ff.add_opt_css('img-css', '.img-thumb, .img-frame { display: inline-block; vertical-align: top} .img-thumb { vertical-align:middle; display: table-cell; text-align: center; overflow: hidden } .img-frame { font-size: small; margin-left: 15px; margin-right: -29px; margin-top: 20px; margin-bottom: 20px; padding: 13px; border: none; /*box-shadow: 0px 2px 4px #aaa;*/ background: transparent; border-radius:18px; } p.caption {line-height: normal; text-indent: 0; } .img-thumb { width:'+pref.img_thumb_size +'px; max-height:'+pref.img_thumb_size+'px} p.caption { width:'+pref.img_thumb_size+'px} #viewed {-moz-box-shadow: 4px 4px 8px black} #img-grid-button[active] { color: #ffa;} canvas { -moz-box-shadow: 2px 2px 5px black } #img-grid, #img-viewer { z-index: 200; padding: 1em } .img-desc { padding: 1ex; opacity: 0; background: black; color: white; position: fixed; bottom: 0; left: 0; right: 0; text-align: center} .img-desc:hover { opacity: .9}');
  2758. return $('@#toggle-btns').a(ui.toggle_button(
  2759. '#img-grid-button', '▦',
  2760. function(b, on) {
  2761. img_grid_on();
  2762. }, 0)
  2763. );
  2764. }
  2765.  
  2766. ff.prefs_hook.push(function() {
  2767. return ui.prefs_group('图片浏览', [
  2768. ui.check_box({
  2769. label: '启用图片浏览',
  2770. value: pref.use_img_view,
  2771. func: function(e) {
  2772. pref.use_img_view = e.target.checked ? 1 : 0;
  2773. },
  2774. block: 1
  2775. }),
  2776. ui.text_box({
  2777. tag: '#thumb-size',
  2778. before: '图标尺寸',
  2779. after: '像素',
  2780. value: pref.img_thumb_size,
  2781. size: 4,
  2782. func: function(e) {
  2783. var x = e.target;
  2784. if (! x.value.match(/^\d+$/)) {
  2785. x.value = pref.img_thumb_size;
  2786. return;
  2787. }
  2788. pref.img_thumb_size = x.value;
  2789. }
  2790. }),
  2791. ]);
  2792. });
  2793.  
  2794. if (pref.use_img_view) {
  2795. ff.more_ui.push(img_grid_button);
  2796. ff.pre_insert.push(replace_imgs);
  2797. }
  2798. var in_editing = false;
  2799. var filter_func = null;
  2800.  
  2801. var re_matcher = /["'\[\]\{\}\\.*+?\-^$():\/]/;
  2802. var author_tags, tagged, re_names = {};
  2803.  
  2804. pref.decl('post_filter_rules', 'obj', []);
  2805. pref.post_filter_rules;
  2806. pref.decl('author_tags', 'obj', {});
  2807. pref.author_tags;
  2808.  
  2809. ff.add_opt_css('filter-css', '#filter-panel { min-width: 12em } #r-editor { display: inline-block; position: fixed; bottom: 2em; right: 2em; z-index: 199; margin: auto; padding: 1ex; background: #607d8b; text-align: left; color:white; border-radius:18px; -webkit-shadow-box:1px 1px 1px #aaa; font-size:13px;} .r-item { min-width: 30em; } .r-section { padding-bottom: 1ex; margin-bottom: 1ex; border-bottom: 1px solid #aaa} .r-del { color: #faa;margin-right: 1em } [bad_input] { outline: 2px solid #faa } #tags-editor {display: table-row } .tag-half { display: table-cell; width: 15em; padding: 2px } .tag-list { width: 100%; height: 20em; border: 1px solid gray} #tag-new { width: 14em } .filter-rule[na] { color: gray } #tag-names, #tag-tags { overflow: auto }');
  2810.  
  2811. function load_tags() {
  2812. var tags = pref.author_tags;
  2813. author_tags = {};
  2814. tagged = {};
  2815.  
  2816. for (var x in tags) {
  2817. for (var n in tags[x]) {
  2818. if (n.match(re_matcher)) {
  2819. if (!re_names[n])
  2820. re_names[n] = {'_pat': new RegExp(n) }
  2821. re_names[n][x] = 1;
  2822. } else {
  2823. if (!author_tags[n]) author_tags[n] = {};
  2824. author_tags[n][x] = 1;
  2825. }
  2826. }
  2827. }
  2828. }
  2829.  
  2830. load_tags();
  2831.  
  2832. function author_tag_match(a, t) {
  2833. if (tagged[a]) {
  2834. return author_tags[a][t];
  2835. }
  2836. if (!author_tags[a]) author_tags[a] = {};
  2837. for (var r in re_names) {
  2838. if (!a.match(re_names[r]._pat))
  2839. continue;
  2840.  
  2841. for (var x in re_names[r]) {
  2842. if (x == '_pat') continue;
  2843. author_tags[a][x] = 1;
  2844. }
  2845. }
  2846. tagged[a] = 1;
  2847. return author_tags[a][t] ? true : false;
  2848. }
  2849.  
  2850. function rules_filter(pg) {
  2851. compile_all_rules();
  2852. if (!filter_func) return;
  2853. pg.page.f('>.post')._map(function(x) {
  2854. filter_func(x, author_tag_match);
  2855. });
  2856. }
  2857.  
  2858. function empty_rule() {
  2859. return {
  2860. name:'新...',
  2861. board:[],
  2862. post:[],
  2863. use:1,
  2864. stop: 0,
  2865. hl: 0,
  2866. disp: 0,
  2867. use: 1,
  2868. };
  2869. }
  2870.  
  2871. function rules_panel() {
  2872. var r = pref.post_filter_rules;
  2873. return [
  2874. $('+div.flex#rules-list')
  2875. .a(r._map(rule_list_item))
  2876. .e('click', ui.single_select),
  2877. $('+div').a([
  2878. ui.text_button('', '新规则', function(e) {
  2879. if (in_editing) return;
  2880. in_editing = true;
  2881. var nitem = rule_list_item(empty_rule());
  2882. nitem[0]._new = 1;
  2883. $('#rules-list').a(nitem);
  2884. rules_editor(nitem);
  2885. }),
  2886. ui.text_button('', '编辑', function(e) {
  2887. if (in_editing) return;
  2888. var x = $('#rules-list').f('[selected]');
  2889. if (!x.length) return;
  2890. rules_editor(x);
  2891. in_editing = true;
  2892. }),
  2893. ui.text_button('', '删除', function(e) {
  2894. if (!ui.check_ctrl(e)) return;
  2895. $('#rules-list').f('[selected]').r();
  2896. save_ui_rules();
  2897. }, {style:'color: #faa'}),
  2898. ui.text_button('', '▲', move_up),
  2899. ui.text_button('', '▼', move_down),
  2900. ui.text_button('', '♻', refilter,
  2901. {title: '从新过滤', style:'color: #cfd'}),
  2902.  
  2903. ui.text_button('', '标签', function() {tags_editor() }),
  2904. ]),
  2905. ];
  2906. }
  2907.  
  2908. function save_ui_rules() {
  2909. pref.post_filter_rules = $('#rules-list').f('>.filter-rule')._map('=$_._rule');
  2910. compile_all_rules();
  2911. }
  2912.  
  2913. function refilter() {
  2914. if (!filter_func) return;
  2915. $('.post')._map(function(x) {
  2916. x.info.hl = x.info.show = 0;
  2917. filter_func(x, author_tag_match);
  2918. ff.post_set_state(x);
  2919. })
  2920. }
  2921.  
  2922. function move_up() {
  2923. if (in_editing) return;
  2924. var sel = $('#rules-list').f('[selected]');
  2925. if (!sel.length) return;
  2926. var up = sel[0].previousSibling;
  2927. if (!up) return;
  2928. sel.f('<').i(sel, up);
  2929. save_ui_rules();
  2930. }
  2931.  
  2932. function move_down() {
  2933. if (in_editing) return;
  2934. var sel = $('#rules-list').f('[selected]');
  2935. if (!sel.length) return;
  2936. var down = sel[0].nextSibling;
  2937. if (!down) return;
  2938. sel.f('<').i(down, sel);
  2939. save_ui_rules();
  2940. }
  2941.  
  2942. function rule_list_item(r) {
  2943. var item = $('+div.sel-item.filter-rule')
  2944. .a($('+input[type=checkbox]')
  2945. .at('checked', r.use == 1? 1 : '')
  2946. .e('click', toggle_use)
  2947. ).a($('+text', r.name));
  2948. item[0]._rule = r;
  2949. if (!rule_applicable(r))
  2950. item.at('na', 1);
  2951. return item;
  2952. }
  2953.  
  2954. function toggle_use(e) {
  2955. var t = $(e.target);
  2956. var r = t.f('<.filter-rule');
  2957. r[0]._rule.use = e.target.checked ? 1 : 0;
  2958. save_ui_rules();
  2959. }
  2960.  
  2961. function filter_ui() {
  2962. $('@#panel-btns').a(ui.panel_button({
  2963. tag: '#filter-panel',
  2964. icon: '♙',
  2965. title: '选帖规则',
  2966. func: rules_panel,
  2967. auto_del: 1,
  2968. }));
  2969.  
  2970. ff.author_menus.push({
  2971. icon: '★',
  2972. icon_attr: {style: 'color: orange; text-shadow: 0 0 1px black'},
  2973. label: '标签...',
  2974. func: function(e) {
  2975. var p = ff.get_menu_post(e);
  2976. tags_editor(p.info.author);
  2977. }
  2978. });
  2979. }
  2980.  
  2981. function make_match_statement(a, op, b) {
  2982. var x = a + '.match(' + (new RegExp(b)) + ')';
  2983. if (op == '=~')
  2984. return x;
  2985. return '!' + x;
  2986. }
  2987.  
  2988. function compile_all_rules() {
  2989. var rs = pref.post_filter_rules.grep(rule_applicable).grep('=$_.use');
  2990. var code = [], txt = false;
  2991. for (var i = 0; i < rs.length; i++) {
  2992. var r = compile_rule(rs[i]);
  2993. if (r[1])
  2994. txt = true;
  2995. code.push(r[0]);
  2996. }
  2997. if (txt)
  2998. code.unshift('var t = p.lastChild.textContent;');
  2999.  
  3000. filter_func = new Function('p, tag_match', code.join('\n'));
  3001. }
  3002.  
  3003. function compile_rule(r) {
  3004. var conds = ['if (true'];
  3005. var req_txt = false;
  3006. var s;
  3007. for (var i = 0; i < r.post.length; i++) {
  3008. var x = r.post[i];
  3009.  
  3010. switch(x.arg) {
  3011. case 'author':
  3012. switch (x.op) {
  3013. case 'lz': s = 'p.info.lz == 1'; break;
  3014. case 'notlz': s = 'p.info.lz != 1'; break;
  3015. case '=~':
  3016. case '!~': s = make_match_statement('p.info.author', x.op, x.regex);
  3017. break;
  3018. case '==': s = 'p.info.author == ' + JSON.stringify(x.str);
  3019. break;
  3020. default: s = '';
  3021. continue;
  3022. }
  3023. break;
  3024. case 'author_tag':
  3025. s = 'tag_match(p.info.author, ' + JSON.stringify(x.tag) + ')';
  3026. if (x.op == '!~')
  3027. s = '!' + s;
  3028. break;
  3029. case 'post_length':
  3030. s = 'p.info.len ' + x.op + x.num;
  3031. break;
  3032. case 'images':
  3033. s = 'p.info.imgs ';
  3034. switch(x.op) {
  3035. case 'zero': s += '== 0'; break;
  3036. case 'notzero': s += '!= 0'; break;
  3037. default:
  3038. s = '';
  3039. break;
  3040. }
  3041. break;
  3042. case 'post_content':
  3043. req_txt = true;
  3044. s = make_match_statement('t', x.op, x.regex);
  3045. break;
  3046. }
  3047.  
  3048. if (s) conds.push('(' + s + ')');
  3049. }
  3050.  
  3051. var oper = [];
  3052. var done = false;
  3053.  
  3054. makeops: do {
  3055. switch(r.disp - 0) {
  3056. case 1:
  3057. case 2: oper.push('p.info.show = ' + r.disp + ';'); break;
  3058. case 3:
  3059. oper.push('p.info.del = 1; return;');
  3060. break makeops;
  3061. }
  3062.  
  3063. switch (r.hl - 0) {
  3064. case 1:
  3065. case 2: oper.push('p.info.hl = ' + r.hl + ';'); break;
  3066. }
  3067.  
  3068. if (r.stop == 1) {
  3069. oper.push('return;');
  3070. }
  3071. } while (0);
  3072.  
  3073. return [conds.join('&&') + ') {' + oper.join('') + '}', req_txt];
  3074. }
  3075.  
  3076. function tags_editor(name) {
  3077. if (in_editing) return;
  3078. in_editing = true;
  3079.  
  3080. var tags = JSON.parse(JSON.stringify(pref.author_tags));
  3081. var authors = {};
  3082. for (var x in tags) {
  3083. for (var i in tags[x])
  3084. authors[i] = 1;
  3085. }
  3086. var new_item = false;
  3087. var pname, ptag;
  3088.  
  3089. function tags_editor_content() {
  3090. return [
  3091. $('+div.tag-half').a([
  3092. $('+div', '人名').a([
  3093. $('+button', '+').e('click', new_name),
  3094. $('+button', '✗', {style:'color:#faa'}).e('click', del_name)
  3095. ]),
  3096. pname = $('+div#tag-names.tag-list').a(
  3097. keys(authors)._map(tag_list_item)
  3098. ).e('click', name_click, true)
  3099. ]),
  3100. $('+div.tag-half').a([
  3101. $('+div', '标签').a([
  3102. $('+button', '+').e('click', new_tag),
  3103. $('+button', '✗', {style: 'color:#faa'}).e('click', del_tag)
  3104. ]),
  3105. ptag = $('+div#tag-tags.tag-list').a(
  3106. keys(tags)._map(tag_list_item)
  3107. ).e('click', tag_click, true)
  3108. ]),
  3109. ];
  3110. }
  3111.  
  3112. function sel_name(a) {
  3113. var n = pname.f('.tag-item');
  3114. var s = null;
  3115. for (var i = 0; i < n.length; i++)
  3116. if (n[i].textContent == a) {
  3117. s = $(n[i]);
  3118. break;
  3119. }
  3120. if (!s) {
  3121. s = tag_list_item(a);
  3122. pname.a(s);
  3123. }
  3124. ui.single_select({target:s[0]});
  3125. pname.f('input[type="checkbox"]').at('style', 'visibility:hidden');
  3126. ptag.f('input[type="checkbox"]').at('style', 'visibility:');
  3127. ptag.f('>.sel-item')._map(function(x) {
  3128. $(x).at('selected', '')
  3129. $(x).f('input[type="checkbox"]')[0].checked
  3130. = tags[x.textContent][a] ? true: false;
  3131. })
  3132. }
  3133.  
  3134. function sel_tag(a) {
  3135. var n = ptag.f('.tag-item');
  3136. var s = null;
  3137. for (var i = 0; i < n.length; i++)
  3138. if (n[i].textContent == a) {
  3139. s = $(n[i]);
  3140. break;
  3141. }
  3142. if (!s) {
  3143. s = tag_list_item(a);
  3144. tags[a] = {};
  3145. ptag.a(s);
  3146. }
  3147.  
  3148. ui.single_select({target:s[0]});
  3149.  
  3150. ptag.f('input[type="checkbox"]').at('style', 'visibility:hidden');
  3151. pname.f('input[type="checkbox"]').at('style', 'visibility:');
  3152. pname.f('>.sel-item')._map(function(x) {
  3153. $(x).at('selected', '');
  3154. $(x).f('input[type="checkbox"]')[0].checked = tags[a][x.textContent] ? true: false;
  3155. })
  3156. }
  3157.  
  3158. function del_name(e) {
  3159. if (!ui.check_ctrl(e)) return;
  3160.  
  3161. var a = pname.f('.sel-item[selected]');
  3162. if (!a.length) return;
  3163. var t = a[0].textContent;
  3164. for (var x in tags)
  3165. delete tags[x][t];
  3166. a.r();
  3167. }
  3168.  
  3169. function del_tag(e){
  3170. if (!ui.check_ctrl(e)) return;
  3171.  
  3172. var a = ptag.f('.sel-item[selected]');
  3173. if (!a.length) return;
  3174. var t = a[0].textContent;
  3175. delete tags[t];
  3176. a.r();
  3177. }
  3178.  
  3179. function name_click(e) {
  3180. var t = $(e.target);
  3181. var ch = t.f('=input')[0];
  3182. if (ch) {
  3183. t = t.f('<.sel-item')[0].textContent;
  3184. var l = ptag.f('[selected]');
  3185. if (!l.length) return;
  3186. l = l[0].textContent;
  3187.  
  3188. if (!ch.checked)
  3189. delete tags[l][t];
  3190. else
  3191. tags[l][t] = 1;
  3192. } else {
  3193. t = t.f('=.sel-item')[0];
  3194. if (t) sel_name(t.textContent);
  3195. }
  3196. }
  3197.  
  3198. function tag_click(e) {
  3199. var t = $(e.target);
  3200. var ch = t.f('=input')[0];
  3201. if (ch) {
  3202. t = t.f('<.sel-item')[0].textContent;
  3203. var l = pname.f('[selected]');
  3204. if (!l.length) return;
  3205. l = l[0].textContent;
  3206.  
  3207. if (!ch.checked)
  3208. delete tags[t][l];
  3209. else
  3210. tags[t][l] = 1;
  3211. } else {
  3212. t = t.f('=.sel-item')[0];
  3213. if (t) sel_tag(t.textContent);
  3214. }
  3215. }
  3216.  
  3217. function new_name() {
  3218. if (new_item) return;
  3219. new_item = true;
  3220. pname.a($('+input[type=text]#tag-new').e('change', function(e) {
  3221. var v = e.target.value;
  3222. if (v.match(re_matcher)) {
  3223. try { new RegExp(v) } catch (ee) {
  3224. ui.goto_item(e.target);
  3225. throw new Error('bad regexp');
  3226. }
  3227. }
  3228. $(e.target).r();
  3229. sel_name(e.target.value);
  3230. new_item = false;
  3231. }));
  3232. $('#tag-new')[0].focus();
  3233. }
  3234.  
  3235. function new_tag() {
  3236. if (new_item) return;
  3237. new_item = true;
  3238. ptag.a($('+input[type=text]#tag-new').e('change', function(e) {
  3239. $(e.target).r();
  3240. sel_tag(e.target.value);
  3241. new_item = false;
  3242. }));
  3243. $('#tag-new')[0].focus();
  3244. }
  3245.  
  3246. function tag_list_item(a) {
  3247. return $('+div.tag-item.sel-item').a([
  3248. $('+input[type=checkbox]'),
  3249. $('+text', a)
  3250. ]);
  3251. }
  3252.  
  3253. function save_tags() {
  3254. pref.author_tags = tags;
  3255. load_tags();
  3256. }
  3257.  
  3258. for (var t in tags) {
  3259. for (var i in tags[t]) {
  3260. if (! authors[i]) authors[i] = {};
  3261. authors[i][t] = 1;
  3262. }
  3263. }
  3264.  
  3265. ui.popup_window({
  3266. title: '标签',
  3267. tag: '#tags-editor',
  3268. attr: {style: 'position: fixed; right: 2em; bottom: 2em; z-index: 200; text-align: left; font-size: small'},
  3269. func: tags_editor_content,
  3270. perm: true,
  3271. }, null).f('.panel-close').e('click', function() {
  3272. save_tags();
  3273. in_editing = false;
  3274. });
  3275. if (name) sel_name(name);
  3276. }
  3277.  
  3278. function rule_applicable(r) {
  3279. if (!r.board.length) return true;
  3280. var t = ff.title;
  3281. var b = ff.board_links.item(-1)[0].textContent;
  3282. for (var i = 0; i < r.board.length; i++) {
  3283. var x = r.board[i];
  3284. switch(x.arg) {
  3285. case 'name':
  3286. switch(x.op) {
  3287. case '==':
  3288. if (b == x.str || t == x.str) return true;
  3289. break;
  3290. case '=~':
  3291. var re = new RegExp(x.regex);
  3292. if (b.match(re) || t.match(re)) return true;
  3293. break;
  3294. }
  3295. break;
  3296. case 'url':
  3297. switch (x.op) {
  3298. case 'idx':
  3299. if (location.href.indexOf(x.str) == 0)
  3300. return true;
  3301. break;
  3302. case '=~':
  3303. var re = new RegExp(x.regex);
  3304. if (location.href.match(re)) return true;
  3305. }
  3306. }
  3307. }
  3308. return false;
  3309. }
  3310.  
  3311. function save_all_rules() {
  3312. pref.post_filter_rules = $('.filter-rule')._map("=$_._rule");
  3313. compile_all_rules();
  3314. }
  3315.  
  3316. function rules_editor(ritem) {
  3317. var rs = ritem[0]._rule;
  3318. var tmpl_board =
  3319. { type: 'select', name: 'arg', kids: [
  3320. { text: '版面名称', value: 'name', onsel:
  3321. { type: 'select', name: 'op', kids:
  3322. [
  3323. { text: '==', onsel:
  3324. { type: 'text', value: '%n', name: 'str' },
  3325. },
  3326. { text: '=~', onsel:
  3327. { type: 'text', name: 'regex' }
  3328. }
  3329. ],
  3330. },
  3331. },
  3332. { text: '地址', value: 'url', onsel:
  3333. { type: 'select', name: 'op', kids:
  3334. [
  3335. { text: '==', value: 'idx', onsel:
  3336. { type: 'text', name: 'str', value: '%u', },
  3337. },
  3338. { text: '=~', onsel:
  3339. { type: 'text', name: 'regex', },
  3340. }
  3341. ]
  3342. },
  3343. },
  3344. ]};
  3345.  
  3346. var tmpl_post =
  3347. { type: 'select', name: 'arg', kids: [
  3348. { text: '作者', value: 'author', onsel:
  3349. { type: 'select', name: 'op', kids: [
  3350. { text: '是楼主', value: 'lz' },
  3351. { text: '非楼主', value: 'notlz' },
  3352. { text: '=', value: '==', onsel:
  3353. { type: 'text', name: 'str' }
  3354. },
  3355. { text: '≠', value: '!=', onsel:
  3356. { type: 'text', name: 'str' }
  3357. },
  3358. { text: '=~', onsel:
  3359. { type: 'text', name: 'regex' }
  3360. },
  3361. { text: '!~', onsel:
  3362. { type: 'text', name: 'regex' }
  3363. },
  3364. ]},
  3365. },
  3366. { text: '作者标签', value: 'author_tag', onsel:
  3367. { type: 'select', name: 'op', kids: [
  3368. { text: '=', value: '==', onsel:
  3369. { type: 'select', name: 'tag', choices: '%tag' }
  3370. },
  3371. { text: '≠', value:'!=', onsel:
  3372. { type: 'select', name: 'tag', choices: '%tag' }
  3373. },
  3374. ]}
  3375. },
  3376. { text: '帖子长度', value: 'post_length', onsel:
  3377. { type: 'select', name: 'op', kids: [
  3378. { text: '≥', value:'>=', onsel:
  3379. { type: 'text', name: 'num' }
  3380. },
  3381. { text: '<', value: '<', onsel:
  3382. { type: 'text', name: 'num' }
  3383. },
  3384. ]}
  3385. },
  3386. { text: '帖子文字', value: 'post_content', onsel:
  3387. { type: 'select', name: 'op', kids: [
  3388. { text: '=~', onsel: { type: 'text', name: 'regex' }},
  3389. { text: '!~', onsel: { type: 'text', name: 'regex' }},
  3390. ]}
  3391. },
  3392. { text: '图片', value: 'images', onsel:
  3393. { type: 'select', name: 'op', kids: [
  3394. { text: '有', value: 'notzero'},
  3395. { text: '无', value: 'zero'},
  3396. ]}
  3397. },
  3398. ]
  3399. };
  3400.  
  3401. var disp_op =
  3402. { type: 'select', name: 'disp', kids: [
  3403. { text: '不变', value: 0 },
  3404. { text: '显示', value: 1 },
  3405. { text: '隐藏', value: 2 },
  3406. { text: '删除', value: 3 },
  3407. ]};
  3408. var hl_op =
  3409. { type: 'select', name: 'hl', kids: [
  3410. { text: '不变', value: 0 },
  3411. { text: '高亮', value: 1 },
  3412. { text: '正常', value: 2 },
  3413. ]};
  3414.  
  3415. function cancel_rule() {
  3416. $('#r-editor').r();
  3417. if (ritem[0]._new)
  3418. ritem.r();
  3419. in_editing = false;
  3420. }
  3421.  
  3422. function save_rule() {
  3423. $('#r-ops').at('bad_input', '');
  3424. $('#r-editor').f('input, select').at('bad_input', '');
  3425. try {
  3426. var ret = ui_to_rule($('#r-ops')[0]);
  3427. ret.name = $('#r-rule-name')[0].value;
  3428. if (!ret.name) ret.name = '新...';
  3429. // no-no-op check
  3430. if ((0 == ret.hl) && (0 == ret.disp) && (0 == ret.stop)) {
  3431. $('#r-ops').at('bad_input', 1);
  3432. throw new Error('至少选择一项');
  3433. }
  3434.  
  3435. ret.board = $('#r-board').f('.rule')._map(ui_to_rule);
  3436. ret.post = $('#r-post').f('.rule')._map(ui_to_rule);
  3437. ret.use = (rs.use == 1 ? rs.use : 0);
  3438.  
  3439. ritem.f('<').i(rule_list_item(ret), ritem);
  3440. ritem.r();
  3441. cancel_rule();
  3442. save_all_rules();
  3443. } catch(e) {
  3444. ui.info_box(e.message, {style:'background:#faa; color: white; border:none; border-radius:15px; -webkit-box-shadow:1px 1px 1px #aaa;'});
  3445. throw e;
  3446. }}
  3447.  
  3448. function ui_from_tmpl(t) {
  3449. var ele;
  3450. switch(t.type) {
  3451. case 'select':
  3452. ele = $('+select');
  3453. ele.e('change', function() {select_select(ele)});
  3454. if (t.name) ele[0]._name = t.name;
  3455. if (t.kids)
  3456. ele.a(t.kids._map(ui_from_tmpl));
  3457. else if (t.choices == '%tag') {
  3458. var tags = pref.author_tags;
  3459. for (var x in tags) {
  3460. ele.a($('+option', x));
  3461. }
  3462. }
  3463. break;
  3464. case 'text':
  3465. ele = $('+input[type=text][size=30]');
  3466. if (t.name) ele[0]._name = t.name;
  3467. switch (t.value) {
  3468. case '%n':
  3469. ele[0].value = ff.board_links.item(-1).txt();
  3470. break;
  3471. case '%u':
  3472. ele[0].value = location.href;
  3473. break;
  3474. default:
  3475. ele[0].value = t.value ? t.value : '';
  3476. }
  3477. break;
  3478. default:
  3479. ele = $('+option', t.text);
  3480. if (t.value != undefined) ele[0].value = t.value;
  3481. if (t.onsel)
  3482. ele[0]._onsel = $('+span').a(ui_from_tmpl(t.onsel));
  3483. }
  3484. return ele;
  3485. }
  3486. function validate_text(x) {
  3487. var bad = false;
  3488. switch(x._name) {
  3489. case 'num':
  3490. if (!x.value.match(/^[1-9]\d*$/))
  3491. bad = true;
  3492. break;
  3493. case 'str':
  3494. if (! x.value.length) bad = true;
  3495. break;
  3496. case 'regex':
  3497. if (! x.value.length) bad = true;
  3498. else {
  3499. try {
  3500. var a = new RegExp(x.value);
  3501. } catch(e) {
  3502. bad = true;
  3503. }
  3504. }
  3505. }
  3506. if (bad){
  3507. [x].at('bad_input', 1);
  3508. return false;
  3509. }
  3510. return true;
  3511. }
  3512. function ui_to_rule(r) {
  3513. var ret = {};
  3514. [r].f('input[type="text"], select, input[type="checkbox"]')._map(function(x) {
  3515. if (x.type == 'text' && !validate_text(x))
  3516. throw new Error('输入错误');
  3517. if (x._value !== undefined)
  3518. ret[x._name] = x._value;
  3519. else
  3520. ret[x._name] = x.value;
  3521. });
  3522. return ret;
  3523. }
  3524. function del_button() {
  3525. return $('+button.r-del', '−', {title: '删除'}).e('click', function(e) { $(e.target).f('<.r-item').r()});
  3526. }
  3527. function rule_to_ui(tmpl, r) {
  3528. if (!r) r = {};
  3529. var x = $('+div.r-item.rule').a([del_button(), ui_from_tmpl(tmpl, r)]);
  3530. var sel = x.f('select');
  3531. if (sel.length)
  3532. select_select(sel, r);
  3533. return x;
  3534. }
  3535. function select_select(s, r) {
  3536. if (!s.length) return;
  3537.  
  3538. var i = 0, v = r ? r[s[0]._name] : null;
  3539. var opts = s.f('>option');
  3540. if (!v)
  3541. i = s[0].selectedIndex;
  3542. else {
  3543. for (i = 0; i < opts.length; i++) {
  3544. if (opts[i].value == v || opts[i].textContent == v)
  3545. break;
  3546. }
  3547. if (i == opts.length) i = 0;
  3548. }
  3549.  
  3550. [s[0].nextSibling].r();
  3551. s[0].selectedIndex = i;
  3552.  
  3553. if (opts[i] && opts[i]._onsel) {
  3554. s.f('<').a(opts[i]._onsel);
  3555. opts[i]._onsel.f('input[type="text"]')._map(function(x) {
  3556. if (r && (x._name in r))
  3557. x.value = r[x._name];
  3558. });
  3559. select_select(opts[i]._onsel.f('select'), r);
  3560. }
  3561. }
  3562.  
  3563. var n;
  3564. var ed = $('+div#r-editor').a(
  3565. $('+div', '规则名称:').a([
  3566. n = $('+input[type=text][size=12]#r-rule-name'),
  3567. $('+button', '取消', {style: 'float:right'})
  3568. .e('click', cancel_rule),
  3569. $('+button', '完成编辑', {style: 'float:right'})
  3570. .e('click', save_rule)
  3571. ])
  3572. );
  3573. n[0].value = rs.name;
  3574.  
  3575. var board_rules = $('+fieldset#r-board', '在符合以下任一条件的版面:').a([
  3576. ((rs && rs.board) ? rs.board : [])._map(function(x) {
  3577. return rule_to_ui(tmpl_board, x)}),
  3578. $('+div.r-item').a($('+button', '+').e('click', function(e) {
  3579. var x = rule_to_ui(tmpl_board);
  3580. var b = $(e.target).f('<');
  3581. b.f('<').a(x).a(b);
  3582. }))
  3583. ]);
  3584. var post_rules = $('+fieldset#r-post', '对满足以下所有条件的帖子:').a([
  3585. ((rs && rs.post) ? rs.post : [])._map(function(x) {
  3586. return rule_to_ui(tmpl_post, x)}),
  3587. $('+div.r-item').a($('+button', '+').e('click', function(e) {
  3588. var x = rule_to_ui(tmpl_post);
  3589. var b = $(e.target).f('<');
  3590. b.f('<').a(x).a(b);
  3591. }))
  3592. ]);
  3593.  
  3594. var ops = $('+fieldset#r-ops.r-section.rule', '釆取操作:').a([
  3595. $('+label', '显示'),
  3596. $('+span').a(rule_to_ui(disp_op, rs).f('select')),
  3597. $('+label', ' 高亮'),
  3598. $('+span').a(rule_to_ui(hl_op, rs).f('select')),
  3599. ui.check_box({
  3600. label: '终止过滤',
  3601. value: rs.stop,
  3602. func: function(e) {
  3603. $(e.target)[0]._value = (e.target.checked ? 1 : 0);
  3604. },
  3605. }).at({title: '满足以上条件的帖子不再用后继规则筛选'}),
  3606. ]);
  3607.  
  3608. var c = ops.f('input[type="checkbox"]')[0];
  3609. c._name = 'stop';
  3610. c._value = rs.stop;
  3611.  
  3612. $('@body').a(ed.a([board_rules, post_rules, ops]));
  3613. }
  3614.  
  3615. ff.more_ui.push(filter_ui);
  3616. ff.pre_insert.push(rules_filter);
  3617.  
  3618. function start_all() {
  3619. ff_startup();
  3620.  
  3621. var pg = ff.get_current_page();
  3622.  
  3623. $('@body')[0].innerHTML = '';
  3624.  
  3625. ff.add_page(pg);
  3626.  
  3627. $('@head')[0].innerHTML = '<title>'+ff.title+'</title>';
  3628. css_black = ("<r>body { background-color: #222}\
  3629. #stats, .page-no { color: #eee }\
  3630. h1 { color: #bdb }\
  3631. .post-body { color: #eee; background-color: #333}\
  3632. .post-head { background: #444; color: #ccc}\
  3633. .post-body, .post-head { border-color: #555}\
  3634. .post[hl] .post-head {\
  3635. background: #543\
  3636. -moz-linear-gradient(top, rgba(255,255,255,.15), transparent);\
  3637. color: white\
  3638. }\
  3639. .post[hl] .post-body { background-color: #234; color: white }\
  3640. .post[hl] .post-head, .post[hl] .post-body { border-color: #456; }\
  3641. .post a { color: #aff }\
  3642. .post a:visited { color: #faf }\
  3643. .post a:hover { color: #ffa }\
  3644. p.sep {\
  3645. border-bottom: 1px solid gray;\
  3646. }\
  3647. .lz-icon { color: pink }\
  3648. .lz-equiv { color: cyan }\
  3649. </r>");
  3650. $('@head').a($('#black-css'));
  3651.  
  3652. new_header('style.forum-filter#base-css', '');
  3653. new_header('style.forum-filter#opt-css', '');
  3654.  
  3655. $('#base-css').txt("<r>body {\
  3656. background: #d8d8d8;\
  3657. }\
  3658. .page {\
  3659. text-align: justify;\
  3660. margin-top: 1em;\
  3661. font-family:微软雅黑;\
  3662. line-height:4ex;\
  3663. font-style:normal;\
  3664. }\
  3665. #content {\
  3666. width: 100%;\
  3667. margin: 3em auto;\
  3668. }\
  3669. h1 {\
  3670. border-bottom: 1px solid #eee;\
  3671. color:#5f5f5f;\
  3672. font-size: 150%;\
  3673. margin: 1em auto;\
  3674. padding: 1em;\
  3675. font-family:微软雅黑;\
  3676. font-style:normal;\
  3677. }\
  3678. \
  3679. h1, #stats {\
  3680. text-align: center;\
  3681. font-family:微软雅黑;\
  3682. font-style:normal;\
  3683. }\
  3684. \
  3685. p {\
  3686. word-wrap: break-word;\
  3687. text-align: justify;\
  3688. text-indent: 2em;\
  3689. line-height:4ex;\
  3690. font-family:微软雅黑;\
  3691. padding:3px;\
  3692. }\
  3693. hr { margin: 1em 2em; border: none; border-bottom: 1px solid gray }\
  3694. p.sep > span { display: none }\
  3695. p.gap:not(:last-child) {\
  3696. margin-bottom: 1em;\
  3697. }\
  3698. .post-head, #main-tools, .panel-head, .text-button {\
  3699. background-color: #607D8B;\
  3700. color: white;\
  3701. border:none;\
  3702. font-family:微软雅黑;\
  3703. }\
  3704. .panel-head {\
  3705. background-color: #607d8b;\
  3706. padding: 7px 1ex;\
  3707. border:none;\
  3708. border-radius:18px;\
  3709. -webkit-box-shadow:1px 1px 1px #aaa;\
  3710. margin-bottom:3px;\
  3711. font-family:微软雅黑;\
  3712. }\
  3713. .post-head {\
  3714. -moz-border-radius-topleft: 4px;\
  3715. -moz-border-radius-topright: 4px;\
  3716. font-size: small;\
  3717. }\
  3718. .fr {\
  3719. float: right;\
  3720. }\
  3721. .post {\
  3722. margin-bottom: 4ex;\
  3723. }\
  3724. .post-body {\
  3725. color: #5f5f5f;\
  3726. font-family:微软雅黑;\
  3727. font-style:normal;\
  3728. border-bottom:1px solid #eee;\
  3729. margin-top:3ex;\
  3730. margin-bottom:5ex;\
  3731. padding-bottom:10ex;\
  3732. }\
  3733. .post-idx, a.author, .timestamp {\
  3734. text-align: center;\
  3735. display: inline-block;\
  3736. padding: .2ex 1ex;\
  3737. margin: .2ex 0;\
  3738. }\
  3739. .post-idx {\
  3740. border-right: 2px groove rgba(0,0,0,0.3)\
  3741. }\
  3742. a {\
  3743. text-decoration: none;\
  3744. }\
  3745. a:hover {\
  3746. color: #faa;\
  3747. }\
  3748. #page-links {\
  3749. cursor: pointer;\
  3750. color:#4093be;\
  3751. }\
  3752. #page-links > *,\
  3753. a.board {\
  3754. display: inline-block;\
  3755. font-size: small;\
  3756. padding: .2ex 1ex;\
  3757. border:none;\
  3758. padding-bottom:10px;\
  3759. padding-top:10px;\
  3760. color:white;\
  3761. font-family:微软雅黑;\
  3762. }\
  3763. #bar-wrapper {\
  3764. position: fixed;\
  3765. left: 0; right: 0;\
  3766. text-align: left;\
  3767. z-index: 100;\
  3768. font-family:微软雅黑;\
  3769. }\
  3770. #bar-wrapper:not([on_top]){ bottom: 0; }\
  3771. #bar-wrapper[on_top] { top: 0; }\
  3772. #bar-wrapper, #main-tools {\
  3773. width: 100%;\
  3774. min-height: 2.5em;\
  3775. }\
  3776. #bar-wrapper:not(:hover) > #main-tools[auto_hide] {\
  3777. display: none;\
  3778. }\
  3779. .table, .th, .td {\
  3780. display: inline-block;\
  3781. cursor: default;\
  3782. }\
  3783. .table {\
  3784. border:none;\
  3785. }\
  3786. .thead {\
  3787. background: #ffffcf;\
  3788. border-radius: 18px;\
  3789. width: auto;\
  3790. padding: 3px;\
  3791. margin-bottom: 3px;\
  3792. -webkit-box-shadow: 1px 1px 1px #aaa;\
  3793. }\
  3794. .thead, .tr {\
  3795. border-radius: 18px;\
  3796. }\
  3797. .tr {\
  3798. white-space: nowrap;\
  3799. }\
  3800. .th {\
  3801. border-left:1px solid #9e9e9e00;\
  3802. border-right:1px solid #9e9e9e00;\
  3803. }\
  3804. .th, .td {\
  3805. overflow: hidden;\
  3806. text-align: center;\
  3807. padding: 0 2px;\
  3808. }\
  3809. .td {\
  3810. border: 1px solid transparent;\
  3811. }\
  3812. .td:last-child, .th:last-child {\
  3813. border-right: none;\
  3814. }\
  3815. .sel-item:nth-child(odd) {\
  3816. background-color:#ffffff;\
  3817. border-radius:18px;\
  3818. -webkit-box-shadow: 1px 1px 1px #aaa;\
  3819. padding: 2px;\
  3820. margin-bottom: 3px;\
  3821. }\
  3822. .flex {\
  3823. overflow-x: hidden;\
  3824. overflow-y: auto;\
  3825. background: white;\
  3826. }\
  3827. .cell-show, .cell-hl, .cell-lz, .cell-imgs { width: 1em}\
  3828. .cell-author {width: 8em }\
  3829. .cell-idx, .cell-len { width: 3em }\
  3830. .r { text-align: right; }\
  3831. .l { text-align: center ; }\
  3832. #panel-btns {\
  3833. display: inline-block;\
  3834. float: right;\
  3835. }\
  3836. \
  3837. .panel-button {\
  3838. display: inline-block;\
  3839. cursor: default;\
  3840. font-size: 120%;\
  3841. width: 1.2em;\
  3842. height: 1.2em;\
  3843. margin: 0 .5ex;\
  3844. text-align: center;\
  3845. -moz-border-radius: 50%;\
  3846. border: none;\
  3847. font-family:微软雅黑;\
  3848. }\
  3849. .panel-button[active],\
  3850. .panel-button:hover {\
  3851. color:#ffa;\
  3852. cursor:pointer;\
  3853. }\
  3854. .panel {\
  3855. position: fixed;\
  3856. right: 0;\
  3857. z-index: 99;\
  3858. text-align: left;\
  3859. border-radius: 18px;\
  3860. }\
  3861. #bar-wrapper, .panel { font-size: small }\
  3862. #prefs-panel-toggle {\
  3863. background-color:rgba(255, 255, 255, 0);\
  3864. margin-bottom: 10px;\
  3865. margin-top: 10px;\
  3866. border:none;\
  3867. }\
  3868. #prefs-panel-toggle[active],\
  3869. #prefs-panel-toggle:hover {\
  3870. color:#ffa;\
  3871. cursor:pointer;\
  3872. }\
  3873. #post-panel-toggle {\
  3874. background-color:rgba(255, 255, 255, 0);\
  3875. margin-bottom: 10px;\
  3876. margin-top: 10px;\
  3877. border:none;\
  3878. }\
  3879. #post-panel-toggle[active],\
  3880. #post-panel-toggle:hover {\
  3881. color:#ffa;\
  3882. cursor:pointer;\
  3883. }\
  3884. #reply-panel-toggle {\
  3885. background-color:rgba(255, 255, 255, 0);\
  3886. margin-bottom: 10px;\
  3887. margin-top: 10px;\
  3888. border:none;\
  3889. }\
  3890. #reply-panel-toggle[active],\
  3891. #reply-panel-toggle:hover {\
  3892. color:#ffa;\
  3893. cursor:pointer;\
  3894. }\
  3895. \
  3896. .sel-item {\
  3897. cursor: pointer;\
  3898. background-color: #eee;\
  3899. -webkit-box-shadow: 1px 1px 1px #aaa;\
  3900. border-radius: 18px;\
  3901. padding: 2px;\
  3902. margin-bottom: 3px;\
  3903. }\
  3904. .sel-item[selected], .menu-item:hover {\
  3905. background-color: #ffffd2;\
  3906. }\
  3907. \
  3908. .toggle-button, .text-button {\
  3909. display: inline-block;\
  3910. -moz-border-radius: 2px;\
  3911. text-align: center;\
  3912. cursor: pointer;\
  3913. }\
  3914. .text-button {\
  3915. margin: 2px;\
  3916. padding: .2ex .5ex;\
  3917. min-width: 2em;\
  3918. border-radius: 10px;\
  3919. -webkit-box-shadow: 1px 1px 1px #aaa;\
  3920. }\
  3921. .toggle-button {\
  3922. color: white;\
  3923. border:none;\
  3924. width: 1.2em;\
  3925. margin: 0 .5ex;\
  3926. }\
  3927. #goggle-btns {\
  3928. padding: 0 1em\
  3929. }\
  3930. #show-all-button[on] {\
  3931. color: #ffa;\
  3932. border:none;\
  3933. }\
  3934. #hl-lz-button[on] {\
  3935. color: #ffa;\
  3936. border:none;\
  3937. }\
  3938. .panel-button, .toggle-button {\
  3939. background-image: -moz-linear-gradient(-66deg,\
  3940. rgba(255,255,255,.3) 20%,\
  3941. rgba(0,0,0,.4) 60%,\
  3942. rgba(255,255,255,.4) 80%);\
  3943. }\
  3944. \
  3945. .post[hl] > .post-head {\
  3946. background: -moz-linear-gradient(top,\
  3947. rgba(200,255,255,0.2),\
  3948. rgba(200,255,255,0) 40%,\
  3949. rgba(80, 70, 30, 0.1) 50%,\
  3950. rgba(80, 70, 30, 0)),\
  3951. -moz-linear-gradient(left, #ffa 30%, rgba(255,255,176,0.3) 70%, #ffa 90%),\
  3952. -moz-repeating-linear-gradient(-30deg, orange 0px, white 3px, orange 6px);\
  3953. border-color: #fd8;\
  3954. color: 222;\
  3955. }\
  3956. .tr[hl][show] {\
  3957. background-image: -moz-linear-gradient(\
  3958. left, rgb(255,255,200), rgba(255,255,128,0));\
  3959. }\
  3960. .post[hl] > .post-body {\
  3961. border-radius: 15px;\
  3962. background:#f8f8f8;\
  3963. box-shadow:0px 2px 8px #aaa;\
  3964. }\
  3965. .post:not([show]) { display: none }\
  3966. .post-row:not([show]) { color: gray}\
  3967. .text-button:hover { background-color: pink }\
  3968. *[goto] {\
  3969. outline-offset: -1px;\
  3970. outline: 1px solid red;\
  3971. }\
  3972. .tr[show] > .td.cell-hl {\
  3973. color: purple;\
  3974. }\
  3975. #toggle-btns {\
  3976. padding: 0 1em\
  3977. }\
  3978. #info-box {\
  3979. color: black;\
  3980. background: #ffa;\
  3981. border-radius: 15px;\
  3982. position: fixed;\
  3983. bottom: 2em;\
  3984. right: 1em;\
  3985. z-index: 1000;\
  3986. padding: 1ex;\
  3987. font-size: small;\
  3988. -webkit-box-shadow: 1px 1px 1px #aaa;\
  3989. }\
  3990. .td.cell-show:hover,\
  3991. .td.cell-hl:hover,\
  3992. .td.cell-lz:hover,\
  3993. .td.cell-idx:hover {\
  3994. cursor: pointer;\
  3995. background: #ccc;\
  3996. }\
  3997. .menu-popup {\
  3998. background: #ddb;\
  3999. border: 1px solid gray;\
  4000. top: 1em; left: 1em;\
  4001. display: inline-block;\
  4002. }\
  4003. .menu-item {\
  4004. display: table-row;\
  4005. text-align: left;\
  4006. font-size: small;\
  4007. }\
  4008. .menu-icon, .menu-label {\
  4009. display: table-cell;\
  4010. padding: .5ex;\
  4011. cursor: default;\
  4012. }\
  4013. .menu-item[menuend] > .menu-label {\
  4014. border-bottom: 1px solid gray;\
  4015. }\
  4016. .menu-icon {\
  4017. text-align: center;\
  4018. padding: .5ex 1ex;\
  4019. border-right: 1px solid gray;\
  4020. background: rgba(255,255,255,.3);\
  4021. }\
  4022. .popup-window, .menu-popup {\
  4023. -moz-box-shadow: 2px 2px 4px black;\
  4024. position: fixed;\
  4025. }\
  4026. #leng-limit {\
  4027. background: transparent;\
  4028. border: 1px solid transparent;\
  4029. color:white\
  4030. }\
  4031. #leng-limit:focus {\
  4032. background: white;\
  4033. border: 1px solid gray;\
  4034. }\
  4035. .post-icon {\
  4036. float: right;\
  4037. padding: 0 1ex;\
  4038. cursor: default;\
  4039. }\
  4040. .lz-icon, [show] > [lz='1'] {\
  4041. color: #d23337;\
  4042. }\
  4043. .lz-equiv, [show] > [lz='2'] {\
  4044. color: #607d8b;\
  4045. }\
  4046. #all-pages { display: inline-block }\
  4047. .popup-inside {\
  4048. background-color: #eee;\
  4049. border: none;\
  4050. font-family:微软雅黑;\
  4051. -webkit-box-shadow: 1px 1px 1px #aaa;\
  4052. }\
  4053. .subpage {\
  4054. display: inline-block;\
  4055. width: 2em;\
  4056. padding: 0 .5em;\
  4057. text-align: center;\
  4058. cursor: pointer;\
  4059. border: 1px solid transparent;\
  4060. }\
  4061. .subpage:hover {\
  4062. border-color: purple;\
  4063. }\
  4064. span.subpage {\
  4065. background: #ffffd5;\
  4066. -webkit-box-shadow: 0px 0px 1px #aaa;\
  4067. border-radius: 18px;\
  4068. text-align: center;\
  4069. }\
  4070. #page-list {\
  4071. max-width: 30em;\
  4072. max-height: 22em;\
  4073. overflow-y: auto;\
  4074. padding: 1ex 20px 1ex 1ex;\
  4075. text-align: center;\
  4076. font-family:微软雅黑;\
  4077. border-radius: 18px;\
  4078. margin-top: 1ex;\
  4079. }\
  4080. .prefs-group {\
  4081. border: none;\
  4082. margin: 1ex;\
  4083. border-radius: 18px;\
  4084. }\
  4085. .prefs-title {\
  4086. background: #ffffcf;\
  4087. border-radius: 18px;\
  4088. margin-bottom: 1ex;\
  4089. padding: 2px;\
  4090. text-align: -webkit-center;\
  4091. -webkit-box-shadow: 1px 1px 1px #aaa;\
  4092. }\
  4093. .prefs-body {\
  4094. padding: 2.5ex 5.5ex .5ex 2ex;\
  4095. font-family:微软雅黑;\
  4096. border: none;\
  4097. background-color: #eee;\
  4098. border-radius: 18px;\
  4099. -webkit-box-shadow: 1px 1px 1px #aaa;\
  4100. }\
  4101. .panel-close { color: white; float: right; cursor: pointer }\
  4102. .panel-close:hover {\
  4103. color: #ffffaa;\
  4104. }\
  4105. img { border: none }\
  4106. #reply-panel {\
  4107. width: auto;\
  4108. height: 33em;\
  4109. position: fixed;\
  4110. bottom: 1em;\
  4111. left: 8px;\
  4112. top: auto !important;\
  4113. right: auto !important;\
  4114. font-family:微软雅黑;\
  4115. margin-bottom: 2ex;\
  4116. background-color: #eee;\
  4117. border-radius: 18px;\
  4118. padding-bottom: 4ex;\
  4119. }\
  4120. a:-webkit-any-link {\
  4121. color: #607d8b;\
  4122. }\
  4123. .TY_ui_window .bcc .ty-content {\
  4124. text-align:-webkit-center;\
  4125. padding: 12px 24px;\
  4126. zoom: 1;\
  4127. display: block;\
  4128. background: #607d8b;\
  4129. width: 34ex;\
  4130. border-radius: 18px;\
  4131. -webkit-box-shadow: 1px 1px 1px #aaa;\
  4132. margin: -16ex 5ex 5ex 6ex;\
  4133. color: white;\
  4134. }\
  4135. </r>");
  4136. ff.make_ui();
  4137. }
  4138.  
  4139. pref.decl('manual_start', 'bool', false);
  4140. pref.manual_start;
  4141. if (pref.manual_start) {
  4142. $('@body').a($('+div', '脱水',
  4143. {style: 'position: fixed; right: 4ex; top: 8ex; font-size:200%; color: white; padding: 15px 8px; border: none; border-radius:4px; background-color:#607D8B; cursor:pointer;font-family:微软雅黑;font-size:10px;-webkit-writing-mode:vertical-lr', title: '启动脚本'})
  4144. .e('click', start_all));
  4145. } else {
  4146. start_all();
  4147. }