MetaFilter number all comments

On MetaFilter.com, adds a "comment 1 of 30" to each comment.

目前為 2019-08-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        MetaFilter number all comments
// @version     6
// @grant       none
// @match       http://*.metafilter.com/*
// @match       https://*.metafilter.com/*
// @description On MetaFilter.com, adds a "comment 1 of 30" to each comment.
// @locale      en-us
// @namespace   https://greasyfork.org/users/324881
// ==/UserScript==

function addCountToComments() {
  // first, clear all counts in case this runs more than once on a page.
  let allCommentCountSpans = Array.from(document.getElementsByClassName('tehhundUserScriptCommentCount'));
  for (let currentSpan of allCommentCountSpans) { currentSpan.remove(); }
  
  // then add counts to every comment div.
  let allCommentDivs = document.getElementsByClassName('comments');
  allCommentDivs = Array.from(allCommentDivs).filter( function(div) { return div.previousSibling.tagName == 'A'; });
  for (let [i,divToHighlight] of allCommentDivs.entries()) {
    divToHighlight.lastChild.innerHTML += '<span class=\'tehhundUserScriptCommentCount\'>Comment ' + (i+1) + ' of ' + allCommentDivs.length + '. </span>';
  }
}

// Attach event listeners

window.addEventListener('load',addCountToComments); // In case this script runs before the window load event, highlight when that event fires.
addCountToComments(); // In case this script runs after the window load event, highlight as soon as Greasemonkey runs the script.