JS practice for S1

JS练习脚本

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

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

QingJ © 2025

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