Show Accurate View Count of StackExchange question

Show accurate view count of StackExchange question

ของเมื่อวันที่ 24-02-2024 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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 of StackExchange question
// @namespace    http://tampermonkey.net/
// @version      0.1
// @license      MIT
// @description  Show accurate view count 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('div[title*="Asked"] time');
//     if (askedTimeElement) {
//         const askedDate = new Date(askedTimeElement.getAttribute('datetime'));
//         askedTimeElement.innerText = formatDate(askedDate);
//     }

//     // Update Modified time
//     const modifiedTimeElement = document.querySelector('div[title*="Modified"] a');
//     if (modifiedTimeElement) {
//         const modifiedDate = new Date(modifiedTimeElement.getAttribute('title'));
//         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(',', '') + ' times';
        }
    }
})();