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

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

Från och med 2024-03-01. Se den senaste versionen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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';
        }
    }
})();