MetaFilter embiggen small hyperlinks

Makes small hyperlinks in comments on MetaFilter.com and all subsites larger. Helpful on mobile devices.

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

// ==UserScript==
// @name          MetaFilter embiggen small hyperlinks
// @description	  Makes small hyperlinks in comments on MetaFilter.com and all subsites larger. Helpful on mobile devices.
// @author        Tehhund
// @match         *://*.metafilter.com/*
// @run-at        document-idle
// @version       8
// @namespace https://gf.qytechs.cn/users/324881
// ==/UserScript==

function embiggenAll() {
  let allHyperlinks = [];
  let allCommentDivs = document.getElementsByClassName('comments');
  allCommentDivs = Array.from(allCommentDivs).filter( function(div) { return div.previousSibling.tagName == 'A'; }); // Some "comment" divs are actually not comments. Real comments are always preceded by an anchor tag so this filters out any not-actually-comment divs.
  for (currentDiv of allCommentDivs) { // get all the hyperlinks from within comment divs.
    allLinksInCurrentDiv = Array.from(currentDiv.getElementsByTagName('A')); // get all anchor/link elements in the current div.
    allHyperlinks = allHyperlinks.concat(allLinksInCurrentDiv); // add those links to the array of all links.
  }
  for (let tag of allHyperlinks) { embiggenOne(tag) } // Check hyperlink font size and increase if it's less than 17px
}

function handleMutationsList(mutationsList, observer) {
	 for (let mutation of mutationsList) { // Loop over all mutations for this event.
		 let allLinksInMutatedNode = Array.from(mutation.target.getElementsByTagName('A')); // Get all anchor elements aka links in the mutated node.
		 for (let currentNode of allLinksInMutatedNode) { embiggenOne(currentNode) }; // Call embiggenOne on every link element in the mutated node.
	 }
}

function embiggenOne(tag) {
  let compStyles = window.getComputedStyle(tag);
  let compFontSize = parseFloat(compStyles.getPropertyValue('font-size'));
  if (compFontSize < 17) tag.style.fontSize = '130%';
}

// Embiggen all small links when the script initially runs.
embiggenAll();

// After the first embiggening, observe the main content div for changes such as new comments or adding a Favorite, and run embiggenOne() on the changed tag.
const mutationObserver = new MutationObserver(handleMutationsList);
mutationObserver.observe(document.getElementById('posts'), { attributes: true, childList: true, subtree: true })

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址