提示文章时间

提示文章时间。支持csdn,掘金,思否,博客园,stackoverflow,知乎专栏,简书。有问题发邮件:[email protected]

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        提示文章时间 
// @namespace   xky1000.cn
// @match       https://blog.csdn.net/*
// @match       https://juejin.cn/*
// @match       https://segmentfault.com/*
// @match       https://www.jianshu.com/p/*
// @match       https://www.cnblogs.com/*/p/*
// @match       https://stackoverflow.com/questions/*
// @match       https://zhuanlan.zhihu.com/p/*
// @version     0.1.5
// @author      xky
// @grant       GM_addStyle
// @license     MIT
// @description 提示文章时间。支持csdn,掘金,思否,博客园,stackoverflow,知乎专栏,简书。有问题发邮件:[email protected]
// ==/UserScript==


GM_addStyle(`#display-date {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10000;
    background-color: #ff9999;
    padding: 0 13px 0 8px;
    color:#000;
    font-size: 10px;
}`)
{
    function display(text) {
        const date = new Date(text);
        const year = date.getFullYear();
        const month = date.getMonth() + 1;
        const day = date.getDate();
        const div = document.createElement('div')
        div.id = 'display-date'
        div.innerText = `${year}/${month}/${day}`
        document.body.appendChild(div);
    }

    const siteHandlers = {
        'blog.csdn.net': () => display(document.querySelector('.time').innerText.match(/\d{4}-\d{2}-\d{2}/)),
        'juejin.cn': () => setTimeout(() => display(document.querySelector('.meta-box .time').dateTime), 500),
        'segmentfault.com': () => display(document.querySelector('time').dateTime),
        'www.jianshu.com': () => setTimeout(() => display(document.querySelector('time').dateTime), 500),
        'www.cnblogs.com': () => display(document.querySelector('#post-date').innerText),
        'stackoverflow.com': () => display(document.querySelector('.relativetime').title),
        'zhuanlan.zhihu.com': () => display(document.querySelector('.ContentItem-time').innerText.match(/\d{4}-\d{2}-\d{2}/))
    }

    siteHandlers[location.hostname]();
}