Makes small hyperlinks in comments on MetaFilter.com and all subsites larger. Helpful on mobile devices.
当前为
// ==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 9
// @namespace https://greasyfork.org/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.
// Removing this again since it causes substantial performance problems with comment sorting scripts.
// const mutationObserver = new MutationObserver(handleMutationsList);
// mutationObserver.observe(document.getElementById('posts'), { attributes: true, childList: true, subtree: true })