TGFC User Tagging

给TGFC加上标记用户/屏蔽用户帖子/修改用户帖子颜色/保存用户帖子/暴力搜索

  1. // ==UserScript==
  2. // @name TGFC User Tagging
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3.1
  5. // @description 给TGFC加上标记用户/屏蔽用户帖子/修改用户帖子颜色/保存用户帖子/暴力搜索
  6. // @author Hibino
  7. // @include http*://bbs.tgfcer.com/*
  8. // @include http*://club.tgfcer.com/*
  9. // @include http*://s.tgfcer.com/*
  10. // @require https://code.jquery.com/jquery-3.1.1.min.js
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_addStyle
  14. // ==/UserScript==
  15.  
  16. /* CSSs
  17. .tgut-clear{
  18. clear: both;
  19. }
  20. .tgut-blur{
  21. filter: blur(20px);
  22. }
  23. .tgut{
  24. right: 0;
  25. position: absolute;
  26. font-weight: normal;
  27. }
  28. .tgut:hover{
  29. }
  30. .tgut-msg{
  31. display: none;
  32. position: fixed;
  33. width: 300px;
  34. padding: 5px 10px;
  35. top: 0;
  36. left: 50%;
  37. margin-left: -150px;
  38. color: #ffffff;
  39. text-align: center;
  40. background: #0033cc;
  41. z-index: 300;
  42. }
  43. .tgut .t{
  44. display: block;
  45. padding: 2px 5px;
  46. color: #ffffff;
  47. background: #006cc2;
  48. }
  49. .tgut .m{
  50. display: none;
  51. position: absolute;
  52. width: 165px;
  53. right: 0;
  54. padding: 10px;
  55. color: #444444;
  56. text-align: right;
  57. border: 3px solid #006cc2;
  58. background: #ffffff;
  59. z-index: 100;
  60. }
  61. .tgut:hover .m{
  62. display: block;
  63. }
  64. .tgut .in{
  65. width: 110px;
  66. }
  67. .tgut .but{
  68. color: #ffffff;
  69. border: 0;
  70. background: #006cc2;
  71. }
  72. .tgut .tag{
  73. margin: 0 0 10px;
  74. }
  75. .tgut .colors{
  76. margin: 0 0 10px;
  77. }
  78. .tgut .clor{
  79. margin: 0 0 10px;
  80. }
  81. .tgut .remv{
  82. margin: 0 0 10px;
  83. }
  84. .tgut .colors .c{
  85. float: right;
  86. width: 32px;
  87. height: 32px;
  88. margin: 0;
  89. }
  90. .tgut .colors .f{
  91. margin-right: 0;
  92. }
  93. .tgut .colors .c1{
  94. background: #641e16;
  95. }
  96. .tgut .colors .c2{
  97. background: #4a235a;
  98. }
  99. .tgut .colors .c3{
  100. background: #0b5345;
  101. }
  102. .tgut .colors .c4{
  103. background: #7d6608;
  104. }
  105. .tgut .colors .c5{
  106. background: #424949 ;
  107. }
  108. .tgut .colors .c6{
  109. background: #e74c3c;
  110. }
  111. .tgut .colors .c7{
  112. background: #f7dc6f;
  113. }
  114. .tgut .colors .c8{
  115. background: #85929e;
  116. }
  117. .tgut .colors .c9{
  118. background: #17a589 ;
  119. }
  120. .tgut .colors .c10{
  121. background: #f0b27a;
  122. }
  123. .tgut-tag{
  124. margin: 10px 0;
  125. color: #ffffff;
  126. text-align: center;
  127. line-height: 24px;
  128. border: 0;
  129. background: #006cc2;
  130. }
  131. .tgut-page-cover{
  132. display: none;
  133. position:absolute;
  134. top: 0;
  135. left: 0;
  136. -moz-opacity: 0.6;
  137. opacity: 0.6;
  138. background-color: #000000;
  139. z-index: 200;
  140. }
  141. .tgut-popup{
  142. position: absolute;
  143. display: none;
  144. left: 50%;
  145. top: 10%;
  146. width: 60%;
  147. background: #ffffff;
  148. border: 5px solid #006cc2;
  149. z-index: 250;
  150. }
  151. .tgut-popup .f-l{
  152. float: left;
  153. }
  154. .tgut-popup .f-r{
  155. float: right;
  156. }
  157. .tgut-popup .tt{
  158. padding: 0 10px;
  159. line-height: 28px;
  160. color: #ffffff;
  161. background: #006cc2;
  162. }
  163. .tgut-popup .cls{
  164. }
  165. .tgut-popup .cls a{
  166. display: block;
  167. width: 24px;
  168. float: right;
  169. font-size: 120%;
  170. color: #fff;
  171. line-height: 24px;
  172. cursor: pointer;
  173. text-align: center;
  174. text-decoration: none;
  175. }
  176. .tgut-popup .cls a:hover{
  177. color: #0e5685;
  178. background: #fff;
  179. }
  180. .tgut-popup .ct{
  181. clear: both;
  182. __padding: 5px;
  183. text-align: left;
  184. }
  185. .tgut-posts{
  186. padding: 10px;
  187. }
  188. .tgut-posts .post{
  189. clear: both;
  190. margin: 10px 0 20px 0;
  191. padding: 10px;
  192. background: #f0f0f0;
  193. border-bottom: 2px solid #006cc2;
  194. overflow: hidden;
  195. }
  196. .tgut-posts .pid{
  197. float: right;
  198. margin: 0 20px 0 0;
  199. font-weight: bold;
  200. text-decoration: underline;
  201. }
  202. .tgut-posts .time{
  203. float: left;
  204. font-weight: bold;
  205. }
  206. .tgut-posts .del{
  207. float: right;
  208. }
  209. .tgut-posts .del button{
  210. color: #ffffff;
  211. border: 0;
  212. background: #006cc2;
  213. }
  214. .tgut-posts .ct{
  215. clear: both;
  216. margin: 10px 0;
  217. }
  218. .tgut-but{
  219. display: inline-block;
  220. margin: 0 5px 0 0;
  221. padding: 2px 5px;
  222. color: #ffffff;
  223. background: #006cc2;
  224. cursor: pointer;
  225. }
  226. .tgut-sett{
  227. padding: 10px;
  228. }
  229. .tgut-sett .but{
  230. color: #ffffff;
  231. border: 0;
  232. background: #006cc2;
  233. }
  234. .tgut-sett .b{
  235. text-align: right;
  236. }
  237. .tgut-sett .t{
  238. margin: 20px 0;
  239. }
  240. .tgut-sett .t .txa{
  241. width: 99%;
  242. height: 200px;
  243. }
  244. .tgut-sch{
  245. padding: 10px;
  246. }
  247. .tgut-sch .t{
  248. text-align: center;
  249. }
  250. .tgut-sch .t .slc{
  251. width: 160px;
  252. }
  253. .tgut-sch .t .inp{
  254. width: 340px;
  255. }
  256. .tgut-sch .t .usr{
  257. width: 100px;
  258. }
  259. .tgut-sch .but{
  260. display: inline-block;
  261. margin: 0 5px 0;
  262. color: #ffffff;
  263. border: 0;
  264. background: #006cc2;
  265. }
  266. .tgut-sch .s{
  267. margin: 5px auto;
  268. text-align: center;
  269. }
  270. .tgut-sch .s span{
  271. display: inline-block;
  272. margin: 0 5px;
  273. font-weight: bold;
  274. }
  275. .tgut-sch .rs{
  276. margin: 10px 0;
  277. }
  278. .tgut-sch .p{
  279. margin: 5px 0;
  280. }
  281. .tgut-sch .p .u{
  282. color: #888888;
  283. }
  284. .tgut-sch .e{
  285. text-align: center;
  286. }
  287. .tgut-sch .e strong{
  288. font-weight: bold;
  289. }
  290. */
  291.  
  292. (function() {
  293. 'use strict';
  294.  
  295. var DATA_FILE = "tgfc_user_tags";
  296. var POST_URL = "/redirect.php?goto=findpost&pid=";
  297. var HTML_USERNAME =
  298. '<div id="tgut_pid_PID" class="tgut" data-uid="UID" data-pid="PID" >' +
  299. '<div class="t">TGUT</div>' +
  300. '<div class="m">' +
  301. '<div class="tag">标签:<input class="in" type="text" name="tag" value="TAG" /></div>' +
  302. '<div class="colors">' +
  303. '<div class="c c1 f"></div>' +
  304. '<div class="c c2"></div>' +
  305. '<div class="c c3"></div>' +
  306. '<div class="c c4"></div>' +
  307. '<div class="c c5"></div>' +
  308. '<div class="c c6 f"></div>' +
  309. '<div class="c c7"></div>' +
  310. '<div class="c c8"></div>' +
  311. '<div class="c c9"></div>' +
  312. '<div class="c c10"></div>' +
  313. '<div class="tgut-clear"></div></div>' +
  314. '<div class="clor">颜色:<input class="in" type="text" name="color" value="COLOR" /></div>' +
  315. '<div class="remv"><label><input type="checkbox" name="remove_post" value="1" REMOVE_POST>隐藏该用户帖子</label></div>' +
  316. '<button class="but but-save-tag" type="button" name="dummy" value="Save" data-pid="PID">保存</button>' +
  317. '<hr>' +
  318. '<button class="but but-save-post" type="button" name="dummy" value="Save Post" data-pid="PID" data-uid="UID">保存帖子</button>' +
  319. '&nbsp;&nbsp;&nbsp;&nbsp;' +
  320. '<button class="but but-view-posts" type="button" name="dummy" value="Save Post" data-pid="PID" data-uid="UID">查看帖子</button>' +
  321. '</div>' +
  322. '</div>';
  323. var HTML_TAG = '<div class="tgut-tag">TAG</div>';
  324. var HTML_MSG = '<div id="tgut_msg" class="tgut-msg"></div>';
  325. var HTML_POPUP =
  326. '<div class="tgut-page-cover" id="tgut_page_cover"></div>' +
  327. '<div class="tgut-popup" id="tgut_popup">' +
  328. '<div class="tt"><div class="f-l" id="tgut_popup_title">&nbsp;</div><div class="f-r cls" id="tgut_popup_close"><a>X</a></div><div class="tgut-clear"></div></div>' +
  329. '<div class="ct" id="tgut_popup_content"></div>' +
  330. '</div>';
  331. var HTML_SETTINGS =
  332. '<div id="tgut_settings" class="tgut-sett">'+
  333. '<div class="b"><button class="but but-clean" type="button" name="dummy" value="Clean">清除数据</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
  334. '<button class="but but-export" type="button" name="dummy" value="Export">导出数据</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
  335. '<button class="but but-import" type="button" name="dummy" value="Import">导入数据</button></div>'+
  336. '<div class="t">导出时请保存下框的所有文本数据。导入时请把文本数据复制到下框然后点击“导入数据”按钮' +
  337. '<br /><textarea id="tgut_data_text" class="txa" name="dummy"></textarea></div>' +
  338. '</div>';
  339. var HTML_SEARCH =
  340. '<div id="tgut_search" class="tgut-sch">' +
  341. '<div class="t">' +
  342. '<select id="tgut_search_fid" class="slc" name="dummy"><option value="">无法取得版块列表</option></select>&nbsp;&nbsp;' +
  343. '<input id="tgut_search_inp" class="inp" type="text" name="dummy" value="" placeholder="多个关键字用半角空格隔开,关键字之间的关系是AND">' +
  344. '<input id="tgut_search_user" class="usr" type="text" name="dummy" value="" placeholder="用户名 (AND)">' +
  345. '<button id="tgut_search_but" class="but" name="dummy" value="search">搜索</button>'+
  346. '<button id="tgut_search_next" class="but" name="dummy" value="next">继续搜索</button>' +
  347. '<button id="tgut_search_stop" class="but" name="dummy" value="stop">停止搜索</button>' +
  348. '<button id="tgut_search_reset" class="but" name="dummy" value="reset">重置</button>' +
  349. '</div><div class="s">当前搜索页<span id="tgut_search_page">1</span></div>' +
  350. '<div id="tgut_search_results" class="rs"><div class="e">' +
  351. '选择版块,输入要搜索的内容回车或者点击“搜索”按钮。当找到结果搜索会停下,如果结果不是你想要的请点击“继续搜索”。要重新搜索请先点击“重置”' +
  352. '<br>添加/删除搜索的版块请自行编辑脚本第356行开始的FORUM_IDS变量' +
  353. '<br><strong>这是暴力一页一页的搜索,请不要经常使用以防止给服务器带来沉重负担</strong></div></div>'+
  354. '</div>';
  355. var FORUM_IDS = {
  356. '33': '游戏业界综合讨论区',
  357. '10': '完全数码讨论区',
  358. '25': '灌水与情感',
  359. '12': '影视专区',
  360. '6': '体育运动专区',
  361. '90': '二手交易区',
  362. '59': '汽车版',
  363. '85': 'Apple 专区',
  364. '41': '摄影区',
  365. '11': '动漫模玩',
  366. '29': '主机&掌机游戏讨论区',
  367. '101': '经典游戏怀旧专区',
  368. '5': '手机游戏讨论区',
  369. '97': '旅行度假',
  370. '86': '招聘求职'
  371. };
  372.  
  373.  
  374. GM_addStyle(
  375. '.tgut-clear{clear:both}.tgut-blur{filter:blur(20px)}.tgut{right:0;position:absolute;font-weight:400}.tgut-msg{display:none;position:fixed;width:300px;padding:5px 10px;top:0;left:50%;margin-left:-150px;color:#fff;text-align:center;background:#03c;z-index:300}.tgut .t{display:block;padding:2px 5px;color:#fff;background:#006cc2}.tgut .m{display:none;position:absolute;width:165px;right:0;padding:10px;color:#444;text-align:right;border:3px solid #006cc2;background:#fff;z-index:100}.tgut:hover .m{display:block}.tgut .in{width:110px}.tgut .but{color:#fff;border:0;background:#006cc2}.tgut .tag{margin:0 0 10px}.tgut .colors{margin:0 0 10px}.tgut .clor{margin:0 0 10px}.tgut .remv{margin:0 0 10px}.tgut .colors .c{float:right;width:32px;height:32px;margin:0}.tgut .colors .f{margin-right:0}.tgut .colors .c1{background:#641e16}.tgut .colors .c2{background:#4a235a}.tgut .colors .c3{background:#0b5345}.tgut .colors .c4{background:#7d6608}.tgut .colors .c5{background:#424949}.tgut .colors .c6{background:#e74c3c}.tgut .colors .c7{background:#f7dc6f}.tgut .colors .c8{background:#85929e}.tgut .colors .c9{background:#17a589}.tgut .colors .c10{background:#f0b27a}.tgut-tag{margin:10px 0;color:#fff;text-align:center;line-height:24px;border:0;background:#006cc2}.tgut-page-cover{display:none;position:absolute;top:0;left:0;-moz-opacity:.6;opacity:.6;background-color:#000;z-index:200}.tgut-popup{position:absolute;display:none;left:50%;top:10%;width:60%;background:#fff;border:5px solid #006cc2;z-index:250}.tgut-popup .f-l{float:left}.tgut-popup .f-r{float:right}.tgut-popup .tt{padding:0 10px;line-height:28px;color:#fff;background:#006cc2}.tgut-popup .cls a{display:block;width:24px;float:right;font-size:120%;color:#fff;line-height:24px;cursor:pointer;text-align:center;text-decoration:none}.tgut-popup .cls a:hover{color:#0e5685;background:#fff}.tgut-popup .ct{clear:both;text-align:left}.tgut-posts{padding:10px}.tgut-posts .post{clear:both;margin:10px 0 20px 0;padding:10px;background:#f0f0f0;border-bottom:2px solid #006cc2;overflow:hidden}.tgut-posts .pid{float:right;margin:0 20px 0 0;font-weight:700;text-decoration:underline}.tgut-posts .time{float:left;font-weight:700}.tgut-posts .del{float:right}.tgut-posts .del button{color:#fff;border:0;background:#006cc2}.tgut-posts .ct{clear:both;margin:10px 0}.tgut-but{display:inline-block;margin:0 5px 0 0;padding:2px 5px;color:#fff;background:#006cc2;cursor:pointer}.tgut-sett{padding:10px}.tgut-sett .but{color:#fff;border:0;background:#006cc2}.tgut-sett .b{text-align:right}.tgut-sett .t{margin:20px 0}.tgut-sett .t .txa{width:99%;height:200px}.tgut-sch{padding:10px}.tgut-sch .t{text-align:center}.tgut-sch .t .slc{width:160px}.tgut-sch .t .inp{width:340px}.tgut-sch .t .usr{width:100px}.tgut-sch .but{display:inline-block;margin:0 5px 0;color:#fff;border:0;background:#006cc2}.tgut-sch .s{margin:5px auto;text-align:center}.tgut-sch .s span{display:inline-block;margin:0 5px;font-weight:700}.tgut-sch .rs{margin:10px 0}.tgut-sch .p{margin:5px 0}.tgut-sch .p .u{color:#888}.tgut-sch .e{text-align:center}.tgut-sch .e strong{font-weight:700}'
  376. );
  377.  
  378. $( 'body' ).append( HTML_MSG );
  379. $( 'body' ).append( HTML_POPUP );
  380.  
  381.  
  382. function test( v ){
  383. return ( v && v !== 0 && v != "0" );
  384. }
  385. function trim( txt ){
  386. return ( txt ? txt.replace( /^\s+|\s+$/g, "" ) : "" );
  387. }
  388. function html( s ){
  389. if( typeof s == 'string' ){
  390. return s.replace(/&/g, "&amp;")
  391. .replace(/</g, "&lt;")
  392. .replace(/>/g, "&gt;")
  393. .replace(/"/g, "&quot;")
  394. .replace(/'/g, "&#039;");
  395. }
  396. return '';
  397. }
  398. function count_obj( o, true_only ){
  399. var c = 0;
  400. for( var i in o ){
  401. true_only ? ( test( o[i] ) && c++ ) : c++;
  402. }
  403. return c;
  404. }
  405. function tl( o ){
  406. console.log( o );
  407. }
  408.  
  409.  
  410. var tg = {
  411.  
  412. is_logged_in: 0,
  413. data_init: {
  414. version: 2,
  415. users: {},
  416. posts: {},
  417. },
  418. user_init: {
  419. uid: 0,
  420. name: '',
  421. tag: '',
  422. color: '',
  423. remove_post: 0,
  424. parent_uid: 0,
  425. related_uids: {},
  426. quotes: {}
  427. },
  428. data: {},
  429.  
  430. msg: function( m ){
  431. $( '#tgut_msg' ).html( m ).stop( true, true ).show( 1, function(){ $( '#tgut_msg' ).animate( {"null":1}, 1000 ).fadeOut( 200 ); } );
  432. },
  433.  
  434. load_data: function(){
  435. var data = tg.data_init;
  436. var tmp = GM_getValue( DATA_FILE, "" );
  437.  
  438. try{
  439. data = JSON.parse( tmp );
  440. }catch( e ){
  441.  
  442. }
  443. if( test( data.version ) ){
  444. tg.data = data;
  445. }
  446. },
  447. save_data: function(){
  448. GM_setValue( DATA_FILE, JSON.stringify( tg.data ) );
  449. },
  450. clean_data: function(){
  451. tg.data = tg.data_init;
  452. tg.save_data();
  453. },
  454. update_data: function(){
  455. if( tg.data.version < 2 ){
  456. tg.data.posts = {};
  457. tg.data.version = 2;
  458. tg.save_data();
  459. }
  460. },
  461.  
  462. init: function(){
  463. // check if logged in
  464. var l = $( '#logo' ).next().next();
  465. if( l.html().indexOf( "logging.php?action=logout" ) > 0 ){
  466. tg.is_logged_in = 1;
  467. // read in stored settings
  468. tg.load_data();
  469. tg.update_data();
  470.  
  471. post.init();
  472. sett.init();
  473. sch.init();
  474. }else{
  475. // do nothing...
  476. }
  477.  
  478. pop.init();
  479. }
  480.  
  481. };
  482.  
  483. var pop = {
  484.  
  485. cover: function( on ){
  486. var c = $( '#tgut_page_cover' );
  487. var o = $( 'body' );
  488. if( on ){
  489. c.css( "width", o.width() ).css( "height", o.height() ).show();
  490. o.find( '.wrap:first' ).addClass( "tgut-blur" );
  491. }else{
  492. o.find( '.wrap:first' ).removeClass( "tgut-blur" );
  493. c.hide();
  494. }
  495.  
  496. },
  497.  
  498. show: function( t, c ){
  499. var o = $( '#tgut_popup' );
  500. var top = $(document).scrollTop() + ( o.height() > 500 ? 1 : 100 );
  501. $( '#tgut_popup_content' ).html( c );
  502. $( '#tgut_popup_title' ).html( ( t ) );
  503. o.css( "margin-left", - o.width() / 2 ).css( "top", top ).show();
  504. pop.cover( 1 );
  505. },
  506. close: function(){
  507. $( '#tgut_popup' ).hide();
  508. pop.cover();
  509. },
  510.  
  511. init: function(){
  512. $( '#tgut_popup_close' ).click( pop.close );
  513. }
  514. };
  515.  
  516.  
  517. var post = {
  518.  
  519. process_posts: function(){
  520. $( "div.viewthread" ).each(
  521. function(){
  522. var o = $( this );
  523. var user = o.find( "cite:first" ).css( "position", "relative" ).css( 'overflow', 'visible' );
  524. var popup = o.find( ".userinfopanel" );
  525. o.find( '.postauthor' ).css( 'overflow', 'visible' );
  526. o.find( '.tgut' ).remove();
  527.  
  528. var name = user.find( "a" ).html();
  529. var uid = post.get_uid( popup );
  530. var pid = o.find( "table" ).first().prop( "id" ).replace( "pid", "" );
  531.  
  532. //alert( username + ":::" + uid + ":::" + pid );
  533. var tag = test( tg.data.users[uid] ) ? tg.data.users[uid] : tg.user_init;
  534. var h = HTML_USERNAME;
  535. h = h.replace( /PID/g, pid )
  536. .replace( /UID/g, uid )
  537. .replace( /TAG/g, html( tag.tag ) )
  538. .replace( /COLOR/g, html( tag.color ) )
  539. .replace( /REMOVE_POST/g, ( test( tag.remove_post ) ? 'checked' : '' ) );
  540. var j = new $( h );
  541. j.find( ".but-save-tag" ).click( post.save );
  542. j.find( ".but-save-post" ).click( post.save_post );
  543. j.find( ".but-view-posts" ).click( post.view_posts );
  544. j.find( ".c" ).click( post.color_click );
  545. user.append( j );
  546.  
  547. if( tag.uid == uid ){
  548. user.parent().find( '.tgut-tag' ).remove();
  549. if( test( tag.tag ) ){
  550. user.after( HTML_TAG.replace( /TAG/g, html( tag.tag ) ) );
  551. }
  552. user.closest( 'table' ).find( 'td' ).css( 'color', '' );
  553. if( test( tag.color ) ){
  554. user.closest( 'table' ).find( 'td' ).css( 'color', tag.color );
  555. }
  556. if( test( tag.remove_post ) ){
  557. user.nextAll(":gt(0)").css( 'display', 'none' );
  558. o.find( '.postmessage' ).css( 'display', 'none' ).after( '<div class="tgut-mesg">用户帖子和签名被屏蔽</div>' );
  559. o.find( '.signatures' ).css( 'display', 'none' );
  560. }else{
  561. user.nextAll().css( 'display', 'block' );
  562. o.find( '.postmessage' ).css( 'display', 'block' );
  563. o.find( '.signatures' ).css( 'display', 'none' );
  564. o.find( '.tgut-mesg' ).remove();
  565. }
  566. }
  567. }
  568. );
  569. },
  570. get_uid: function( d ){
  571. var s = d.find( "dd:eq(0)" ).html().replace( "&nbsp;", "" );
  572. return trim( s );
  573. },
  574. get_name: function( pid ){
  575. var name = $( '#pid' + pid ).find( 'cite:first' ).find( "a" ).html();
  576. return trim( name );
  577. },
  578. color_click: function( e ){
  579. var o = $( this );
  580. o.closest( ".tgut" ).find( "[name='color']" ).val( o.css( "background-color" ) );
  581.  
  582. },
  583. save: function( e ){
  584. var o = $( this ).closest( ".tgut" );
  585. var uid = o.data( "uid" );
  586. var pid = o.data( "pid" );
  587. var tag = o.find( "[name='tag']" ).val();
  588. var color = o.find( "[name='color']" ).val();
  589. var remove_post = o.find( "[name='remove_post']" ).is( ':checked' );
  590. if( !test( uid ) ){
  591. return;
  592. }
  593. if( !test( tg.data.users[uid] ) ){
  594. tg.data.users[uid] = tg.user_init;
  595. }
  596. tg.data.users[uid].uid = uid;
  597. tg.data.users[uid].tag = tag;
  598. tg.data.users[uid].name = post.get_name( pid );
  599. tg.data.users[uid].color = color;
  600. tg.data.users[uid].remove_post = remove_post ? 1 : 0;
  601. tg.save_data();
  602. tg.msg( "已保存用户标签" );
  603. post.process_posts();
  604. },
  605. save_post: function( e ){
  606. var o = $( this );
  607. var pid = o.data( 'pid' );
  608. var uid = o.data( 'uid' );
  609. var content = trim( $( '#postmessage_' + pid ).html() );
  610. var time_str = trim( $( '#pid' + pid ).find( '.postinfo' ).clone().children().remove().end().text() ); // well well well....
  611.  
  612. if( !test( tg.data.posts[uid] ) ){
  613. tg.data.posts[uid] = {};
  614. }
  615. tg.data.posts[uid][pid] = {
  616. 'uid': uid,
  617. 'pid': pid,
  618. 'name': post.get_name( pid ),
  619. 'time': time_str,
  620. 'post': content
  621. };
  622.  
  623. tg.save_data();
  624. tg.msg( "帖子保存了" );
  625.  
  626. },
  627. del_post: function( e ){
  628. var o = $( this );
  629. var pid = o.data( 'pid' );
  630. var uid = o.data( 'uid' );
  631.  
  632. if( test( tg.data.posts[uid] ) && test( tg.data.posts[uid][pid] ) ){
  633. delete( tg.data.posts[uid][pid] );
  634. tg.save_data();
  635. tg.msg( "帖子删除了" );
  636. }
  637.  
  638. $( '#tgut_post_' + pid ).remove();
  639. if( !count_obj( tg.data.posts[uid] ) ){
  640. pop.close();
  641. }
  642.  
  643. },
  644. view_posts: function( e ){
  645. var o = $( this );
  646. var pid = o.data( 'pid' );
  647. var uid = o.data( 'uid' );
  648.  
  649. if( !test( tg.data.posts[uid] ) || !count_obj( tg.data.posts[uid] ) ){
  650. tg.msg( '没有针对该用户保存的帖子' );
  651. return;
  652. }
  653.  
  654. var name = '';
  655. var h = '<div class="tgut-posts">';
  656. for( var i in tg.data.posts[uid] ){
  657. var p = tg.data.posts[uid][i];
  658. name = p.name;
  659. h += '<div class="post" id="tgut_post_' +p.pid+ '"><div class="time">' +p.time+ '</div>' +
  660. '<div class="del"><button class="but" name="dummy" value="Del" data-pid="' +p.pid+ '" data-uid="' +p.uid+ '">删除</button></div>' +
  661. '<div class="pid"><a href="' +POST_URL+p.pid+ '" target="_blank">Post ID: ' +p.pid+ '</a></div>' +
  662. '<div class="ct">' +p.post+ '</div></div>';
  663. }
  664. h += '</div>';
  665. var j = new $( h );
  666. j.find( '.but' ).click( post.del_post );
  667. pop.show( name, j );
  668. },
  669.  
  670. init: function(){
  671. post.process_posts();
  672. }
  673.  
  674. };
  675.  
  676.  
  677. var sett = {
  678.  
  679. clean: function(){
  680. if( confirm( "确定删除所有以保存的用户标签以及帖子吗?" ) ){
  681. tg.clean_data();
  682. tg.save_data();
  683. tg.init();
  684. tg.msg( "数据已清除" );
  685. }
  686. },
  687. export: function(){
  688. var str = JSON.stringify( tg.data );
  689. $( '#tgut_data_text' ).val( str );
  690. tg.msg( "数据已显示在输入框中" );
  691. },
  692. import: function(){
  693. var data = {};
  694. var str = trim( $( '#tgut_data_text' ).val() );
  695. try{
  696. data = JSON.parse( str );
  697. }catch( e ){
  698. tg.msg( "数据不是有效的JSON字串" );
  699. return;
  700. }
  701. if( test( data.version ) ){
  702. tg.data = data;
  703. tg.update_data();
  704. tg.save_data();
  705. tg.msg( "成功导入数据" );
  706. tg.init();
  707. }else{
  708. tg.msg( "无法识别数据版本" );
  709. }
  710. },
  711. show: function(){
  712. var j = new $( HTML_SETTINGS );
  713. j.find( '.but-clean' ).click( sett.clean );
  714. j.find( '.but-export' ).click( sett.export );
  715. j.find( '.but-import' ).click( sett.import );
  716. pop.show( 'TGUT设置', j );
  717. },
  718.  
  719. init: function(){
  720. // find the user bar beside the log
  721. var o = $( '#logo' ).parent().find( 'cite:first' ).parent();
  722. if( !o.find( '.tgut-but' ).length ){
  723. var j = new $( '<div class="tgut-but">TGUT</div>' );
  724. j.click( sett.show );
  725. o.append( j );
  726. }
  727. }
  728. };
  729.  
  730.  
  731. var sch = {
  732. p: 1,
  733. s: 0,
  734. url: "/forum-FID-PAGE.html",
  735. empty: '',
  736.  
  737. show: function(){
  738. sch.reset();
  739. pop.show( 'TGUT暴力搜索', HTML_SEARCH );
  740. $( '#tgut_search_inp' ).keyup( sch.keyup );
  741. $( '#tgut_search_user' ).keyup( sch.keyup );
  742. $( '#tgut_search_but' ).click( sch.sch );
  743. $( '#tgut_search_next' ).click( sch.next );
  744. $( '#tgut_search_reset' ).click( sch.reset );
  745. $( '#tgut_search_stop' ).click( sch.stop );
  746.  
  747. /* 论坛去掉了左下角的快速链接。。。。
  748. var o = $( '#footfilter' ).children( 'select' );
  749. if( o.length == 1 ){
  750. $( '#tgut_search_fid' ).html( o.html().replace( '版块跳转 ...', '[选择搜索版块]' ) );
  751. }
  752. */
  753. var o = $( '#tgut_search_fid' ).empty().append( '<option value="">[选择搜索版块]</option>' );
  754. for( var i in FORUM_IDS ){
  755. o.append( '<option value="' +i+ '">' +FORUM_IDS[i]+ '</option>' );
  756. }
  757. },
  758. reset: function(){
  759. sch.set_p(1);
  760. sch.s = 0;
  761. $( '#tgut_search_inp' ).val( '' );
  762. $( '#tgut_search_user' ).val( '' );
  763. $( '#tgut_search_fid' ).val( '' );
  764. },
  765. stop: function(){
  766. sch.s = 1;
  767. },
  768. set_p: function( p ){
  769. sch.p = p;
  770. $( '#tgut_search_page' ).html( p );
  771. },
  772. max_p: function(){
  773. return 50;
  774. },
  775. get_v: function(){
  776. var v = $( '#tgut_search_inp' ).val().trim();
  777. if( v ){
  778. return v.split( ' ' );
  779. }
  780. return [];
  781. },
  782. get_u: function(){
  783. var v = $( '#tgut_search_user' ).val().trim();
  784. return v;
  785. },
  786. keyup: function( e ){
  787. if( e ){
  788. var k = (e.keyCode) ? e.keyCode : e.which;
  789. ( k == 13 ) && sch.sch();
  790. }
  791. return false;
  792. },
  793. next: function(){
  794. sch.p++
  795. sch.set_p( sch.p );
  796. sch.sch();
  797. },
  798. fid: function(){
  799. return $( '#tgut_search_fid' ).val();
  800. },
  801. sch: function(){
  802. var s_v = sch.get_v();
  803. var s_u = sch.get_u();
  804. var fid = sch.fid();
  805. if( ( s_v.length > 0 || s_u ) && fid ){
  806. if( sch.p < sch.max_p() ){
  807. tg.msg( '搜索中....' );
  808. var url = sch.url.replace( 'FID', fid ).replace( 'PAGE', sch.p );
  809. //$.post( url, {}, sch.sch_callback ); // fxxk the TGFC server does not put charset in header
  810. $.ajax({
  811. data: {},
  812. type: "GET",
  813. url: url,
  814. beforeSend: function( xhr ) {
  815. xhr.overrideMimeType( "text/html; charset=GBK" );
  816. },
  817. success: sch.sch_callback
  818. });
  819. }else{
  820. sch.msg( '已达到最大搜索页数,搜索停止' );
  821. }
  822. }else{
  823. sch.msg( '版块不能为空,关键字和用户名不能同时为空' );
  824. }
  825. },
  826. sch_callback: function( data ){
  827. var o = $( '#tgut_search_results' ).empty();
  828. var s_v = sch.get_v();
  829. var s_u = sch.get_u();
  830. if( s_v.length || s_u ){
  831. var shit = $( data );
  832. var list = shit.find( '#forum_' + sch.fid() ).find( 'tbody' );
  833. shit.remove();
  834. if( list.length > 0 ){
  835. var f = 0;
  836. list.each(
  837. function( i ){
  838. var tds = $( this ).find( 'tr' ).children();
  839. var p = tds.eq(2).find( 'a' );
  840. var u = tds.eq(3).find( 'a' );
  841. var str_p = p.html() || '';
  842. var str_u = u.html() || '';
  843. var f_p = 0;
  844. var f_u = 0;
  845. if( s_v.length ){
  846. if(
  847. s_v.every(
  848. function( x ){
  849. return str_p.indexOf( x ) != -1;
  850. }
  851. )
  852. ){
  853. f_p = 1;
  854. }
  855. }else{
  856. f_p = 1;
  857. }
  858. if( s_u ){
  859. if( str_u.indexOf( s_u ) != -1 ){
  860. f_u = 1;
  861. }
  862. }else{
  863. f_u = 1;
  864. }
  865. if( f_p && f_u ){
  866. f++;
  867. o.append( '<div class="p"><a href="' +p.prop( 'href' )+ '" target="_blank">' +p.html()+ '</a> <a class="u" href="' +u.prop( 'href' )+ '" target="_blank">' +u.html()+ '</a></div>' );
  868. }
  869. }
  870. );
  871. if( f < 1 ){
  872. if( sch.p < sch.max_p() ){
  873. sch.msg( '当前页没有结果,搜索下一页...' );
  874. if( !sch.s ){
  875. sch.next();
  876. }else{
  877. sch.s = 0;
  878. sch.msg( '搜索已停止' );
  879. }
  880. }
  881. }
  882. }else{
  883. sch.msg( '该页没有得到任何帖子信息,搜索停止' );
  884. }
  885. }else{
  886. sch.msg( '关键字和用户名不能同时为空' );
  887. }
  888. },
  889. msg: function( s ){
  890. $( '#tgut_search_results' ).empty().html( '<div class="e">' +s+ '</div>' );
  891. },
  892.  
  893.  
  894. init: function(){
  895. var o = $( '#logo' ).parent().find( 'cite:first' ).parent();
  896. //if( o.html().indexOf( '搜索' ) < 0 ){
  897. var j = new $( '<div class="tgut-but">暴力搜索</div>' );
  898. j.click( sch.show );
  899. o.append( j );
  900. //}
  901. }
  902. };
  903.  
  904. tg.init();
  905.  
  906. })();