JavBus论坛移动端界面适配

使司机社(JavBus)的论坛适应移动端界面

As of 2023-12-12. See the latest version.

  1. // ==UserScript==
  2. // @name JavBus论坛移动端界面适配
  3. // @namespace https://github.com/Steven-Fake/JavBus-forum-mobile-layout
  4. // @homepageURL https://sleazyfork.org/zh-CN/users/1140711-steven-fake
  5. // @version 1.1.1
  6. // @license MIT
  7. // @description 使司机社(JavBus)的论坛适应移动端界面
  8. // @author Steven-Fake
  9. // @icon https://www.javbus.com/favicon.ico
  10. // @match https://www.javbus.com/forum*
  11. // @match https://www.buscdn.cfd/forum*
  12. // @match https://www.buscdn.lol/forum*
  13. // @match https://www.busfan.cfd/forum*
  14. // @match https://www.busfan.lol/forum*
  15. // @match https://www.cdnbus.cfd/forum*
  16. // @match https://www.cdnbus.lol/forum*
  17. // @match https://www.dmmbus.cfd/forum*
  18. // @match https://www.dmmbus.lol/forum*
  19. // @match https://www.dmmsee.cfd/forum*
  20. // @match https://www.dmmsee.lol/forum*
  21. // @match https://www.javsee.cfd/forum*
  22. // @match https://www.javsee.lol/forum*
  23. // @match https://www.seejav.cfd/forum*
  24. // @match https://www.seejav.lol/forum*
  25. // @grant none
  26. // ==/UserScript==
  27.  
  28.  
  29. (function () {
  30. //使用adjust变量来判断是否需要调整为移动端布局,并添加监听事件
  31. const adjust = window.innerHeight > window.innerWidth && window.innerWidth < 1600;
  32. if (adjust) {
  33. console.log("JavBus论坛移动端界面适配v1.1.1: 启用移动端布局");
  34. const pageType = ((url) => {
  35. if (url.includes("tid=")) {
  36. return "post";
  37. } else if (url.includes("uid=")) {
  38. return "profile";
  39. } else if (url.includes("action=login")) {
  40. return "login";
  41. } else if (url.includes("search.php")) {
  42. return "search";
  43. } else {
  44. return "index";
  45. }
  46. })(window.location.href);
  47.  
  48. /* 注入自适应调整的meta标签 */
  49. const appendMeta = document.createElement("meta");
  50. appendMeta.name = "viewport";
  51. appendMeta.content = "width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no";
  52. document.head.appendChild(appendMeta);
  53.  
  54. /* 调整无用元素
  55. * 1. 移除顶部广告
  56. * 2. 删除本就隐藏的元素
  57. * */
  58. if (pageType !== "search") {
  59. try {
  60. //1.移除顶部广告
  61. document.getElementsByClassName("bcpic2")[0].remove();
  62. } catch (e) {
  63. console.log("JavBus论坛移动端界面适配v1.1.1: 尝试移除顶部广告时出错。");
  64. }
  65. try {
  66. //2.删除本就隐藏的元素
  67. document.getElementById("myprompt_menu").remove();
  68. document.getElementById("myitem_menu").remove();
  69. document.getElementById("qmenu_menu").remove();
  70. document.getElementsByClassName("wp cl")[0].remove();
  71. } catch (e) {
  72. console.log("JavBus论坛移动端界面适配v1.1.1: 尝试删除无用元素时出错。");
  73. }
  74. }
  75.  
  76. /* 调整顶栏
  77. * 1. 删除logo
  78. * 2. 调整导航栏样式
  79. * 3. 调整搜索框样式
  80. * 4. 清除顶栏的无用元素
  81. * 5. 将个人信息按钮移动到nav中
  82. * 6. 隐藏ID
  83. * */
  84. if (pageType !== "search") {
  85. //1. 删除logo
  86. document.getElementsByClassName("jav-logo")[0].remove();
  87. //2. 调整导航栏样式
  88. const nav = document.getElementById("toptb");
  89. nav.style.cssText = "width: 100%; min-width: 0; padding: 0;";
  90. nav.children[0].style.cssText = "width: 100%; padding: 0; margin: 0;";
  91. nav.children[0].children[0].style.cssText = "width: 100%; padding: 0; margin: 0;";
  92. //3. 调整搜索框样式
  93. const search_div = document.getElementsByClassName("jav-form-group")[0];
  94. search_div.style.cssText = "width: 35%; min-width: 0;";//调整宽度
  95. search_div.children[0].style.cssText = "width: 50%; margin-left: 5%;";//调整宽度
  96. search_div.children[1].style.cssText = "width: 35%; min-width: 50px; margin-right: 0;";//调整宽度
  97. search_div.outerHTML = '<li>' + search_div.outerHTML + '</li>';
  98. //4. 清除顶栏的无用元素
  99. document.querySelectorAll('.nav-title.nav-inactive').forEach(function (e) {
  100. e.remove();
  101. });
  102. //5.将个人信息按钮移动到nav中
  103. const info_li = document.createElement("li");
  104. info_li.appendChild(document.getElementsByClassName("login-wrap y")[0]);
  105. nav.getElementsByClassName("z")[0].children[0].appendChild(info_li);
  106. //6.隐藏ID
  107. document.getElementsByClassName("member-name")[0].remove();
  108.  
  109. /*调整主要内容
  110. * 1. 调整主内容的布局
  111. * 2. 删除层级导航栏
  112. * */
  113. //1.调整主内容的布局
  114. const main_wrapper_div = document.getElementById("wp");
  115. main_wrapper_div.style.cssText = "width: 100%; min-width: 0; padding: 0;";
  116. const main_div = document.getElementsByClassName("mn")[0];
  117. main_div.style.cssText = "width: 100%; min-width: 0; padding: 0;";
  118. //2.删除层级导航栏
  119. if (pageType === "post") {
  120. document.getElementById("pt").children[0].remove();
  121. } else if (pageType === "index") {
  122. document.getElementById("pt").children[1].remove();
  123. document.getElementById("chart").children[1].style.float = "left";//调整部分选项为右浮动
  124. }
  125.  
  126. //轮播图片框和帖子推荐列表
  127. if (pageType === "index") {
  128. const carousel_div = main_div.firstElementChild;
  129. //调整宽度
  130. carousel_div.style.cssText = "width: 100%; min-width: 0; padding: 0; height: auto;";
  131. //调整轮播图片框
  132. carousel_div.children[0].style.cssText = "float: none; width: 100%; height: auto;";
  133. //调整轮播图片框右侧的div
  134. carousel_div.children[1].style.cssText = "margin: 0; margin-top: 10px; width: 100%; height: auto;";
  135. //帖子推荐列表
  136. const post_list_div = document.getElementsByClassName("sideMenu");
  137. for (let i = 0; i < post_list_div.length; i++) {
  138. let sideMenu = post_list_div[i];
  139. for (let j = 0; j < sideMenu.childElementCount; j++) {
  140. sideMenu.children[j].style.width = "100%";
  141. sideMenu.children[j].firstChild.remove(); //删除发帖用户的名称
  142. }
  143. }
  144. //两个分区板块
  145. const comprehensive_tbody = document.getElementsByClassName("fl_tb")[0].firstElementChild;
  146. const welfare_tbody = document.getElementsByClassName("fl_tb")[1].firstElementChild;
  147. for (let i = 0; i < comprehensive_tbody.childElementCount; i++) {//调整“综合交流区”布局
  148. let area_tr = comprehensive_tbody.children[i]; //分区(tr)
  149. for (let j = 0; j < area_tr.childElementCount; j++) {
  150. let area_td = area_tr.children[j]; //分区的各项描述信息td
  151. if (j !== 0 && j !== 1) {//j=0是分区的图标,j=1是其他信息的目标td
  152. area_tr.children[1].innerHTML += area_td.outerHTML;
  153. area_td.style.display = "none";
  154. }
  155. }
  156. }
  157. for (let i = 0; i < welfare_tbody.childElementCount; i++) {//调整“福利讨论分区”布局
  158. let area_tr = welfare_tbody.children[i]; //分区(tr)
  159. for (let j = 0; j < area_tr.childElementCount; j++) {
  160. let area_td = area_tr.children[j]; //分区的各项描述信息td
  161. if (j !== 0 && j !== 1) {//j=0是分区的图标,j=1是其他信息的目标td
  162. area_tr.children[1].innerHTML += area_td.outerHTML;
  163. area_td.style.display = "none";
  164. }
  165. }
  166. }
  167. }
  168. }
  169. //调整帖子和回复中的图片尺寸
  170. if (pageType === "post") {
  171. let post_td = document.getElementsByClassName("t_f");
  172. for (let i = 0; i < post_td.length; i++) {
  173. let imgs = post_td[i].getElementsByTagName("img");
  174. for (let j = 0; j < imgs.length; j++) {
  175. if (!imgs[j].src.includes("/static/image/smiley/")) {//不调整表情图片
  176. imgs[j].style.cssText = "width: 100%; height: auto;";
  177. }
  178. }
  179. }
  180. }
  181.  
  182. //调整个人信息页的发帖表格布局
  183. if (pageType === "profile") {
  184. document.querySelectorAll('.z').forEach(function (e) {
  185. e.style.width = "100%";
  186. e.style.padding = "0";
  187. });
  188. if (document.getElementsByClassName("th").length > 0) {
  189. const post_table = document.getElementsByClassName("th")[0];
  190. //按照1:4:2:1:2的比例调整各列宽度
  191. post_table.children[0].style.width = "10%";
  192. post_table.children[1].style.width = "40%";
  193. post_table.children[2].style.width = "20%";
  194. post_table.children[3].style.width = "10%";
  195. post_table.children[4].style.width = "20%";
  196. }
  197. }
  198.  
  199. //调整登录界面
  200. if (pageType === "login") {
  201. document.getElementById("ct").style.width = "100%";//调整浮窗的宽度
  202. let floatWindow = document.getElementsByClassName("biaoqi_dl");
  203. let floatWindowInfo_div = document.getElementsByClassName("rfm");
  204. let buttonWrappers_div = document.getElementsByClassName("rfm bw0");
  205. let buttons = document.getElementsByClassName("pn pnc");
  206. for (let i = 0; i < floatWindow.length; i++) {//调整浮窗的边距
  207. floatWindow[i].style.cssText = "margin-left: 0; margin-right: 0;"
  208. }
  209. for (let i = 0; i < floatWindowInfo_div.length; i++) {//调整浮窗中各条信息的边距
  210. floatWindowInfo_div[i].style.cssText = "width: 100%; padding-left: 5%;"
  211. }
  212. for (let i = 0; i < buttonWrappers_div.length; i++) {
  213. buttonWrappers_div[i].style.width = "auto";//调整按钮的宽度
  214. }
  215. for (let i = 0; i < buttons.length; i++) {
  216. buttons[i].style.width = "auto";//调整按钮的宽度
  217. }
  218. document.getElementsByClassName("f_c altw")[0].style.padding = "0"; //跳转显示框
  219. }
  220.  
  221. //调整搜索界面
  222. if (pageType === "search") {
  223. document.getElementById("scform_srchtxt").style.width = "50%";
  224. document.getElementById("scform_submit").style.cssText = "width: 30%; min-width: 100px;";
  225. document.getElementById("toptb").style.cssText = "width: 100%; min-width: 0;padding: 0; border: 0;";//调整顶栏的宽度
  226. document.getElementById("scform").style.cssText += "width: 100%; min-width: 0;";//调整搜索框的宽度
  227. document.getElementById("ft").remove();//删除页脚
  228. //调整搜索结果的布局
  229. try {
  230. document.getElementById("threadlist").style.width = "100%";
  231. } catch (e) {
  232. }
  233. }
  234. /*侧边栏*/
  235. if (pageType === "index") {
  236. let sidebar_div = document.getElementById("sd");
  237. const sidebarHotTopics_div = sidebar_div.firstElementChild;
  238. const sidebarChoice_div = sidebar_div.children[1];
  239. //调整宽度
  240. sidebar_div.style.cssText = "width: 100%; min-width: 0;";
  241. sidebarHotTopics_div.style.cssText = "width: 100%; min-width: 0;";
  242. sidebarChoice_div.style.cssText = "width: 100%; min-width: 0;";
  243. const hotTopicsContainer_div = document.getElementsByClassName("main-right-zuixin")[0];
  244. for (let i = 0; i < hotTopicsContainer_div.childElementCount; i++) {
  245. let post_li = hotTopicsContainer_div.children[i];
  246. post_li.firstElementChild.firstElementChild.width = "100%";
  247. }
  248. //显示“热门主题”完整的标题
  249. const hotTopicsTitle_div = document.getElementsByClassName("comment-post");
  250. for (let i = 0; i < hotTopicsTitle_div.length; i++) {
  251. hotTopicsTitle_div[i].firstElementChild.textContent = hotTopicsTitle_div[i].firstElementChild.title;
  252. }
  253. //显示“精选内容”完整的标题
  254. const selectedTitle_div = document.getElementsByClassName("main-right-tw")[0];
  255. selectedTitle_div.firstElementChild.children[1].firstElementChild.textContent = selectedTitle_div.firstElementChild.children[1].firstElementChild.title;
  256. document.getElementsByClassName("main-right-tw-txt")[0].style.width = "100%";
  257. } else if (pageType === "post") {
  258. let sidebar_div = document.getElementsByClassName("sd sd_allbox")[0];
  259. const selectedContent_div = document.getElementsByClassName("main-right-box cl");
  260. const selectTheme_div = document.getElementsByClassName("main-right-zuixin")[0];
  261. //调整宽度
  262. sidebar_div.style.cssText = "width: 100%; min-width: 0;";
  263. for (let i = 0; i < selectedContent_div.length; i++) {
  264. selectedContent_div[i].style.cssText = "width: 100%; min-width: 0;";
  265. }
  266. //调整“精选主题”每个li的宽度
  267. for (let i = 0; i < selectTheme_div.childElementCount; i++) {
  268. let post_li = selectTheme_div.children[i];
  269. post_li.firstElementChild.firstElementChild.width = "100%";
  270. }
  271. }
  272.  
  273.  
  274. if (pageType !== "search") {
  275. /* 调整回到页首按钮的位置 */
  276. const backToTop_div = document.getElementsByClassName("biaoqi-fix-area")[0];
  277. backToTop_div.style.cssText = "left: 0; margin-left: 80%;"
  278. backToTop_div.firstElementChild.style.bottom = "10%";
  279.  
  280. /*调整页脚*/
  281. const footer = document.getElementsByClassName("jav-footer")[0];
  282. footer.style.cssText = "width: 100%; min-width: 0; padding: 0;";
  283. footer.firstElementChild.style.padding = "10px";
  284. }
  285. } else {
  286. let tip = "JavBus论坛移动端界面适配v: 未启用移动端布局,原因: ";
  287. if (window.innerWidth >= 1600) {
  288. if (window.innerWidth >= window.innerHeight) {
  289. console.log(tip + "当前屏幕宽度大于1600px, 且不为竖屏。");
  290. } else {
  291. console.log(tip + "当前屏幕宽度大于1600px。");
  292. }
  293. } else {
  294. if (window.innerWidth >= window.innerHeight) {
  295. console.log(tip + "当前屏幕不为竖屏。");
  296. } else {
  297. console.log(tip + "未知原因。");
  298. }
  299. }
  300. console.log("width:", window.innerWidth, "height:", window.innerHeight);
  301. }
  302. })();