Zhihu Tools

置前回答时间、专栏文章发表时间;自动播放GIF; 自动展开被折叠的回答

目前為 2020-05-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Zhihu Tools
// @author      Yandong
// @namespace   https://github.com/YandLiu/Userscripts
// @description 置前回答时间、专栏文章发表时间;自动播放GIF; 自动展开被折叠的回答
// @version     0.10
// @match       *://*.zhihu.com/*
// @run-at      document-end
// @grant       none
// ==/UserScript==

/********** 自动播放 GIF ***********/
// 测试页面: https://zhuanlan.zhihu.com/p/84896463
function loadGIF() {
    var gifs = document.querySelectorAll(".ztext-gif");
    gifs.forEach((i) => {
        i.src = i.src.replace(/jpg$/g, "webp");
        i.parentNode.classList.add("isPlaying");
    });
}

/********** 置前时间 ***********/
// 普通页面
if (document.location.hostname == "www.zhihu.com") {
    document.onscroll = function () {
        // 展开被折叠的回答
        try {
            document.querySelector(".CollapsedAnswers-bar button").click();
        } catch (e) {}
        // 展开被折叠的更多回答
        try {
            document.querySelector("button.QuestionMainAction").click();
        } catch (e) {}
        let time = document.querySelectorAll(".ContentItem-time");
        time.forEach((i) => {
            i.parentNode.parentNode.insertAdjacentElement(
                "afterbegin",
                i.parentNode
            );
        });
        loadGIF();
    };
}
// 知乎专栏
if (document.location.hostname == "zhuanlan.zhihu.com") {
    let time = document.querySelector(".ContentItem-time");
    time.parentNode.insertAdjacentElement("afterbegin", time);
    loadGIF();
}

QingJ © 2025

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