Greasy Fork is available in English.

知乎

统计知乎回答时间

Verzia zo dňa 01.12.2019. Pozri najnovšiu verziu.

// ==UserScript==
// @name         知乎
// @namespace    zgzhihu
// @version      0.11
// @description  统计知乎回答时间
// @author       You
// @match        *://www.zhihu.com/people/*/answers*
// @match        *://www.zhihu.com/people/*/answers/*
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.js
// @run-at       document-end
// @grant        unsafeWindow
// @grant        GM_setClipboard
// ==/UserScript==
(function() {
    'use strict';
    function getDateStr(seconds){
        var date = new Date(seconds*1000)
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        var currentTime = year + "-" + month + "-" + day + "  " + hour + ":" + minute + ":" + second;
        return currentTime
    }
    function utc2beijing(utc_datetime) {
        // 转为正常的时间格式 年-月-日 时:分:秒
        var T_pos = utc_datetime.indexOf('T');
        var Z_pos = utc_datetime.indexOf('Z');
        var year_month_day = utc_datetime.substr(0,T_pos);
        var hour_minute_second = utc_datetime.substr(T_pos+1,Z_pos-T_pos-1);
        var new_datetime = year_month_day+" "+hour_minute_second;
        // 处理成为时间戳
        timestamp = new Date(Date.parse(new_datetime));
        timestamp = timestamp.getTime();
        timestamp = timestamp/1000;
        // 增加8个小时,北京时间比utc时间多八个时区
        var timestamp = timestamp+8*60*60;
        // 时间戳转为时间
        return getDateStr(timestamp);
        //var beijing_datetime = new Date(parseInt(timestamp) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
        //return beijing_datetime;
    }
    function loadContent() {
        let checkLoadListTimer = setInterval(function(){
            if(!$('.PlaceHolder.List-item').length) {
                clearInterval(checkLoadListTimer);
                $(".List-item").each(function() {
                    let createdTime = utc2beijing($(this).find("meta[itemprop='dateCreated']").eq(0).attr('content'));
                    let content = "<span style='color:#f00;font-weight:900'>"+createdTime+"</span>"
                    $(this).find(".AuthorInfo.AnswerItem-authorInfo").append(content);
                });
            }
        },200);
    }
    //翻页
    $('.Pagination').on('click', "button", function(event) {
        loadContent();
    });
    //tab点击
    $('.Tabs.ProfileMain-tabs li[aria-controls="Profile-answers"]').on('click', function(event) {
        loadContent();
    });
    //排序
    $('body').on('click', ".Select-list button", function(event) {
        loadContent();
    });
    loadContent();
})();