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 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        AH mobile word count
// @description Show the wordcount next to the date on alternatehistory mobile. Has an option to hide 0-wordcount threads.
// @author      C89sd
// @version     1.1
// @match       https://www.alternatehistory.com/*
// @namespace   https://greasyfork.org/users/1376767
// ==/UserScript==

'use strict';

const COLLAPSE_ZERO_THREADS = false;


// Match AH's @media(max-width: 650px){.wordcount{display: none;}},
const style = document.createElement('style');
style.textContent = `
  .mobile-only {
    display: none !important;
  }

  @media (max-width: 650px) {
    .mobile-only {
      display: block !important;
    }
  }
`;
document.head.appendChild(style);

const threads = document.querySelectorAll('div.structItem');
for (const thread of threads) {
  var found = false;
  const link = thread.querySelector('a[data-xf-click="overlay"]');

  if (link && link.textContent.startsWith('Word Count: ')) {
    found = true;
    link.textContent = link.textContent.replace('Word Count: ', 'Words: ');

    const mobileDate = thread.querySelector('div.structItem-cell--latest');

    if (mobileDate) {
      const middleDot = document.createElement('a');
      middleDot.textContent = '·';
        const gap = '0.5ch';
      middleDot.style.marginRight = gap;
      middleDot.style.marginLeft = gap;
      middleDot.classList.add('mobile-only');
      mobileDate.append(middleDot);

      const clonedLink = link.cloneNode(true);
      clonedLink.classList.add('mobile-only');
      mobileDate.append(clonedLink);
    }
  }

  if (!found && COLLAPSE_ZERO_THREADS) {
    const title = thread.querySelector('.structItem-title');
    if (title) {
        const clone = title.cloneNode(true);
        clone.style.opacity = '0.2';
        clone.style.whiteSpace = 'nowrap';
        clone.style.paddingLeft = '8px';
        clone.style.letterSpacing = '-0.5x';
        // clone.style.fontWeight = '350';

       // Delete all children
        while (thread.firstChild) {
          thread.removeChild(thread.firstChild);
        }
        thread.appendChild(clone);
    }
  }
}