html - 如何获取站点上使用的所有字体系列的列表?

标签 html css font-face webfonts

<分区>

我的主要目标是删除未使用的font-faces(字体链接)。我必须知道网站上实际使用的所有字体系列,然后我将删除所有未使用的。宾果游戏 ;)

最佳答案

只需将其粘贴到控制台并按回车键,您就可以得到一个带有字体列表的警告弹出窗口..

function styleInPage(css, verbose){
    if(typeof getComputedStyle== "undefined")
    getComputedStyle= function(elem){
        return elem.currentStyle;
    }
    var who, hoo, values= [], val,
    nodes= document.body.getElementsByTagName('*'),
    L= nodes.length;
    for(var i= 0; i<L; i++){
        who= nodes[i];
        if(who.style){
            hoo= '#'+(who.id || who.nodeName+'('+i+')');
            val= who.style.fontFamily || getComputedStyle(who, '')[css];
            if(val){
                if(verbose) values.push([hoo, val]);
                else if(values.indexOf(val)== -1) values.push(val);
            }
            val_before = getComputedStyle(who, ':before')[css];
            if(val_before){
                if(verbose) values.push([hoo, val_before]);
                else if(values.indexOf(val_before)== -1) values.push(val_before);
            }
            val_after= getComputedStyle(who, ':after')[css];
            if(val_after){
                if(verbose) values.push([hoo, val_after]);
                else if(values.indexOf(val_after)== -1) values.push(val_after);
            }
        }
    }
    return values;
}

alert(styleInPage('fontFamily'));// returns array:

Screenshot

关于html - 如何获取站点上使用的所有字体系列的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53081383/

上一篇:html - 将鼠标悬停在其中的标签上时如何更改 <li> 元素符号图标?

下一篇:javascript - Vue.js 转换 : animate height while using slide out animation

相关文章:

javascript - 如何将鼠标跟踪效果添加到特定的 wordpress 行?

jquery - 将鼠标悬停在浏览器中的 ID HTML 元素上时如何调用 "tooltip"?

html - 使 bootstrap div 可滚动

css - 字体外观与标题与普通文本不同的原因

php - HTML 标签中的字符大小写

javascript - 如何仅提高 2 个变量计数器而不是所有变量计数器的速度

python - CSS 文件在 Django 中不起作用

IE 中的 CSS 溢出问题

html - CSS 中的@font-face 问题

css - Font-Face 不适用于 Chrome