markList Script

special Follows!

目前為 2020-12-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         markList Script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  special Follows!
// @author       行亦难

// @match        https://*.imoutolove.me/*
// @match        https://*.level-plus.net/*

// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==

// 最大条数
var max_count = 10;

(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';
    }
    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)
    }
}
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()))
    // 缓存中读取列表
    addHomeList()

}


function page_element(){
    // 点击mark
    let $ = jQuery;
    $('#toptool').append($(initMark()))
    $('.c-mark').click((event)=>{
        console.log($(event.target));
        $(event.target).hide();

        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)
        //console.log(tizName, tizUrl, tizId, isAnswer)
        let map = GM_getValue('mark_map') ? GM_getValue('mark_map') : new Object();
        map[tizId] = {tizName, tizUrl, tizId, isAnswer}
        //console.log(map)
        //let mark_map = GM_getValue('mark_map');

        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();
    for(let key in mark_map){
        let str = `<div class="c-item" data-id="${mark_map[key].tizId}">
                <a href="${mark_map[key].tizUrl}">
                    ${mark_map[key].tizName}
</a>
                <b class="answer">${mark_map[key].isAnswer?'[有答案]':''}</b>
                <strong><a href="javascript:void(0);" class="c-del">[删除]</a></strong>
            </div>`
      $('.c-items').append($(str))
    }
    $('.c-del').click(function(event){
        //删除marke
        let item = $(event.target).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);
        }
    })
}
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)
    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 `<div class="div1">
        <span>&nbsp;&nbsp;此处拖动</span><span>&nbsp;&nbsp;>>>> Mark列表</span>
        <span class="btn c-close">缩小</span>
        <div class="div2">
            <div class="c-items">
            </div>
            <div class="c-loader">
                <div class="loader">Loading...</div>
            </div>
        </div>
        <div class="refresh-btn">

            <span class="btn">刷新</span>

        </div>
    </div>
    <div class="c-open btn">放大</div>`
}
function initMark(){
    return `<div class="c-mark btn">Mark</div>`
}
function initCss() {
    // 初始化样式
    let textCss = `
        .div1 {
            width: 20vw;
            min-height: 100px;
            position: fixed;
            right: 0;
            top: 30%;
            padding-top: 20px;
            border-radius: 5px;
            overflow: hidden;
            z-index: 999;
            text-align: left;
            cursor: pointer;
            display:none;
            background-color: white;
            border: 1px solid black;
        }
        .c-open{
            cursor: pointer;
            right: 15px;
            top: 30%;
            position: fixed;
        }
       .refresh-btn{
            height: 20px;
            padding: 8px;
            width: max-content;
        }
        .div2 {
            margin-top: 20px;
            min-height: 200px;
            background-color: white;
            border-bottom: 1px solid;
            border-top: 1px solid;

        }

        .c-close {
            position: absolute;
            right: 5px;
            top: 20px;
            cursor: pointer;
        }

        .c-item {
          line-height: 24px;
          border-bottom: 1px dashed;
          padding: 0 0 0 3px;
        }

        .c-mark{
            right: 15px;
            top: 25%;
            position: fixed;
            cursor: pointer;
        }
        .answer {
         color:red;
         }

        .c-loader {
            display: none;
        }

        .loader {
            color: yellow;
            font-size: 60px;
            text-indent: -9999em;
            overflow: hidden;
            width: 1em;
            height: 1em;
            border-radius: 50%;
            margin: 0px auto;
            position: relative;
            -webkit-transform: translateZ(0);
            -ms-transform: translateZ(0);
            transform: translateZ(0);
            -webkit-animation: load6 1.7s infinite ease, round 1.7s infinite ease;
            animation: load6 1.7s infinite ease, round 1.7s infinite ease;
        }

        @-webkit-keyframes load6 {
            0% {
                box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
            }

            5%,
            95% {
                box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
            }

            10%,
            59% {
                box-shadow: 0 -0.83em 0 -0.4em, -0.087em -0.825em 0 -0.42em, -0.173em -0.812em 0 -0.44em, -0.256em -0.789em 0 -0.46em, -0.297em -0.775em 0 -0.477em;
            }

            20% {
                box-shadow: 0 -0.83em 0 -0.4em, -0.338em -0.758em 0 -0.42em, -0.555em -0.617em 0 -0.44em, -0.671em -0.488em 0 -0.46em, -0.749em -0.34em 0 -0.477em;
            }

            38% {
                box-shadow: 0 -0.83em 0 -0.4em, -0.377em -0.74em 0 -0.42em, -0.645em -0.522em 0 -0.44em, -0.775em -0.297em 0 -0.46em, -0.82em -0.09em 0 -0.477em;
            }

            100% {
                box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
            }
        }

        @keyframes load6 {
            0% {
                box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
            }

            5%,
            95% {
                box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
            }

            10%,
            59% {
                box-shadow: 0 -0.83em 0 -0.4em, -0.087em -0.825em 0 -0.42em, -0.173em -0.812em 0 -0.44em, -0.256em -0.789em 0 -0.46em, -0.297em -0.775em 0 -0.477em;
            }

            20% {
                box-shadow: 0 -0.83em 0 -0.4em, -0.338em -0.758em 0 -0.42em, -0.555em -0.617em 0 -0.44em, -0.671em -0.488em 0 -0.46em, -0.749em -0.34em 0 -0.477em;
            }

            38% {
                box-shadow: 0 -0.83em 0 -0.4em, -0.377em -0.74em 0 -0.42em, -0.645em -0.522em 0 -0.44em, -0.775em -0.297em 0 -0.46em, -0.82em -0.09em 0 -0.477em;
            }

            100% {
                box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
            }
        }

        @-webkit-keyframes round {
            0% {
                -webkit-transform: rotate(0deg);
                transform: rotate(0deg);
            }

            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
            }
        }

        @keyframes round {
            0% {
                -webkit-transform: rotate(0deg);
                transform: rotate(0deg);
            }

            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
            }
        }`;
    return textCss;
}