NGA Subscribe Tool

NGA 订阅工具,在打开页面时检测关注的作者是否发布了新帖,若是则在进入版面时弹出提醒(在帖子内不提醒)

  1. // ==UserScript==
  2. // @name NGA Subscribe Tool
  3. // @namespace https://gf.qytechs.cn/zh-CN/scripts/38841-nga-subscribe-tool
  4. // @version 0.1.2.20180413
  5. // @icon http://bbs.nga.cn/favicon.ico
  6. // @description NGA 订阅工具,在打开页面时检测关注的作者是否发布了新帖,若是则在进入版面时弹出提醒(在帖子内不提醒)
  7. // @author AgLandy
  8. // @include /^https?:\/\/(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn)/(thread\.php\?(f|st)id|read).+/
  9. // @grant none
  10. // @require https://gf.qytechs.cn/scripts/39014-nga-user-script-loader/code/NGA%20User%20Script%20Loader.js
  11. // ==/UserScript==
  12.  
  13. //发布地址:http://bbs.ngacn.cc/read.php?tid=13525229
  14.  
  15. (function(){
  16.  
  17. function init(usl){
  18.  
  19. let $ = usl.$,
  20. st = commonui.subscribeTool = {
  21. init: function(){
  22. let data = {s: 0};
  23. if(localStorage.subscribeToolData)
  24. data = JSON.parse(localStorage.subscribeToolData);
  25. else{
  26. data[8143443] = {'name': '奥妮酱', 'read': 1};
  27. localStorage.subscribeToolData = JSON.stringify(data);
  28. }
  29. return data;
  30. },
  31. cache: {},
  32. f: function(ck){
  33. let noti = commonui.notification,
  34. go = function(){
  35. for(let i = 0; i < ck.length; i++){
  36. let t = st.cache[ck[i]],
  37. s = commonui.cutstrbylen(t[2],19);
  38. if(s.length < t[2].length)
  39. s += '...';
  40. $('<span><b style="color:blue">&#9632;</b> <span class="silver">' +
  41. commonui.time2dis(ck[i]) +
  42. ' <a class="b" target="_blank" href="/nuke.php?func=ucp&uid=' + t[1] + '">' +
  43. t[0] +
  44. '</a> 发布了主题 <nobr><a class="b" href="' + t[3] + '" title="' + t[2] + '" target="_blank">' +
  45. s +
  46. '</a></nobr><br></span></span>').prependTo('div.single_ttip2 div.div1:has(span.title:contains("提醒信息")) td:eq(0)'); //js_notification.js
  47. st.data[t[1]].read = 1;
  48. localStorage.subscribeToolData = JSON.stringify(st.data);
  49. }
  50. st.cache = {};
  51. };
  52. if(!noti.box)
  53. noti.createBox();
  54. if(noti.box.style.display != 'none')
  55. return go();
  56. if(!document.body)
  57. return window.setTimeout(function(){st.f(ck);}, 3000);
  58. if(noti.box.parentNode != document.body)
  59. document.body.appendChild(noti.box);
  60. noti.box._.show(0, 0);
  61. if(noti.box.offsetHeight > __NUKE.position.get().ch){
  62. if(noti.box.style.position != 'absolute')
  63. noti.box.style.position = 'absolute';
  64. if(noti.timeout)
  65. window.clearInterval(noti.timeout);
  66. }
  67. else{
  68. if(noti.box.style.position != 'fixed')
  69. noti.box.style.position = 'fixed';
  70. if(window.__UA && __UA[0] == 1 && __UA[1] <= 6)
  71. noti.timeout = window.setInterval(function(){commonui.notification.checkPos();}, 3000);
  72. } //notification.js commonui.notification.openBox
  73. go();
  74. },
  75. r: function(){
  76. //在帖子中为除自己以外的楼层添加关注按钮
  77. if(usl.lS && $('a[name="uid"]')[0]){
  78. $('a[name="uid"]').next().remove(); //去除已有的按钮
  79. $('a[name="uid"]').closest('td').unbind('.stBtn'); //解绑悬停事件
  80. $('a[name="uid"]').each(function(i, uid){
  81. let a = $(uid),
  82. u = a.text();
  83. if(u == __CURRENT_UID)
  84. return;
  85. a.parent().css({'position':'relative'});
  86. let d = $('<span style="font:15px/16px Serif;vertical-align:bottom;margin-left:3px;color:#ff7800;cursor:pointer;' + (st.data.s ? '' : 'display:none;') + '" />').html(st.data[u] ? '♥' : '♡').click(function(){
  87. d.html(st.data[u] ? '♡' : '♥');
  88. st.data[u] = st.data[u] ? null : {'name': commonui.posterInfo.uI.users[u].username, 'read': 1};
  89. localStorage.subscribeToolData = JSON.stringify(st.data);
  90. }).insertAfter(a);
  91. if(!st.data.s)
  92. a.closest('td').bind({
  93. 'mouseenter.stBtn': function(){d.fadeIn();},
  94. 'mouseleave.stBtn': function(){d.fadeOut();}
  95. });
  96. }); //添加按钮及绑定事件
  97. }
  98.  
  99. //检测是否有关注作者的新帖
  100. let n = 0;
  101. if(usl.lS)
  102. $.each(st.data, function(k, v){
  103. if(v == null || k == 's'){
  104. n++;
  105. return;
  106. } //取消关注的作者跳过检测
  107. if(commonui.postArg && commonui.postArg.data[0] && commonui.postArg.data[0].pAid == k && __CURRENT_TID > v.lastTid){
  108. v.lastTid = __CURRENT_TID;
  109. v.read = 1;
  110. localStorage.subscribeToolData = JSON.stringify(st.data);
  111. n++;
  112. return;
  113. } //若当前页为关注作者的新帖首页则不再提示该帖
  114. $.post('thread.php?order_by=postdatedesc&authorid=' + k, 'lite=xml', function(response){
  115. let t = $(response).find('__T item:eq(0)'),
  116. tid = parseInt(t.find('tid').text()),
  117. postdate = parseInt(t.find('postdate').text()),
  118. author = t.find('author').text(),
  119. authorid = t.find('authorid').text(),
  120. subject = t.find('subject').text(),
  121. url = t.find('tpcurl').text();
  122. if(tid > v.lastTid){
  123. v.read = 0;
  124. if(authorid != '0')
  125. st.cache[postdate] = [author, authorid, subject, url];
  126. }
  127. else if(authorid != '0' && v.read == 0){
  128. st.cache[postdate] = [author, authorid, subject, url];
  129. }
  130. v.lastTid = tid;
  131. localStorage.subscribeToolData = JSON.stringify(st.data);
  132. n++;
  133. });
  134. });
  135.  
  136. //版面中显示关注作者头像及新帖提醒
  137. if(/\/thread\.php\?(f|st)id.+$/.test(window.location.href)){
  138. //新帖提醒
  139. if(usl.lS)
  140. (function check(){
  141. if(st.check){
  142. if(st.check > 20){
  143. st.lastCheck = 'timeout';
  144. delete st.check;
  145. st.cache = {};
  146. return;
  147. }
  148. else
  149. st.check++;
  150. }
  151. else
  152. st.check = 1;
  153.  
  154. if(n == Object.keys(st.data).length){
  155. st.lastCheck = st.check;
  156. delete st.check;
  157. let ck = Object.keys(st.cache);
  158. if(ck[0])
  159. if(commonui.notification)
  160. st.f(ck);
  161. else
  162. commonui.loadNotiScript(function(){
  163. st.f(ck);
  164. });
  165. }
  166. else
  167. setTimeout(function(){
  168. check();
  169. },150);
  170. })();
  171.  
  172. //显示关注作者头像
  173. let authors = $('div#mc a[href^="/nuke.php?func=ucp&uid="]');
  174. if(!authors[0])
  175. return;
  176. authors.each(function(i, author){
  177. let uid = author.title.replace(/\D/g, '');
  178. if(!st.data[uid] || $(author).prev('div:has(img)')[0])
  179. return;
  180. $.post('nuke.php?__lib=ucp&__act=get&uid=' + uid, '__output=12', function(response){
  181. if(!response.result.avatar)
  182. return;
  183. let a = commonui.selectAvatar(response.result.avatar, __CURRENT_UID),
  184. td = author.parentNode,
  185. rp = td.getClientRects()[0],
  186. h = rp.bottom - rp.top,
  187. d = _$('/div').$0(
  188. 'style', {
  189. borderRight: '1px solid ' + __COLOR.bg0,
  190. overflow: 'hidden',
  191. width: h + 'px',
  192. height: h + 'px',
  193. cssFloat: 'left',
  194. margin: '-6px 0 -6px -' + h + 'px'
  195. },
  196. _$('/img').$0(
  197. 'onload', function(){
  198. let r;
  199. if(this.height > this.width){
  200. r = h / this.width;
  201. this.width = h;
  202. this.height *= r;
  203. this.style.marginTop = (Math.abs(h - this.height) / 3 * -1) + 'px';
  204. }
  205. else{
  206. r = h / this.height;
  207. this.height = h;
  208. this.width *= r;
  209. this.style.marginLeft = (Math.abs(h - this.width) / 2 * -1) + 'px';
  210. }
  211. this.style.opacity = 0.7;
  212. this.style.display = '';
  213. },
  214. 'style', {display:'none'},
  215. 'src', a
  216. )
  217. );
  218. td.style.paddingLeft = h + 'px';
  219. $(author).before(d); //forum.js commonui.loadThreadInfoSetAvatar
  220. });
  221. });
  222. }
  223. }
  224. };
  225.  
  226. commonui.mainMenu.data[402] = {innerHTML: '订阅按钮设置', on: {event: 'click', func: function(e){
  227. let o = __SETTING.o = commonui.createadminwindow(),
  228. k = _$('/input').$0('type','checkbox','checked',0)._.on('click', function(){
  229. st.data.s = this.checked ? 0 : 1;
  230. localStorage.subscribeToolData = JSON.stringify(st.data);
  231. st.r();
  232. });
  233. o._.addContent(null);
  234. o._.addTitle('订阅按钮设置');
  235. o._.addContent(
  236. k,
  237. '悬停显示',
  238. _$('/br')
  239. );
  240. if(!st.data.s)
  241. k._.attr('checked', 1);
  242. o._.show(e);
  243. }}, parent: 18};
  244. commonui.mainMenu.data[18].subKeys.push(402);
  245.  
  246. st.data = usl.lS ? st.init() : {'8143443':{'name':'奥妮酱'}, s: 0};
  247.  
  248. st.r();
  249.  
  250. if(!usl.userScriptData.stBtn)
  251. usl.userScriptData.stBtn = st.r;
  252.  
  253. }
  254.  
  255. (function check(){
  256. try{
  257. if(commonui.userScriptLoader.$)
  258. init(commonui.userScriptLoader);
  259. else
  260. setTimeout(check, 5);
  261. }
  262. catch(e){
  263. setTimeout(check, 50);
  264. }
  265. })();
  266.  
  267. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址