Show Accurate View Count of StackExchange question

Show accurate view count of StackExchange question

目前为 2024-02-24 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Show Accurate View Count of StackExchange question
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @license MIT
  6. // @description Show accurate view count 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. (function() {
  52. 'use strict';
  53.  
  54. // // Define a function to format the date
  55. // function formatDate(date) {
  56. // return date.toISOString().replace('T', ' ').replace(/\..*$/, 'Z');
  57. // }
  58.  
  59. // // Update Asked time
  60. // const askedTimeElement = document.querySelector('div[title*="Asked"] time');
  61. // if (askedTimeElement) {
  62. // const askedDate = new Date(askedTimeElement.getAttribute('datetime'));
  63. // askedTimeElement.innerText = formatDate(askedDate);
  64. // }
  65.  
  66. // // Update Modified time
  67. // const modifiedTimeElement = document.querySelector('div[title*="Modified"] a');
  68. // if (modifiedTimeElement) {
  69. // const modifiedDate = new Date(modifiedTimeElement.getAttribute('title'));
  70. // modifiedTimeElement.innerText = formatDate(modifiedDate);
  71. // }
  72.  
  73. // Update Viewed count
  74. const viewedElement = document.querySelector('div[title*="Viewed"]');
  75. if (viewedElement) {
  76. const viewCount = viewedElement.getAttribute('title').match(/Viewed ([\d,]+) times/);
  77. if (viewCount && viewCount[1]) {
  78. viewedElement.innerText ='Viewed '+ viewCount[1].replace(',', '') + ' times';
  79. }
  80. }
  81. })();