知乎回答头部显示回答日期

try to take over the world!

目前为 2020-04-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         知乎回答头部显示回答日期
// @namespace    http://tampermonkey.net/
// @version      0.3
// @author       Yupeg.LV
// @include      *.zhihu.com/*
// @require      https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js
// @description try to take over the world!
// ==/UserScript==

function timestampToTime(timestamp) {
    var date = new Date(timestamp);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y + M + D + h + m + s;
}
(function () {
    'use strict';
    var $ = $ || window.$;
    setInterval(() => {
        $('.ContentItem').each(function (index, element) {
            let ctime = $(this).find('meta[itemprop="dateCreated"]'),
                mtime = $(this).find('meta[itemprop="dateModified"]'),
                cc = ctime.attr('content'),
                mc = mtime.attr('content'),
                cd = timestampToTime(cc),
                md = timestampToTime(mc);
            let add = $(this).find('div[class="css-h5al4j"]');
            console.log(add, add.hasClass('yupeg_add_time'));
            if (!add.hasClass('yupeg_add_time')) {
                add.addClass('yupeg_add_time');
                add.append(`<span>&nbsp;&nbsp;&nbsp;&nbsp;创建于:${cd}&nbsp;&nbsp;&nbsp;&nbsp;最后修改:${md}</span>`);
            }

            let add2 = $(this).find('div[class="RichContent is-collapsed"]');
            if (!add2.hasClass('yupeg_add_time')) {
                add2.addClass('yupeg_add_time');
                add2.prepend(`<div style='text-align:left;color:#999;font-size:14px;'>
                            创建于:${cd}&nbsp;&nbsp;&nbsp;&nbsp;最后修改:${md}
                        </div>`);
            }

        });
    }, 1000);
    $('.QuestionPage ').each(function (index, element) {
        let ctime = $(this).find('meta[itemprop="dateCreated"]'),
            mtime = $(this).find('meta[itemprop="dateModified"]'),
            cc = ctime.attr('content'),
            mc = mtime.attr('content'),
            cd = timestampToTime((new Date(cc)).getTime()),
            md = timestampToTime((new Date(mc)).getTime());
        let add = $(this).find('div[class="QuestionHeader-side"]');
        add.append(`<div  style='text-align:left;color:#999'>
                        <p>创建于:${cd}</p>
                        <p>最后编辑:${md}</p>
                    </div>`);
    });
})();

QingJ © 2025

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