JS practice for S1

JS练习脚本

当前为 2018-01-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name JS practice for S1
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.131
  5. // @description JS练习脚本
  6. // @author Lery
  7. // @include /^([^\.]+\.)?(saraba1st|stage1(st)?)\.(com|cc)/2b/.*
  8. // @grant GM_xmlhttpRequest
  9. // @require https://cdn.bootcss.com/store.js/1.3.20/store+json2.min.js
  10. // ==/UserScript==
  11.  
  12. //自动对旧链接进行修改跳转
  13. let pattern0 = new RegExp('^([^.]+\\.)?(saraba1st|stage1(st)?)\\.(com|cc)/2b/read');
  14. if(pattern0.test(document.URL)){
  15. location.href="https://" + location.hostname + "/2b/thread-" + location.href.split("tid-")[1].split(".html")[0] + "-1-1.html";
  16. }
  17.  
  18. //修改网页标题后缀
  19. let pattern1 = new RegExp('^(?:论坛|.+?)(?=(?:论坛)?(?: - Stage1st)? - stage1\\/s1 游戏动漫论坛$)');
  20. if(pattern1.test(document.title)){
  21. document.title = pattern1.exec(document.title) + " - STAGE1";
  22. }
  23.  
  24. //自动签到
  25. if(document.querySelector('a[href*="study_daily_attendance-daily_attendance.html"]')){
  26. ajaxget(document.querySelector('a[href*="study_daily_attendance-daily_attendance.html"]').href);
  27. document.querySelector('a[href*="study_daily_attendance-daily_attendance.html"] + .pipe').remove();
  28. document.querySelector('a[href*="study_daily_attendance-daily_attendance.html"]').remove();
  29. }
  30.  
  31. //点击更换漫区随机图
  32. if(document.querySelector('img[src^="http://ac.stage3rd.com/S1_ACG_randpic.asp"]')){
  33. let changepic = document.querySelector('img[src^="http://ac.stage3rd.com/S1_ACG_randpic.asp"]');
  34. changepic.onclick = function(){
  35. document.querySelector('img[src^="http://ac.stage3rd.com/S1_ACG_randpic.asp"]').src="http://ac.stage3rd.com/S1_ACG_randpic.asp"+"?t=" + Math.random();
  36. };
  37. }
  38.  
  39. //自定义快捷入口
  40. function createLink(name, addr) {
  41. let node = document.createElement("li");
  42. if(window.location.pathname == "/2b/" + addr)
  43. node.className = "a";
  44. let link = document.createElement("a");
  45. link.setAttribute("href",addr);
  46. link.setAttribute("hidefocus","true");
  47. link.appendChild(document.createTextNode(name));
  48. node.appendChild(link);
  49. return node;
  50. }
  51.  
  52. /*找到导航栏位置*/
  53. document.getElementsByTagName("h2")[0].childNodes[0].setAttribute("href", "./forum.php");
  54. var linkList = document.getElementById("nv").getElementsByTagName("ul")[0];
  55.  
  56. /*增加快捷入口*/
  57. GM_xmlhttpRequest({
  58. method: "GET",
  59. url: "https://" + location.hostname + "/2b/forum.php?mod=ajax&action=forumjump",
  60. onload: function(data){
  61. let pattern = new RegExp('<div id="flsrchdiv">[\\s\\S]+(?=<script type)');
  62. let xmldata = pattern.exec(data.response);
  63. let parser = new DOMParser();
  64. doc = parser.parseFromString(xmldata, "application/xml");
  65. let forumItems = doc.querySelectorAll('.jump_bdl li:nth-child(3) p a');
  66. /*删除原快捷入口*/
  67. while(linkList.firstChild) {
  68. linkList.removeChild(linkList.firstChild);
  69. }
  70. /*生成新快捷入口*/
  71. if(forumItems.length >= 1){
  72. let pattern = new RegExp('.*?(?=论坛|$)');
  73. for(let i = 0; i < forumItems.length; i++){
  74. let item = forumItems[i];
  75. let itemText = pattern.exec(item.textContent);
  76. let href = item.getAttribute('href');
  77. linkList.appendChild(createLink(itemText,href));
  78. }
  79. }
  80. /*在此处添加您的自定义快捷入口,格式为 linkList.appendChild(createLink("入口名称","主域名/2b/后面的地址")); ,参考下面提供的默认项*/
  81. linkList.appendChild(createLink("抹布","home.php?mod=space&do=friend&view=blacklist"));
  82. linkList.appendChild(createLink("客户端","thread-1486168-1-1.html"));
  83. linkList.appendChild(createLink("我的回复","forum.php?mod=guide&view=my&type=reply"));
  84. }
  85. });
  86.  
  87. //记录并显示上次阅读的界面
  88. let pattern5 = new RegExp('forum\\.php\\?mod=(forumdisplay|viewthread)|(forum|thread)(-[0-9]+)+\\.html');
  89. if(pattern5.test(document.URL)){
  90. if (!store.enabled) {
  91. alert('浏览器不支持本地缓存或开启了私隐模式,功能将失效。');
  92. }else{
  93. let lastread = store.get('lastread') ? store.get('lastread') : {};
  94. let lastrc = store.get('lastrc') ? store.get('lastrc') : {};
  95. if(unsafeWindow.tid){
  96. GM_xmlhttpRequest({
  97. method: "GET",
  98. url: "https://" + location.hostname + "/2b/api/mobile/index.php?module=viewthread&tid=" + unsafeWindow.tid,
  99. onload: function(data){
  100. let json = JSON.parse(data.responseText);
  101. var replies = json.Variables.thread.replies;
  102. replies = replies ? replies : 1;
  103. lastrc[unsafeWindow.tid] = replies;
  104. store.set('lastrc', lastrc);
  105. }
  106. });
  107. let page = document.querySelector('#pgt > div > div > strong');
  108. page = page ? page.textContent : 1;
  109. lastread[unsafeWindow.tid] = page;
  110. store.set('lastread', lastread);
  111. }else{
  112. let table = document.getElementsByName('moderate')[0].children[2];
  113. if(table) {
  114. let tbodys = table.getElementsByTagName('tbody');
  115. for(i = 0;i < tbodys.length;i++) {
  116. let tbody = tbodys[i];
  117. let [ordertype, tid] = tbody.id.split('_');
  118. if(tid){
  119. let page = lastread[tid];
  120. if(page){
  121. let oldrc = lastrc[tid];
  122. let ele = document.createElement('a');
  123. ele.style.color = '#C03322';
  124. ele.style.fontWeight = 'bold';
  125. ele.style.padding = '1px 3px';
  126. ele.style.border = '1px solid #C03322';
  127. ele.text = '回第' + page + '页';
  128. let prevpage = document.querySelector('#pgt > div > strong');
  129. prevpage = prevpage ? prevpage.textContent : 1;
  130. if(document.querySelector('#' + tbody.id + ' a').href.indexOf("forum.php")!=-1){
  131. ele.href = 'forum.php?mod=viewthread&tid=' + tid + '&extra=page%3D' + prevpage + '&page=' + page;
  132. }else{
  133. ele.href = 'thread-' + tid + '-' + page + '-' + prevpage + '.html';
  134. }
  135. let currentrc = parseInt(document.querySelector('#' + tbody.id + ' > tr > .num > .xi2').innerHTML);
  136. if(currentrc > oldrc) {
  137. let rc = document.createElement('div');
  138. let node=document.createTextNode('+' + String(currentrc - oldrc));
  139. rc.appendChild(node);
  140. rc.style.display = 'inline';
  141. rc.style.color = '#F6F7EB';
  142. rc.style.backgroundColor = '#C03322';
  143. rc.style.fontWeight = 'bold';
  144. rc.style.padding = '1px 3px 1px 1px';
  145. rc.style.border = '1px solid #C03322';
  146. rc.style.borderRadius = '0 4px 4px 0';
  147. ele.style.borderRadius = '4px 0 0 4px';
  148. document.querySelector('#' + tbody.id + ' > tr > th').appendChild(ele);
  149. document.querySelector('#' + tbody.id + ' > tr > th').appendChild(rc);
  150. }else{
  151. ele.style.borderRadius = '4px';
  152. document.querySelector('#' + tbody.id + ' > tr > th').appendChild(ele);
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }

QingJ © 2025

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