Show Accurate View Count, Asked timestamp and Modified timestamp of StackExchange question

Show Accurate View Count, Asked timestamp and Modified timestamp of StackExchange question.

Fra og med 01.03.2024. Se den nyeste version.

// ==UserScript==
// @name         Show Accurate View Count, Asked timestamp and Modified timestamp of StackExchange question
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @license      MIT
// @description  Show Accurate View Count, Asked timestamp and Modified timestamp of StackExchange question.
// @author       aspen138
// @match      *://*.stackexchange.com/*
// @match          *://*.stackoverflow.com/questions/*
// @match          *://superuser.com/questions/*
// @match          *://meta.superuser.com/questions/*
// @match          *://serverfault.com/questions/*
// @match          *://meta.serverfault.com/questions/*
// @match          *://askubuntu.com/questions/*
// @match          *://meta.askubuntu.com/questions/*
// @match          *://mathoverflow.net/questions/*
// @match          *://meta.mathoverflow.net/questions/*
// @match          *://*.stackexchange.com/questions/*
// @match          *://answers.onstartups.com/questions/*
// @match          *://meta.answers.onstartups.com/questions/*
// @match          *://stackapps.com/questions/*
// @match          *://*.stackoverflow.com/review/*
// @match          *://superuser.com/review/*
// @match          *://meta.superuser.com/review/*
// @match          *://serverfault.com/review/*
// @match          *://meta.serverfault.com/review/*
// @match          *://askubuntu.com/review/*
// @match          *://meta.askubuntu.com/review/*
// @match          *://mathoverflow.net/review/*
// @match          *://meta.mathoverflow.net/review/*
// @match          *://*.stackexchange.com/review/*
// @match          *://answers.onstartups.com/review/*
// @match          *://meta.answers.onstartups.com/review/*
// @match          *://stackapps.com/review/*
// @match          *://*.stackoverflow.com/search*
// @match          *://superuser.com/search*
// @match          *://meta.superuser.com/search*
// @match          *://serverfault.com/search*
// @match          *://meta.serverfault.com/search*
// @match          *://askubuntu.com/search*
// @match          *://meta.askubuntu.com/search*
// @match          *://mathoverflow.net/search*
// @match          *://meta.mathoverflow.net/search*
// @match          *://*.stackexchange.com/search*
// @match          *://answers.onstartups.com/search*
// @match          *://meta.answers.onstartups.com/search*
// @match          *://stackapps.com/search*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    // Define a function to format the date
    function formatDate(date) {
        return date.toISOString().replace('T', ' ').replace(/\..*$/, 'Z');
    }

    // Update Asked time
    const askedTimeElement = document.querySelector('time[itemprop="dateCreated"]');
    if (askedTimeElement) {
        const askedDate = new Date(askedTimeElement.getAttribute('datetime'));
        console.log("askedDate=", askedDate);
        askedTimeElement.innerText = formatDate(askedDate);
    }

    // Update Modified time
    const modifiedTimeElement = document.querySelector('a[href*="?lastactivity"]');
    if (modifiedTimeElement) {
        const modifiedDate = new Date(modifiedTimeElement.getAttribute('title'));
        console.log("modifiedDate=", modifiedDate);
        modifiedTimeElement.innerText = formatDate(modifiedDate);
    }

    // Update Viewed count
    const viewedElement = document.querySelector('div[title*="Viewed"]');
    if (viewedElement) {
        const viewCount = viewedElement.getAttribute('title').match(/Viewed ([\d,]+) times/);
        if (viewCount && viewCount[1]) {
            viewedElement.innerText = 'Viewed ' + viewCount[1].replace(/,/g, '') + ' times';
        }
    }
})();
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

注册一下就行

Rainyun

一年攒够 12 元