m.mysmth.net cross link

add cross links between mobile, www2 and nForum views

当前为 2021-07-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name m.mysmth.net cross link
  3. // @description add cross links between mobile, www2 and nForum views
  4. // @include https://*.mysmth.net/*
  5. // @version 1.3.2
  6. // @namespace https://greasyfork.org/users/5696
  7. // @grant none
  8. // @require https://code.jquery.com/jquery-3.5.1.min.js
  9. // ==/UserScript==
  10. function buildWww2BoardSearch(board) {
  11. return '<a href="https://www.mysmth.net/bbsbfind.php?board=' + board + '">搜索</a>';
  12. }
  13. function buildMobileArticleLink(board, tid) {
  14. return '<a href="https://m.mysmth.net/article/' + board + '/single/' + tid + '/0">手机版</a>';
  15. }
  16. function buildWww2ArticleDeleteLink(bid, tid) {
  17. return '<a href="https://www.mysmth.net/bbsdel.php?bid=' + bid + '&id=' + tid + '">www2</a>';
  18. }
  19. function buildMobileThreadLink(board, gid, start, page) {
  20. if (start !== null) {
  21. return '<a href="https://m.mysmth.net/article/' + board + '/' + gid + '/?s=' + start + '">手机版</a>';
  22. }
  23. page = (page !== null) ? '/?p=' + page : '';
  24. return '<a href="https://m.mysmth.net/article/' + board + '/' + gid + page + '">手机版</a>';
  25. }
  26. function buildNforumThreadLink(board, tid, page) {
  27. page = (page !== null && !isNaN(page)) ? '?p=' + page : '';
  28. return '<a href="https://www.mysmth.net/nForum/#!article/' + board + '/' + tid + page + '">nForum</a>';
  29. }
  30. function buildMobileThreadBoardLink(board, page) {
  31. page = (page !== null) ? '/?p=' + page : '';
  32. return '<a href="https://m.mysmth.net/board/' + board + page + '">手机版</a>';
  33. }
  34. function buildNforumThreadBoardLink(board, page) {
  35. page = (page !== null) ? '?p=' + page : '';
  36. return '<a href="https://www.mysmth.net/nForum/#!board/' + board + page + '">nForum</a>';
  37. }
  38.  
  39. function buildLoginForm(multiline) {
  40. $form = $('<form id="loginform" action="/user/login" method="post"></form>');
  41. $form.append('用户: <input id="userid" name="id" type="input" value="moudy">');
  42. $form.append((multiline)?'<br/>':'&nbsp;');
  43. $form.append('密码: <input id="passwd" name="passwd" type="password">');
  44. $form.append((multiline)?'<br/>':'&nbsp;');
  45. $form.append('<input id="TencentCaptcha" data-appid="2068091125" data-cbfn="captchaSuccess" type="button" value="刷新">');
  46. $form.append('<input name="ticket" id="ticket2" value="" type="hidden">');
  47. $form.append('<input name="randstr" id="randstr2" value="" type="hidden">');
  48. return $form;
  49. }
  50.  
  51. function mobileLogin() {
  52. $("#TencentCaptcha").attr("value", "正在登陆");
  53. $.ajax({
  54. url: "https://m.mysmth.net/user/login",
  55. method: "POST",
  56. data: $('form').serialize(),
  57. complete: function() { window.location.href = window.location.href+(window.location.href.includes("?")?"&":"?") + "reload="+Date.parse(new Date()); },
  58. error: function(xhr, status, error) { console.log(status); alert(error); },
  59. success: function(doc, status, xhr) { $("#TencentCaptcha").attr("value", "登陆成功"); }
  60. });
  61. }
  62.  
  63. function patchMobile() {
  64. if(!$("#TencentCaptcha").length) {
  65. var e = $(".sp.hl.f");
  66. if (e.length) {
  67. if ( e.text() == "您没有绑定手机号码,没有发表文章的权限"
  68. || e.text() == "您无权阅读此版面"
  69. ) {
  70. e.append(buildLoginForm(true));
  71. $("#TencentCaptcha").click(mobileLogin);
  72. return
  73. }
  74. }
  75. if(!$(".menu.nav").children("a[href*='logout']").length) {
  76. $(".menu.nav").prepend(buildLoginForm(false));
  77. }
  78. }
  79. e = document.getElementsByClassName('menu nav') [0];
  80. if (e.children.length == 9) {
  81. var str = '';
  82. if (e.children[4].innerHTML.length > 2)
  83. str += e.children[4].outerHTML + '|';
  84. if (e.children[5].innerHTML.length > 2)
  85. str += e.children[5].outerHTML + '|';
  86. if (e.children[6].innerHTML.length > 2)
  87. str += e.children[6].outerHTML;
  88. if (str.length > 0)
  89. document.getElementsByClassName('sec nav') [0].innerHTML += '||' + str;
  90. }
  91. $(".menu.sp").append(e.outerHTML);
  92. $("#TencentCaptcha").click(mobileLogin);
  93. $("form input[value='快速回复']").closest("div").remove();
  94.  
  95. s = document.getElementsByTagName('script');
  96. for (var i = 1; i < s.length; i++) {
  97. s[i].parentNode.removeChild(s[i]);
  98. }
  99.  
  100. var slist = document.getElementsByClassName('slist sec') [1];
  101. var linklist = {
  102. links: [],
  103. ptr: -1
  104. };
  105.  
  106. var httpRequest = new XMLHttpRequest();
  107. httpRequest.responseType = 'document';
  108. httpRequest.onreadystatechange = function () {
  109. if (httpRequest.readyState === 4 && httpRequest.status === 200) {
  110. if(linklist.ptr < 0)
  111. {
  112. linklist.links = httpRequest.response.getElementsByClassName('nav sec') [0].children;
  113. linklist.ptr++;
  114. }
  115. else
  116. {
  117. var slist2 = httpRequest.response.getElementsByClassName('slist sec') [0];
  118. slist.parentNode.insertBefore(slist2, slist.nextSibling);
  119. slist = slist2;
  120. }
  121.  
  122. if (linklist.ptr >= linklist.links.length)
  123. {
  124. return;
  125. }
  126. linklist.ptr++;
  127. var url = "https://m.mysmth.net" + linklist.links[linklist.ptr].getAttribute('href');
  128. httpRequest.open('GET', url, true);
  129. httpRequest.send();
  130. }
  131. };
  132. var url = "https://m.mysmth.net/hot";
  133. httpRequest.open('GET', url, true);
  134. httpRequest.send();
  135. }
  136. function patchMobileThreadBoard() {
  137. var match = /https?:\/\/m\.mysmth\.net\/board\/(\w+)(\/?\?p=(\d+))?/.exec(document.URL);
  138. var board = match[1];
  139. var page = match[3];
  140. var nav = document.getElementsByClassName('nav sec') [0];
  141. nav.innerHTML = nav.innerHTML + '||' + buildNforumThreadBoardLink(board, page) + '||' + buildWww2BoardSearch(board);
  142. //list
  143. list = document.getElementsByClassName('list sec') [0].children;
  144. for (var i = 0; i < list.length; i++) {
  145. li = list[i];
  146. t = li.children[0];
  147. a = li.children[1];
  148. d = a.textContent.substring(0, 10);
  149. var ta1 = t.childNodes[0];
  150. var ta2 = document.createElement('a');
  151. var ta3 = a.children[0];
  152. var ta4 = a.children[1];
  153. var span = document.createElement('span');
  154. ta1.title = li.textContent;
  155. if(d.match(/^\d{4}-\d{2}-\d{2}$/) && Date.now()-Date.parse(d) > 7*24*60*60*1000) {
  156. ta1.text = "(坟)"+ta1.text;
  157. }
  158. ta2.text = t.childNodes[1].textContent;
  159. ta2.href = ta1.href + '?p=' + Math.floor(parseInt(/\((\d+)\)/.exec(t.childNodes[1].textContent) [1]) / 10 + 1);
  160. t.replaceChild(ta2, t.childNodes[1]);
  161. t.appendChild(span);
  162. span.appendChild(ta3);
  163. span.appendChild(ta4);
  164. $(span).css("font-size", "x-small");
  165. $(span).find("a").css("margin-left", "5px");
  166. li.removeChild(a);
  167. }
  168. }
  169. function patchMobileThread() {
  170. var match = /https?:\/\/m\.mysmth\.net\/article\/(\w+)\/(\d+)(\?p=(\d+))?/.exec(document.URL);
  171. var board = match[1];
  172. var gid = match[2];
  173. var page = match[4];
  174. var start = 0;
  175. $('.nav.hl').each(function() {
  176. $(this).find("a[href*='/forward/']").each(function() {
  177. match = /\/\w+\/forward\/(\d+)/.exec($(this).attr("href"));
  178. start = match[1];
  179. $(this).append('|' + buildMobileArticleLink(board, start).replace('手机版', '单文'))
  180. $(this).append('|' + buildWww2ArticleDeleteLink(board, start).replace('www2', '删除'))
  181. });
  182. });
  183. $(".nav.sec").first().append('||' + buildNforumThreadLink(board, gid, page) + '||' + buildWww2BoardSearch(board));
  184. }
  185. function patchMobileArticle() {
  186. var match = /https?:\/\/m\.mysmth\.net\/article\/(\w+)\/(\d+)\?s=(\d+)/.exec(document.getElementsByClassName('sec nav') [0].childNodes[2].href);
  187. var board = match[1];
  188. var gid = match[2];
  189. var start = match[3];
  190. var nav = document.getElementsByClassName('nav sec') [0];
  191. nav.innerHTML = nav.innerHTML + '||' + buildNforumThreadLink(board, gid) + '||' + buildWww2BoardSearch(board);
  192. }
  193. function patchMobileArticleBoard() {
  194. var match = /https?:\/\/m\.mysmth\.net\/board\/(\w+)\/0(\?p=(\d+))?/.exec(document.URL);
  195. var board = match[1];
  196. var page = match[3];
  197. var nav = document.getElementsByClassName('nav sec') [0];
  198. nav.innerHTML = nav.innerHTML + '||' + buildNforumThreadBoardLink(board) + '||' + buildWww2BoardSearch(board);
  199. }
  200. function patchMobilePost() {
  201. var btns = document.getElementsByClassName('btn') [0].parentElement;
  202. var button = document.createElement('input');
  203. button.type = 'button';
  204. button.value = 'IMG';
  205. button.className = 'btn';
  206. button.onclick = function () {
  207. var textarea = document.getElementsByName('content') [0];
  208. var newvalue = textarea.value.substring(0, textarea.selectionStart);
  209. newvalue += '[img=';
  210. newvalue += textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
  211. newvalue += '][/img]'
  212. newvalue += textarea.value.substring(textarea.selectionEnd);
  213. textarea.value = newvalue;
  214. }
  215. }
  216. function patchWww2FindResult() {
  217. var match = /https?:\/\/www\.mysmth\.net\/bbsbfind\.php\?.*\bboard=(\w+)\b/.exec(document.URL);
  218. var board = match[1];
  219. var links = $("a[href*='bbscon']").each(function() {
  220. var id = /\bid=(\d+)/.exec($(this).attr("href"))[1]
  221. $(this).attr("href", "https://m.mysmth.net/article/"+board+"/single/"+id+"/0");
  222. });
  223. }
  224. function patchNforumThread() {
  225. var match = /https?:\/\/www\.mysmth\.net\/nForum\/#!article\/(\w+)\/(\d+)(\?p=(\d+))?/.exec(document.URL);
  226. var board = match[1];
  227. var gid = match[2];
  228. var page = match[4];
  229. var nav = document.getElementById('notice');
  230. nav.innerHTML += '&ensp;&ensp;【' + buildMobileThreadLink(board, gid, null, page).replace('href', 'onclick="javascript: window.location=this.href" href') + '】';
  231. }
  232. function patchNforumThreadBoard() {
  233. var match = /https?:\/\/www\.mysmth\.net\/nForum\/#!board\/(\w+)(\/?\?p=(\d+))?/.exec(document.URL);
  234. var board = match[1];
  235. var page = match[3];
  236. var nav = document.getElementById('notice');
  237. nav.innerHTML += '&ensp;&ensp;【' + buildMobileThreadBoardLink(board, page).replace('href', 'onclick="javascript: window.location=this.href" href') + '】';
  238. }
  239.  
  240. if (document.URL.match(/^https?:\/\/m\.mysmth\.net\/\W?/)) {
  241. patchMobile();
  242. }
  243.  
  244.  
  245. if($(".menu.sp").text().includes("发生错误")) {
  246. // do nothing
  247. } else if (document.URL.match(/https?:\/\/wap\.mysmth\.net\/index/)) {
  248. window.location.href = "https://m.mysmth.net/index";
  249. } else if (document.URL.match(/https?:\/\/m\.mysmth\.net\/article\/\w+\/(\d+)/)) {
  250. patchMobileThread();
  251. } else if (document.URL.match(/https?:\/\/m\.mysmth\.net\/board\/\w+\/0(\?p=(\d+))?/)) {
  252. patchMobileArticleBoard();
  253. } else if (document.URL.match(/https?:\/\/m\.mysmth\.net\/board\/\w+(p=(\d+))?/)) {
  254. patchMobileThreadBoard();
  255. } else if (document.URL.match(/https?:\/\/m\.mysmth\.net\/article\/\w+\/single\/(\d+)/)) {
  256. patchMobileArticle();
  257. } else if (document.URL.match(/https?:\/\/m\.mysmth\.net\/article\/\w+\/post/)) {
  258. patchMobilePost();
  259. } else if (document.URL.match(/https?:\/\/m\.mysmth\.net\/article\/\w+\/edit/)) {
  260. patchMobilePost();
  261. } else if (document.URL.match(/https?:\/\/www\.mysmth\.net\/bbsbfind\.php\?.*\bboard=(\w+)\b/)) {
  262. patchWww2FindResult();
  263. } else if (document.URL.match(/https?:\/\/www\.mysmth\.net\/nForum\/#!article\/(\w+)\/(\d+)/)) {
  264. patchNforumThread();
  265. } else if (document.URL.match(/https?:\/\/www\.mysmth\.net\/nForum\/#!board\/(\w+)/)) {
  266. patchNforumThreadBoard();
  267. }