AH mobile word count

Show the wordcount next to the date on alternatehistory mobile. Has an option to hide 0-wordcount threads.

当前为 2025-04-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name AH mobile word count
  3. // @description Show the wordcount next to the date on alternatehistory mobile. Has an option to hide 0-wordcount threads.
  4. // @author C89sd
  5. // @version 1.1
  6. // @match https://www.alternatehistory.com/*
  7. // @namespace https://greasyfork.org/users/1376767
  8. // ==/UserScript==
  9.  
  10. 'use strict';
  11.  
  12. const COLLAPSE_ZERO_THREADS = false;
  13.  
  14.  
  15. // Match AH's @media(max-width: 650px){.wordcount{display: none;}},
  16. const style = document.createElement('style');
  17. style.textContent = `
  18. .mobile-only {
  19. display: none !important;
  20. }
  21.  
  22. @media (max-width: 650px) {
  23. .mobile-only {
  24. display: block !important;
  25. }
  26. }
  27. `;
  28. document.head.appendChild(style);
  29.  
  30. const threads = document.querySelectorAll('div.structItem');
  31. for (const thread of threads) {
  32. var found = false;
  33. const link = thread.querySelector('a[data-xf-click="overlay"]');
  34.  
  35. if (link && link.textContent.startsWith('Word Count: ')) {
  36. found = true;
  37. link.textContent = link.textContent.replace('Word Count: ', 'Words: ');
  38.  
  39. const mobileDate = thread.querySelector('div.structItem-cell--latest');
  40.  
  41. if (mobileDate) {
  42. const middleDot = document.createElement('a');
  43. middleDot.textContent = '·';
  44. const gap = '0.5ch';
  45. middleDot.style.marginRight = gap;
  46. middleDot.style.marginLeft = gap;
  47. middleDot.classList.add('mobile-only');
  48. mobileDate.append(middleDot);
  49.  
  50. const clonedLink = link.cloneNode(true);
  51. clonedLink.classList.add('mobile-only');
  52. mobileDate.append(clonedLink);
  53. }
  54. }
  55.  
  56. if (!found && COLLAPSE_ZERO_THREADS) {
  57. const title = thread.querySelector('.structItem-title');
  58. if (title) {
  59. const clone = title.cloneNode(true);
  60. clone.style.opacity = '0.2';
  61. clone.style.whiteSpace = 'nowrap';
  62. clone.style.paddingLeft = '8px';
  63. clone.style.letterSpacing = '-0.5x';
  64. // clone.style.fontWeight = '350';
  65.  
  66. // Delete all children
  67. while (thread.firstChild) {
  68. thread.removeChild(thread.firstChild);
  69. }
  70. thread.appendChild(clone);
  71. }
  72. }
  73. }