yaphes1993hotmail.com / 全微博自动阅读

// ==UserScript==
// @name              全微博自动阅读
// @license MIT
// @version           1.0.0
// @description       按日期自动阅读nene微博
// @match             *weibo.com/u/6823546584*
// @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 = '<div class="btn_bed W_fl" id="fast_link_btn" title="自动阅读" style="display: inline-block;"">';
    //    html_btn += '<span class="g-button-right">';
    html_btn += '<a href="javascript:;" class="W_btn_d btn_34px" 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.opt_box.clearfix");
        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 window_array = [];
        var current_p = document.documentElement.scrollTop || document.body.scrollTop;
        var last_p = -100;

        //get whole list
        while (true) {
            current_p = document.documentElement.scrollTop || document.body.scrollTop;
            if (last_p == current_p) break;
            window.scrollTo(0,document.body.scrollHeight);
            await sleep(2000);
            last_p = current_p;
        }
        console.log("scrolled to bottom");

        weibo_list = $(".WB_detail");
        console.log("obtained %s weibos", weibo_list.length);
        var i = 0;
        var len = weibo_list.length;
        for (i=0;i<len;i++) {
            var link = "https://weibo.com"+weibo_list[i].children[1].firstElementChild.getAttribute("href");
            console.log(link);
            var ww = window.open(link);
            await sleep(20000);
            ww.close();
        }

    }

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


})