m.mysmth.net cross link

add cross links between mobile, www2 and nForum views

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

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