// ==UserScript== // @name markList Script // @namespace http://tampermonkey.net/ // @version 0.1.7 // @description special Follows! // @author 行亦难 // @match https://*.summer-plus.net/* // @match https://*.level-plus.net/* // @match https://*.white-plus.net/* // @match https://*.south-plus.net/* // @match https://*.imoutolove.me/* // @grant GM_setValue // @grant GM_getValue // @downloadURL https://update.greasyfork.icu/scripts/418511/markList%20Script.user.js // @updateURL https://update.greasyfork.icu/scripts/418511/markList%20Script.meta.js // ==/UserScript== // 最大条数 var max_count = 100; (function() { 'use strict'; //use tools if(!jQuery){ console.log('没获取到jq'); return; } home_element(); home_event(); if(window.location.pathname.includes('index.php') || window.location.pathname == '/'){ console.log('首页') }else if(window.location.pathname == '/u.php'){ console.log('用户信息') }else if(window.location.pathname == '/read.php'){ console.log('帖子详情') // if(jQuery('a[href$="fid-48.html"].gray3').length){ if(jQuery('.crumbs-item.gray3').text().includes('询问&求物')){ page_element(); } }else{ console.log('其他页面') } //initTempDiv(`/read.php?tid-1020134.html`) // Your code here... })(); function home_event(){ // 获取元素和初始值 let oBox = document.querySelector('.div1'), disX = 0, disY = 0; let div2 = document.querySelector('.div2'); let close2 = document.querySelector('.c-close'); let open2 = document.querySelector('.c-open'); let refresh = document.querySelector('.refresh-btn'); let loader = document.querySelector('.c-loader'); // 容器鼠标按下事件 oBox.onmousedown = function (e) { let ev = e || window.event; disX = ev.clientX - this.offsetLeft; disY = ev.clientY - this.offsetTop; document.onmousemove = function (e) { let ev = e || window.event; oBox.style.left = (ev.clientX - disX) + 'px'; oBox.style.top = (ev.clientY - disY) + 'px'; }; document.onmouseup = function () { document.onmousemove = null; document.onmouseup = null; }; return false; }; // 事件不冒泡 div2.onmousedown = (event) => { event.stopPropagation(); } close2.onclick = () => { oBox.style.display = 'none'; open2.style.display = 'block'; } open2.onclick = (event) => { oBox.style.display = 'block'; //event.target.style.display = 'none'; jQuery('.c-open').hide() } refresh.onclick = () => { while (document.querySelector('.c-item')) { document.querySelector('.c-item').remove(); } loader.style.display = 'block'; refresh.style.display = 'none'; let mark_map = GM_getValue('mark_map') ? GM_getValue('mark_map') : new Object(); let arr_p = [] for(let item in mark_map){ arr_p.push(initTempDiv(`/read.php?tid=${item}`, item)); } Promise.all(arr_p).then((res)=>{ console.log(res); for(let i of res){ if(i.isAnswer){ mark_map[i.id].isAnswer = true; }else{ mark_map[i.id].isAnswer = false; } } GM_setValue('mark_map', mark_map); loader.style.display = 'none'; refresh.style.display = 'block'; addHomeList(); }) console.log('循环结束') return; //GM_setValue('mark_map', mark_map); setTimeout(() => { loader.style.display = 'none'; refresh.style.display = 'block'; addHomeList(); }, 2000) } // 清空已读 let reset2 = document.querySelector('.c-reset'); reset2.onclick = () => { let mark_map = GM_getValue('mark_map'); if(mark_map){ let arr_temp = [] for(let i in mark_map){ if(mark_map[i].rank == 2){ arr_temp.push(mark_map[i]) delete mark_map[i]; } } if(arr_temp.length > 0){ GM_setValue('mark_map', mark_map); while (document.querySelector('.c-item')) { document.querySelector('.c-item').remove(); } addHomeList(); } } } } function home_element(){ // 初始化悬浮窗节点 let cssDiv = document.createElement('style'); cssDiv.innerHTML = initCss(); //let nTable = document.querySelector('#main .t table'); //nTable.appendChild(cssDiv); let $ = jQuery; $('#toptool').append($(cssDiv)) $('#toptool').append($(initHtml())) // 12.12更新 $('#guide').prepend($('.c-open')); // 缓存中读取列表 addHomeList() } function page_element(){ let $ = jQuery; $('#toptool').append($(initMark())); // 12.12更新 let tizName = $('strong [href^=read]').text(); let tizUrl = window.location.pathname + window.location.search; let tizId = tizUrl.match(/[0-9]+/).toString(); // 加强匹配 //let isAnswer = Boolean($('.tpc_content:eq(3) .s3').length); let isAnswer = false; if($('.tpc_content:eq(3) .s3').length){ if($('.tpc_content:eq(3) .s3').text().includes('最佳答案奖励')){ isAnswer = true } }else{ isAnswer = false; } let map = GM_getValue('mark_map') ? GM_getValue('mark_map') : new Object(); $('.t3').prepend($('.c-mark')); let flag = true for(let key in map){ if(key === tizId){ flag = false; $('.c-mark').addClass('unmark').text('已 Mark'); } } // 点击mark $('.c-mark').click((event)=>{ console.log($(event.target)); console.log(flag); flag=!flag; //console.log(tizName, tizUrl, tizId, isAnswer) map[tizId] = {tizName, tizUrl, tizId, isAnswer, rank: isAnswer?0:1} if(flag){ $('.c-mark').removeClass('unmark').text('Mark'); delete map[tizId]; GM_setValue('mark_map', map); }else{ $('.c-mark').addClass('unmark').text('已 Mark'); if(Object.keys(map).length > max_count){ return } GM_setValue('mark_map', map); } }) } function addHomeList(){ // 缓存中读取列表 let $ = jQuery; let mark_map = GM_getValue('mark_map') ? GM_getValue('mark_map') : new Object(); if(!Object.keys(mark_map).length){ $('.c-items').append($(`
`)) } let arr = []; for (let key in mark_map) { arr.push(mark_map[key]); } if (arr.length > 0) { if (arr.length > 1) { arr.sort(function (a, b) { return a.rank - b.rank; }) } for(let item of arr){ let str = `` $('.c-items').append($(str)) } } $('.c-del').click(function(event){ //删除marke let item = $(event.target).parent().parent(); console.log(item.data()) if(item.data().id){ item.remove() //console.log(mark_map) delete mark_map[item.data().id] GM_setValue('mark_map', mark_map); } }) //点击有答案的,标记已读 $('.c-item-text').on('click', function(event){ console.log($(event.target).data()) let id = $(event.target).data().id if(id && mark_map[id].isAnswer){ $('.c-items').append($(event.target).parent()) mark_map[id].rank = 2; GM_setValue('mark_map', mark_map); $(event.target).parent().find('.isRead').text('[已读]'); } }) } function delItem(id){ } async function initTempDiv(url, id){ // 创建缓存节点,解析文本形式的html let $ = jQuery; let p1 = await getPageData(url); let tempDiv = document.createElement('div'); tempDiv.innerHTML = p1; let tic = $(tempDiv) //let flag = tic.find('.tpc_content:eq(3) .s3').get(0) let flag = false; if(tic.find('.tpc_content:eq(3) .s3').length){ if(tic.find('.tpc_content:eq(3) .s3').text().includes('最佳答案奖励')){ flag = true } }else{ flag = false; } if(flag){ console.log(flag) return {isAnswer:Boolean(flag), id}; }else{ console.log('无') return {isAnswer: false, id}; } } // 获取求物区的帖子数据 function getPageData(url){ return new Promise(function(resolve, reject){ let xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200 || xhr.status == 304) { resolve(xhr.responseText) } } xhr.send(); }) } function initHtml(){ return `