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 08.03.2024. Se den seneste versjonen.

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