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

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

目前为 2024-03-06 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Show Accurate View Count, Asked timestamp and Modified timestamp of StackExchange question
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @license MIT
  6. // @description Show Accurate View Count, Asked timestamp and Modified timestamp of StackExchange question.
  7. // @author aspen138
  8. // @match *://*.stackexchange.com/*
  9. // @match *://*.stackoverflow.com/questions/*
  10. // @match *://superuser.com/questions/*
  11. // @match *://meta.superuser.com/questions/*
  12. // @match *://serverfault.com/questions/*
  13. // @match *://meta.serverfault.com/questions/*
  14. // @match *://askubuntu.com/questions/*
  15. // @match *://meta.askubuntu.com/questions/*
  16. // @match *://mathoverflow.net/questions/*
  17. // @match *://meta.mathoverflow.net/questions/*
  18. // @match *://*.stackexchange.com/questions/*
  19. // @match *://answers.onstartups.com/questions/*
  20. // @match *://meta.answers.onstartups.com/questions/*
  21. // @match *://stackapps.com/questions/*
  22. // @match *://*.stackoverflow.com/review/*
  23. // @match *://superuser.com/review/*
  24. // @match *://meta.superuser.com/review/*
  25. // @match *://serverfault.com/review/*
  26. // @match *://meta.serverfault.com/review/*
  27. // @match *://askubuntu.com/review/*
  28. // @match *://meta.askubuntu.com/review/*
  29. // @match *://mathoverflow.net/review/*
  30. // @match *://meta.mathoverflow.net/review/*
  31. // @match *://*.stackexchange.com/review/*
  32. // @match *://answers.onstartups.com/review/*
  33. // @match *://meta.answers.onstartups.com/review/*
  34. // @match *://stackapps.com/review/*
  35. // @match *://*.stackoverflow.com/search*
  36. // @match *://superuser.com/search*
  37. // @match *://meta.superuser.com/search*
  38. // @match *://serverfault.com/search*
  39. // @match *://meta.serverfault.com/search*
  40. // @match *://askubuntu.com/search*
  41. // @match *://meta.askubuntu.com/search*
  42. // @match *://mathoverflow.net/search*
  43. // @match *://meta.mathoverflow.net/search*
  44. // @match *://*.stackexchange.com/search*
  45. // @match *://answers.onstartups.com/search*
  46. // @match *://meta.answers.onstartups.com/search*
  47. // @match *://stackapps.com/search*
  48. // @grant none
  49. // ==/UserScript==
  50.  
  51.  
  52. (function() {
  53. 'use strict';
  54.  
  55. // Define a function to format the date
  56. function formatDate(date) {
  57. return date.toISOString().replace('T', ' ').replace(/\..*$/, 'Z');
  58. }
  59.  
  60. // Update Asked time
  61. const askedTimeElement = document.querySelector('time[itemprop="dateCreated"]');
  62. if (askedTimeElement) {
  63. const askedDate = new Date(askedTimeElement.getAttribute('datetime'));
  64. console.log("askedDate=", askedDate);
  65. askedTimeElement.innerText = formatDate(askedDate);
  66. }
  67.  
  68. // Update Modified time
  69. const modifiedTimeElement = document.querySelector('a[href*="?lastactivity"]');
  70. if (modifiedTimeElement) {
  71. const modifiedDate = new Date(modifiedTimeElement.getAttribute('title'));
  72. console.log("modifiedDate=", modifiedDate);
  73. modifiedTimeElement.innerText = formatDate(modifiedDate);
  74. }
  75.  
  76. // Update Viewed count
  77. const viewedElement = document.querySelector('div[title*="Viewed"]');
  78. if (viewedElement) {
  79. const viewCount = viewedElement.getAttribute('title').match(/Viewed ([\d,]+) times/);
  80. if (viewCount && viewCount[1]) {
  81. viewedElement.innerText = 'Viewed ' + viewCount[1].replace(/,/g, '') + ' times';
  82. }
  83. }
  84. })();