Silent B

隐藏指定的超展开列表项目,等等

  1. /*
  2. // ==UserScript==
  3. // @name Silent B
  4. // @namespace https://github.com/hentaiPanda
  5. // @description 隐藏指定的超展开列表项目,等等
  6. // @author niR
  7. // @version 4672.20 pre Bismark
  8. // @license MIT License
  9. // @encoding utf-8
  10. // @require http://code.jquery.com/jquery-2.1.1.js
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @include http://bgm.tv/rakuen/topiclist
  14. // @include http://bangumi.tv/rakuen/topiclist
  15. // @include http://chii.in/rakuen/topiclist
  16. // @include http://bgm.tv/
  17. // @include http://bangumi.tv/
  18. // @include http://chii.in/
  19. // @include /^http://bgm\.tv/subject/[0-9]+/
  20. // @include /^http://bangumi\.tv/subject/[0-9]+/
  21. // @include /^http://chii\.in/subject/[0-9]+/
  22. // @include http://bgm.tv/subject_search/*
  23. // @include http://bangumi.tv/subject_search/*
  24. // @include http://chii.in/subject_search/*
  25. // @include /^http://bgm\.tv/(anime|book|music|real)/browser/
  26. // @include /^http://bangumi\.tv/(anime|book|music|real)/browser/
  27. // @include /^http://chii\.in/(anime|book|music|real)/browser/
  28. // @include /^http://bgm\.tv/group/(?!topic).+/
  29. // @include /^http://bangumi.tv/group/(?!topic).+/
  30. // @include /^http://chii.in/group/(?!topic).+/
  31. // @include http://bgm.tv/settings*
  32. // @include http://bangumi.tv/settings*
  33. // @include http://chii.in/settings*
  34. // ==/UserScript==
  35. */
  36. var addBtn, addBtnGroup, addBtnHome, addSettingBtn, checkTsuRtg, getParentNode, hideRank, hideRating, hideTsukkomi, initItemList, initItemListGroup, initItemListHome, main, refreshIndexList, refreshList, refreshTopicList, removeItem, removeItemGroup, removeItemHome, sbsetting, updateTsuRtg;
  37.  
  38. getParentNode = function(node, level) {
  39. var i, pn;
  40. i = level - 1;
  41. pn = node.parentNode;
  42. if (level === 0) {
  43. return node;
  44. }
  45. while (i > 0) {
  46. pn = pn.parentNode;
  47. i -= 1;
  48. }
  49. return pn;
  50. };
  51.  
  52. addBtn = function() {
  53. $('li.item_list > div.inner > span.row').each(function() {
  54. var x_btn;
  55. x_btn = '<span class="xlihil"><a href="javascript:;">[X]</a></span>';
  56. return this.innerHTML = this.innerHTML + x_btn;
  57. });
  58. return $('body').on('click.removeli', '.xlihil', function(evt) {
  59. return removeItem(evt.target);
  60. });
  61. };
  62.  
  63. removeItem = function(node) {
  64. var item, tpcid;
  65. item = getParentNode(node, 4);
  66. GM_setValue(item.id, true);
  67. tpcid = item.id.split("item_group_")[1];
  68. console.log(tpcid);
  69. GM_setValue("/group/topic/" + tpcid, true);
  70. return item.outerHTML = '';
  71. };
  72.  
  73. initItemList = function() {
  74. var flag;
  75. flag = false;
  76. $('li.item_list').each(function() {
  77. if (GM_getValue(this.id, false)) {
  78. this.outerHTML = '';
  79. return flag = true;
  80. }
  81. });
  82. return flag;
  83. };
  84.  
  85. addBtnHome = function() {
  86. $('div#home_subject_tpc a.l, div#home_grp_tpc a.l:not(.rr)').each(function() {
  87. var x_btn;
  88. if ($(this).attr("href").startsWith("/group/my")) {
  89. return;
  90. }
  91. x_btn = '<a class="xlihil" href="javascript:;">[X]</a>';
  92. return $(this).next().html(function(i, old) {
  93. return old + x_btn;
  94. });
  95. });
  96. return $('body').on('click.removeli', '.xlihil', function(evt) {
  97. return removeItemHome(evt.target);
  98. });
  99. };
  100.  
  101. removeItemHome = function(node) {
  102. var itemhref, tpcid;
  103. itemhref = $(node).parents().eq(0).prev().attr("href");
  104. GM_setValue(itemhref, true);
  105. tpcid = itemhref.split("/group/topic/")[1];
  106. console.log(tpcid);
  107. GM_setValue("item_group_" + tpcid, true);
  108. return $(node).parents().eq(2).remove();
  109. };
  110.  
  111. initItemListHome = function() {
  112. var flag;
  113. flag = false;
  114. $('div#home_subject_tpc a.l, div#home_grp_tpc a.l').each(function() {
  115. var href;
  116. href = $(this).attr("href");
  117. if (GM_getValue(href, false)) {
  118. $(this).parents().eq(1).remove();
  119. return flag = true;
  120. }
  121. });
  122. return flag;
  123. };
  124.  
  125. addBtnGroup = function() {
  126. $('table.topic_list td.subject').each(function() {
  127. var x_btn;
  128. x_btn = '<small class="grey"><a class="xlihil" href="javascript:;">[X] </a></small>';
  129. return $(this).html(function(i, old) {
  130. return x_btn + old;
  131. });
  132. });
  133. return $('body').on('click.removeli', '.xlihil', function(evt) {
  134. return removeItemGroup(evt.target);
  135. });
  136. };
  137.  
  138. removeItemGroup = function(node) {
  139. var itemhref, tpcid;
  140. itemhref = $(node).parent().next().attr("href");
  141. console.log(itemhref);
  142. GM_setValue(itemhref, true);
  143. tpcid = itemhref.split("/group/topic/")[1];
  144. console.log(tpcid);
  145. GM_setValue("item_group_" + tpcid, true);
  146. return $(node).parents().eq(2).remove();
  147. };
  148.  
  149. initItemListGroup = function() {
  150. var flag;
  151. flag = false;
  152. $('table.topic_list td.subject a.l').each(function() {
  153. var href;
  154. href = $(this).attr("href");
  155. if (GM_getValue(href, false)) {
  156. $(this).parents().eq(1).remove();
  157. return flag = true;
  158. }
  159. });
  160. return flag;
  161. };
  162.  
  163. refreshList = function() {
  164. var i;
  165. i = true;
  166. return $('li.item_list').each(function() {
  167. if (this.style.display) {
  168. return;
  169. }
  170. if (i) {
  171. this.className = 'line_odd item_list';
  172. } else {
  173. this.className = 'line_even item_list';
  174. }
  175. i = !i;
  176. return console.log(this.id);
  177. });
  178. };
  179.  
  180. refreshIndexList = function(klasslist, klass, subklass) {
  181. $(klass).each(function() {
  182. var sub_item, swch;
  183. swch = true;
  184. sub_item = $(this).find(subklass);
  185. if (!sub_item.length) {
  186. return;
  187. }
  188. sub_item.each(function() {
  189. if (swch) {
  190. this.className = klasslist[0];
  191. } else {
  192. this.className = klasslist[1];
  193. }
  194. swch = !swch;
  195. return 1;
  196. });
  197. return 1;
  198. });
  199. return true;
  200. };
  201.  
  202. refreshTopicList = function(klasslist, klass) {
  203. var swch;
  204. swch = true;
  205. $(klass).each(function() {
  206. if (this.style.display) {
  207. return;
  208. }
  209. if (swch) {
  210. this.className = klasslist[0];
  211. } else {
  212. this.className = klasslist[1];
  213. }
  214. swch = !swch;
  215. return 1;
  216. });
  217. return true;
  218. };
  219.  
  220. hideTsukkomi = function(swch) {
  221. if (!swch) {
  222. return;
  223. }
  224. return $("#comment_box").remove();
  225. };
  226.  
  227. hideRating = function(swch) {
  228. if (!swch) {
  229. return;
  230. }
  231. return $("#ChartWarpper, #columnSubjectInHomeB .global_rating").remove();
  232. };
  233.  
  234. hideRank = function(swch) {
  235. if (!swch) {
  236. return;
  237. }
  238. return $("#browserItemList span.rank, #browserItemList p.rateInfo").remove();
  239. };
  240.  
  241. addSettingBtn = function() {
  242. $(".secTab").html(function(i, old) {
  243. return '<li><a href="javascript:;" id="sb_setting"><span>STB设置</span></a></li>' + old;
  244. });
  245. $('body').off('click.sb_setting');
  246. return $('body').on('click.sb_setting', '#sb_setting', function() {
  247. return sbsetting();
  248. });
  249. };
  250.  
  251. updateTsuRtg = function(node) {
  252. switch (node.id) {
  253. case "rtg_yes":
  254. return GM_setValue("hiderating", true);
  255. case "rtg_no":
  256. return GM_setValue("hiderating", false);
  257. case "tsu_yes":
  258. return GM_setValue("hidetsukkomi", true);
  259. case "tsu_no":
  260. return GM_setValue("hidetsukkomi", false);
  261. default:
  262. return false;
  263. }
  264. };
  265.  
  266. checkTsuRtg = function() {
  267. var defaultval, flagrtg, flagtsu;
  268. defaultval = true;
  269. flagtsu = GM_getValue("hidetsukkomi", defaultval);
  270. flagrtg = GM_getValue("hiderating", defaultval);
  271. if (flagrtg) {
  272. $("#rtg_yes")[0].checked = true;
  273. } else {
  274. $("#rtg_no")[0].checked = true;
  275. }
  276. if (flagtsu) {
  277. return $("#tsu_yes")[0].checked = true;
  278. } else {
  279. return $("#tsu_no")[0].checked = true;
  280. }
  281. };
  282.  
  283. sbsetting = function() {
  284. var newcolumn;
  285. $("#columnB").css("display", "none");
  286. $("#header > h1").html(function(i, old) {
  287. return "STB设置";
  288. });
  289. $(".secTab > li > a").removeClass("selected");
  290. $("#sb_setting").addClass("selected");
  291. newcolumn = '<span class="text"><table class="settings" cellpadding="5" cellspacing="0" align="center" width="98%"><tbody><tr><td valign="top" width="12%"><h2 class="subtitle">隐藏评分信息</h2></td><td valign="top"></td></tr><tr><td valign="top" width="20%">是</td><td valign="top"><input name="rtg_radio" class="stb" id="rtg_yes" type="radio"></td></tr><tr><td valign="top" width="20%">否</td><td valign="top"><input name="rtg_radio" class="stb" id="rtg_no" type="radio"></td></tr><tr><td valign="top" width="12%"><h2 class="subtitle">隐藏概览页吐槽箱</h2></td><td valign="top"></td></tr><tr><td valign="top" width="20%">是</td><td valign="top"><input name="tsu_radio" class="stb" id="tsu_yes" type="radio"></td></tr><tr><td valign="top" width="20%">否</td><td valign="top"><input name="tsu_radio" class="stb" id="tsu_no" type="radio"></td></tr></tbody></span>';
  292. $("#columnA").html(newcolumn);
  293. checkTsuRtg();
  294. $('body').off('click.sb_input');
  295. return $('body').on('click.sb_input', 'input.stb', function(evt) {
  296. return updateTsuRtg(evt.target);
  297. });
  298. };
  299.  
  300. main = function() {
  301. var defaultval, i, j, len, path, ref, regPatt, results;
  302. defaultval = true;
  303. path = location.pathname;
  304. regPatt = {
  305. "/$": function() {
  306. var flag;
  307. console.log("http://bangumi.tv");
  308. flag = initItemListHome();
  309. addBtnHome();
  310. if (flag) {
  311. return refreshIndexList(['line_odd clearit', 'line_even clearit'], '.sideTpcList', 'li');
  312. }
  313. },
  314. "/rakuen/topiclist": function() {
  315. var flag;
  316. console.log("/rakuen");
  317. flag = initItemList();
  318. if (flag) {
  319. refreshList();
  320. }
  321. return addBtn();
  322. },
  323. "/subject/[0-9]+$": function() {
  324. var flagrtg, flagtsu;
  325. flagtsu = GM_getValue("hidetsukkomi", defaultval);
  326. flagrtg = GM_getValue("hiderating", defaultval);
  327. hideTsukkomi(flagtsu);
  328. return hideRating(flagrtg);
  329. },
  330. "/subject_search/.*": function() {
  331. var flagrtg;
  332. flagrtg = GM_getValue("hiderating", defaultval);
  333. return hideRank(flagrtg);
  334. },
  335. "/(anime|book|music|real)/browser": function() {
  336. var flagrtg;
  337. flagrtg = GM_getValue("hiderating", defaultval);
  338. return hideRank(flagrtg);
  339. },
  340. "/group/(?!topic).+": function() {
  341. var flag;
  342. flag = initItemListGroup();
  343. addBtnGroup();
  344. if (flag) {
  345. return refreshTopicList(['topic odd', 'topic even'], '.topic');
  346. }
  347. },
  348. "/settings": function() {
  349. console.log("/settings");
  350. return addSettingBtn();
  351. }
  352. };
  353. ref = Object.keys(regPatt);
  354. results = [];
  355. for (j = 0, len = ref.length; j < len; j++) {
  356. i = ref[j];
  357. if (RegExp(i).test(path)) {
  358. results.push(regPatt[i]());
  359. } else {
  360. results.push(void 0);
  361. }
  362. }
  363. return results;
  364. };
  365.  
  366. main();