v2ex 免跳转浏览 + 折叠回复少的页面

折叠回复少的页面;在 v2ex 主页面显示鼠标悬停内容

目前为 2022-04-15 提交的版本。查看 最新版本

// ==UserScript==
// @name        v2ex 免跳转浏览 + 折叠回复少的页面
// @namespace   ThomasKara
// @run-at document-end
// @include     http*://*v2ex.com/*
// @version     0.0.4
// @description 折叠回复少的页面;在 v2ex 主页面显示鼠标悬停内容
// ==/UserScript==
function insertAfter(newNode, existingNode) {
    existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
}

// 折叠回复小于等于1的页面
(function () {
    'use strict';
    var box=document.querySelector("#Main .box");
    var l=box.querySelectorAll("#Main .box .cell.item");
    var less=[""];

    if (l.length){
        for (var i=0;i<l.length;i++){
            var tr=l[i].querySelector("tr");
            if (tr.lastElementChild.children.length==0||parseInt(tr.lastElementChild.querySelector("a").innerText)<=1){
                l[i].style="padding: 0 10px;overflow: hidden;height: 1.3rem;border: none;";
                l[i].querySelector(".item_title").style.fontSize=".9em";
                less.push(l[i]);
            }
        }
        less[0]=less.length+" - "+Math.floor(100*(l.length-less.length)/l.length)+"% ("+(l.length-less.length)+"/"+l.length+")";
        box.append(...less);

        console.log(less[0]);
}
})();

// 免跳转预览
(function () {
    'use strict';
    var l=document.querySelectorAll("#Main .box .cell.item");
    var ifrm=document.querySelector("iframe.fast-viewer");
    var blocker=document.querySelector("div.blocker");

    if (l.length){
        document.querySelector("#Rightbar").style.display="none";
        if (!ifrm){
            ifrm=document.createElement("iframe");
            ifrm.classList.add("fast-viewer");
            ifrm.style="width: 92vw;height: 80vh;border: 1px solid gray;z-index: 1;";
            blocker=document.createElement("div");
            blocker.classList.add("blocker");
            blocker.style="position: fixed; bottom: 0px; width: 100%;";
            blocker.title="this area is blocked to prevent falling, try to scroll up";
        }
        for (var i=0;i<l.length;i++){
            var a=l[i].querySelector(".item_title a");
            if (a){
                let current=l[i];
                let a=current.querySelector(".item_title a");
                a.onmouseenter=()=>{
                    if (ifrm.src!=a.href){
                        ifrm.src=a.href;
                        insertAfter(ifrm, current);
                        window.scrollTo(0, current.getBoundingClientRect().top + document.documentElement.scrollTop)
                        ifrm.onload=()=>{
                            ifrm.contentWindow.document.querySelector("#reply-box").style.display="none";
                            ifrm.contentWindow.document.querySelector("#Bottom").style.display="none";
                        };
                        blocker.style.height=window.innerHeight-ifrm.offsetHeight-current.offsetHeight+"px";
                        insertAfter(blocker, ifrm);
                    }
                };
            }
        }
    }
})();

QingJ © 2025

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