yaphes1993hotmail.com / 自动阅读

// ==UserScript==
// @name              自动阅读
// @license MIT
// @version           1.2.3
// @description       自动阅读nene微博
// @match             *://weibo.com/a/hot/7588679047487489*
// @require           https://cdn.jsdelivr.net/npm/sweetalert2@9
// @require           https://cdn.jsdelivr.net/npm/js-base64
// @require           https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js
// @grant             GM_setValue
// @grant             GM_getValue
// @grant             window.close
// @grant             window.focus
// @run-at            document-start
// ==/UserScript==

$(document).ready(function () {
    'use strict';
    if (Base64.extendString) {
        Base64.extendString();
    }
    var dir;
    var codeInfo;
    var content;
    var file_id;
    var failed = 0;
    var html_btn = '<a href="javascript:;" class="nav_item cur" id="fast_link_btn" title="自动阅读" style="display: inline-block;"">';
    //    html_btn += '<span class="g-button-right">';
    html_btn += '<em class="icon icon-disk" title="自动阅读"></em>';
    html_btn += '<span class="text" style="width: auto;">自动阅读</span>'
    html_btn += '</span></a>';
    console.log("starting")
    let loop = setInterval(() => {
        var html_tag = $("div.UG_left_nav.UG_nav_tag");
        if (!html_tag.length) return false;
        html_tag.append(html_btn);
        $("#fast_link_btn").click(function () {
            autoRead();
        });
        clearInterval(loop);
    }, 500);

    function sleep(ms) {
        return new Promise(
            resolve => setTimeout(resolve, ms)
        );
    }

    async function autoRead(str='') {
        console.log("Starting auto read")
        var weibo_list;
        var eow = false;   //end of weibo
        var read_count = 1;

        //get whole list
        while (!eow) {
            weibo_list = $(".UG_content_row")[0]
            var last_str = weibo_list.lastElementChild.innerText;
            if (last_str.includes("查看更多未读微博")==false) {
                eow = true;
                break;
            }
            else {
                weibo_list.lastElementChild.click()
                await sleep(2000);
                console.log("more weibo")
                eow = false;
            }
        }

        weibo_list = $(".UG_content_row")[0];
        var window_array = [];
        var len = weibo_list.children.length;
        var i;
        for (i = 1;i < len;i++) {
            var link = weibo_list.children[i].getAttribute("href");
            if (!link)
                link = weibo_list.children[i].children[1].getAttribute("href");
            var ww = window.open(link);
            window_array.push(ww);
            //window.focus();
            //weibo_list.children[i].click();
            console.log("reading %i weibo", i);
            console.log(link);
            await sleep(16000);
            console.log(window_array);
            ww.close();
        }
        //await sleep(15000);
        //window_array.forEach(closeWindow);

    }

    function closeWindow(item, index) {
        item.close();
    }


})