FollowsList Script

special Follows!

  1. // ==UserScript==
  2. // @name FollowsList Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1.1
  5. // @description special Follows!
  6. // @author 行亦难
  7. // @require https://cdn.jsdelivr.net/npm/layui-layer@1.0.9/dist/layer.js
  8.  
  9. // @match https://*.imoutolove.me/*
  10.  
  11. // @match https://*.level-plus.net/*
  12.  
  13.  
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // ==/UserScript==
  17. //console.log('jishu');
  18. (function() {
  19. 'use strict';
  20. // Your code here...
  21.  
  22. //layer.alert(isLogin());
  23. if(!isLogin()) return;
  24. //use tools
  25. if(window.location.pathname.includes('index.php') || window.location.pathname == '/'){
  26. console.log('首页')
  27. indexTool();
  28. }else if(window.location.pathname == '/u.php'){
  29. console.log('用户信息')
  30. userDetails();
  31. }else if(window.location.pathname == '/read.php'){
  32. console.log('帖子详情')
  33. nDetails();
  34. }else{
  35. console.log('其他页面')
  36. }
  37. //indexTool();
  38.  
  39.  
  40. //
  41. //检测jq是否已经引入
  42. console.log(jQuery('#header'))
  43. })();
  44.  
  45. function isLogin(){
  46. // 检查是否已经登录(不可用)
  47. if(document.getElementById('login_0') === null) {
  48. return true;
  49. }else{
  50. console.log('未登录(不可用)')
  51. return false;
  52. }
  53. }
  54.  
  55. function initCss(){
  56. // 初始化样式
  57. let textCss = `
  58. .layui-btn{
  59. color:#333;
  60. font-weight: 500;
  61. cursor: pointer;
  62. }
  63. .tabs{
  64. display: flex;
  65. }
  66. .tabs > div{
  67. flex:1;
  68. }
  69. .active{
  70. color:#000;
  71. font-weight: 700;
  72. }
  73. .specialList {
  74. flex:1;
  75. padding: 0px;
  76. }
  77. .specialList>a{
  78. display: block;
  79. margin: 0 4px;
  80. }
  81. .specialBox{
  82. display: none;
  83. width: 400%;
  84.  
  85. }
  86. .followTabs{
  87. height: 80px;
  88. text-align: center;
  89. }
  90. .follow{
  91. display:inline-block;
  92. cursor: pointer;
  93. }
  94. .unfollow{
  95. display: none;
  96. }
  97. `;
  98. return textCss;
  99. }
  100. async function indexTool(){
  101.  
  102. let $ = jQuery;
  103. //GM_setValue('arrFollows', {})
  104. let arrFollows = GM_getValue('arrFollows')?GM_getValue('arrFollows'):{};
  105. console.log('index.arr',arrFollows)
  106.  
  107. let nTable = document.querySelector('#main .t table');
  108. let nTab = document.createElement('div');
  109. nTab.className = 'layui-btn active';
  110. nTab.innerHTML = '最新讨论';
  111.  
  112. let nTab2 = document.createElement('div');
  113. nTab2.className = 'layui-btn';
  114. nTab2.innerHTML = '特别关注';
  115.  
  116. let nTabs = document.createElement('div');
  117. nTabs.className = 'tabs';
  118.  
  119. nTabs.appendChild(nTab);
  120. nTabs.appendChild(nTab2);
  121.  
  122. //nTable.querySelector('.tr2 td').replaceChild(nTab, nTable.querySelector('.tr2 td .b'));
  123. //nTable.querySelector('.tr2 td').appendChild(nTabs);
  124.  
  125. nTable.querySelector('.tr2 td').replaceChild(nTabs, nTable.querySelector('.tr2 td .b'));
  126.  
  127. // 最新讨论-节点
  128. let newsDiv = $('#main .t table').find('.tr3').eq(0);
  129.  
  130. let specialBox = document.createElement('div');
  131. specialBox.className = 'specialBox';
  132.  
  133. for(let i = 0; i < 4; i++){
  134. let specialList = document.createElement('div');
  135. specialList.className = 'specialList specialList'+i+'';
  136. specialBox.appendChild(specialList);
  137. }
  138. newsDiv.get(0).appendChild(specialBox)
  139.  
  140. //
  141. let cssDiv = document.createElement('style');
  142. cssDiv.innerHTML = initCss();
  143.  
  144. nTable.appendChild(cssDiv);
  145. //
  146. //event
  147. //let $ = jQuery;
  148. nTab = $(nTab);
  149. nTab2 = $(nTab2);
  150. //
  151.  
  152. nTab.click(function(){
  153. rtClass.apply(this, null);
  154. newsDiv.find('td').show();
  155. $('.specialBox').css('display','none');
  156. });
  157. nTab2.click(function(){
  158. rtClass.apply(this, null)
  159. newsDiv.find('td').hide();
  160. $('.specialBox').css('display','flex');
  161. });
  162.  
  163.  
  164. //设置视图
  165. for(let i = 0; i < Object.keys(arrFollows).length; i++){
  166.  
  167. //await setList('526481', $('.specialList'));
  168. let uuid = Object.keys(arrFollows)[i];
  169. await setList(uuid, $('.specialList' + i));
  170. if(arrFollows[uuid]){
  171. $('.specialList' + i).find('.u-h1').text(arrFollows[uuid].replace(/昵称:/,''))
  172. }
  173. $('.specialList' + i).find('.u-h1').click(function(){
  174. //console.log(uuid)
  175. location.href = `u.php?action-show-uid-${uuid}.html`
  176. })
  177. }
  178.  
  179.  
  180.  
  181.  
  182. //console.log($(await initTempDiv()).find('#user-login'))
  183. //console.log(initTempDiv())
  184. function rtClass(){
  185. // 切换按钮组
  186. $(nTabs).find('div').removeClass('active');
  187. $(this).addClass('active');
  188. }
  189.  
  190. async function initTempDiv(url){
  191. // 创建缓存节点,解析文本形式的html
  192. let p1 = await getUserData(url);
  193. let tempDiv = document.createElement('div');
  194. tempDiv.innerHTML = p1;
  195.  
  196. let tic = $(tempDiv).find('#u-contentmain .u-table tbody tr').map(function(){
  197. return $(this).find('th')[0]
  198. }).map(function(){
  199. return $(this).find('a')
  200. });
  201. if(tic.length > 0){
  202.  
  203. tic.map(function(){
  204. return jQuery(this).eq(0).prepend(jQuery(this).eq(1).append('] ').prepend(' ['))
  205. })
  206. return {list: tic, nickName: $(tempDiv).find('.u-h1')};
  207. }else{
  208. console.log('主题列表为0。');
  209. return {list: $('<a>暂无更多主题。</a>'), nickName: $(tempDiv).find('.u-h1')};
  210. }
  211.  
  212. }
  213. async function setList(uid, thisBox){
  214.  
  215. //let thisBox = $('.specialList0');
  216. if(thisBox.children().length){
  217. thisBox.children().remove()
  218. }
  219.  
  220. //获取列表数据集合,obj + jq对象,并设置到视图
  221. let arrayDiv = await initTempDiv(`/u.php?action-topic-uid-${uid}.html`);
  222.  
  223. if(!arrayDiv) {
  224. return;
  225. }
  226.  
  227. let specialName1= document.createElement('h1');
  228. specialName1.className = 'u-h1';
  229. specialName1.style = 'margin: 8px;';
  230. specialName1.innerHTML = arrayDiv['nickName'].text();
  231.  
  232. thisBox.append(specialName1)
  233.  
  234. arrayDiv['list'].slice(0,6).map(function(){
  235. thisBox.append($(this).clone().get(0))
  236. return null
  237. })
  238.  
  239. let btn = document.createElement('div');
  240. btn.innerHTML = '刷新'
  241. btn.style = 'display: inline-block;margin: 8px;cursor: pointer;';
  242. btn.className = 'btn refresh-btn';
  243. btn.dataset.uid = uid;
  244.  
  245. $(btn).click(function(){
  246. let index = layer.load(2, {time: 10*1000});
  247. setList(uid, thisBox).then(()=>{
  248. layer.close(index);
  249. })
  250. })
  251. thisBox.append(btn);
  252. }
  253. }
  254.  
  255.  
  256. function getUserData(url){
  257. return new Promise(function(resolve, reject){
  258. let xhr = new XMLHttpRequest();
  259. xhr.open('GET', url, true);
  260. xhr.onreadystatechange = function() {
  261. if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) {
  262. resolve(xhr.responseText)
  263. }
  264. }
  265. xhr.send();
  266. })
  267. }
  268.  
  269. function nDetails() {
  270. //注入帖子详情页
  271. let $ = jQuery;
  272.  
  273. let cssDiv = document.createElement('style');
  274. cssDiv.innerHTML = initCss();
  275.  
  276. $('#main').append($(cssDiv));
  277.  
  278. //init
  279. let userInfo = $('.user-info').map(function(){
  280. return $(this).find('.f12').eq(0).text()
  281. })
  282. let userInfoTwo = getUserInfotwo();
  283.  
  284. let arrFollows = GM_getValue('arrFollows')?GM_getValue('arrFollows'):{};
  285. //
  286.  
  287. let nTabs = document.createElement('div');
  288. nTabs.className = 'followTabs';
  289. nTabs.innerHTML = `<div class="btn follow">特别关注</div><div class="abtn follow unfollow">取消关注</div>`
  290.  
  291. $('.r_two').map(function(index){
  292. if(userInfo[index] == userInfoTwo){
  293. return $(this)
  294. }else{
  295. return $(this).append($(nTabs).clone().data('fid',index));
  296. }
  297.  
  298.  
  299. }).map(function(){
  300. let follow = $(this).find('.followTabs .follow').eq(0);
  301. let unfollow = $(this).find('.followTabs .follow').eq(1);
  302.  
  303. //判断是否已关注
  304. let index = $(this).find('.followTabs').data('fid');
  305. if(Object.keys(arrFollows).includes(userInfo[index])){
  306. follow.hide();
  307. unfollow.css('display','inline-block');
  308. }
  309.  
  310. follow.click(function(){
  311. if(document.readyState != 'complete'){
  312. layer.msg('还在加载');
  313. console.log(document.readyState)
  314. return;
  315. }else if(document.readyState == 'complete'){
  316.  
  317. if( Object.keys(arrFollows).length > 3){
  318. layer.msg('暂时只能关注四位');
  319. return;
  320. }
  321.  
  322. followUse.apply(this, null);
  323. //arrFollows.push(userInfo[index]);
  324. let nickName = $('.user-info').eq(index).text().match(/昵称: \S+/)
  325. arrFollows[userInfo[index]] = nickName?nickName[0]:''
  326. console.log(arrFollows)
  327. GM_setValue('arrFollows', arrFollows);
  328. }
  329.  
  330. })
  331. unfollow.click(function(){
  332. if(document.readyState != 'complete'){
  333. //layer.msg('别点了,还在加载呢');
  334. console.log(document.readyState)
  335. return;
  336. }else if(document.readyState == 'complete'){
  337. unfollowUse.apply(this, null)
  338. if(Object.keys(GM_getValue('arrFollows')).includes(userInfo[index])){
  339. delete arrFollows[userInfo[index]];
  340. GM_setValue('arrFollows', arrFollows);
  341. }
  342.  
  343. }
  344.  
  345. })
  346. })
  347.  
  348. //console.log(temp)
  349.  
  350. }
  351.  
  352.  
  353. function userDetails() {
  354.  
  355. let $ = jQuery;
  356.  
  357.  
  358. let cssDiv = document.createElement('style');
  359. cssDiv.innerHTML = initCss();
  360.  
  361. $('#main').append($(cssDiv));
  362.  
  363. let nTabs = document.createElement('div');
  364. nTabs.className = 'followTabs';
  365. nTabs.style = 'height: auto;margin-top: 1rem;'
  366. nTabs.innerHTML = `<div class="btn follow">特别关注</div><div class="abtn follow unfollow">取消关注</div>`
  367. let jTabs= $(nTabs)
  368.  
  369.  
  370. let uid = $('.u-table tr th').eq(0).text();
  371. let nickName = $('.u-table tr th').eq(3).text();
  372.  
  373. //判断是否已关注
  374. let arrFollows = GM_getValue('arrFollows')?GM_getValue('arrFollows'):{};
  375. if(Object.keys(arrFollows).includes(uid)){
  376. jTabs.find('.follow').eq(0).hide();
  377. jTabs.find('.follow').eq(1).css('display','inline-block');
  378. }
  379.  
  380.  
  381.  
  382. jTabs.find('.follow').eq(0).click(function(){
  383.  
  384. //如果大于四个特别关注
  385. if(Object.keys(arrFollows).length > 3) {
  386. layer.msg('暂时只能关注四位');
  387. }else{
  388. arrFollows[uid] = nickName?nickName:''
  389. GM_setValue('arrFollows', arrFollows);
  390. followUse.apply(this, null);
  391. }
  392.  
  393. })
  394. jTabs.find('.follow').eq(1).click(function(){
  395.  
  396. if(Object.keys(GM_getValue('arrFollows')).includes(uid)){
  397. delete arrFollows[uid];
  398. GM_setValue('arrFollows', arrFollows);
  399. }
  400. console.log(arrFollows);
  401. unfollowUse.apply(this, null);
  402. })
  403.  
  404.  
  405. //如果是自己的主页。
  406. if(!location.search) return;
  407.  
  408.  
  409. $('#u-profile').prepend(jTabs)
  410.  
  411. }
  412.  
  413. function followUse(){
  414. jQuery(this).hide().next().css('display','inline-block');
  415. let index = jQuery(this).parent().data('fid');
  416. // console.log(userInfo[index])
  417. }
  418. function unfollowUse(){
  419. jQuery(this).hide().prev().css('display','inline-block');
  420. }
  421.  
  422. function getUserInfotwo(){
  423. let userInfo = jQuery('.user-infotwo').text().match(/UID: \d+/)
  424. try{
  425. if(userInfo && userInfo.length){
  426. return userInfo[0].replace(/UID: /,'')
  427. }else{
  428. return ''
  429. }
  430. }catch(e){
  431. console.log(e)
  432. return '';
  433. }
  434.  
  435. }

QingJ © 2025

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