当前位置: 首页> 娱乐> 八卦 > 长沙企业建站销售电话_开发公司撤销网签起诉书怎么弄_网站优化seo培训_酒店网络营销推广方式

长沙企业建站销售电话_开发公司撤销网签起诉书怎么弄_网站优化seo培训_酒店网络营销推广方式

时间:2025/7/14 14:59:22来源:https://blog.csdn.net/feifeiyechuan/article/details/144656984 浏览次数:0次
长沙企业建站销售电话_开发公司撤销网签起诉书怎么弄_网站优化seo培训_酒店网络营销推广方式

【Chrome Extension】一、CSDN计时扩展设计

    • 重点内容
      • 内容脚本 content_scripts
    • 文件目录
        • 1、整体目录
        • 2、manifest.json
        • 3、scripts/content.js
        • 4、css/content.css

重点内容

在这里插入图片描述

内容脚本 content_scripts

1、manifest.json文件配置

{"manifest_version": 3,		# *依赖Chrome插件版本"name": "FeiFeiYeChuan-Tools-CSDN Article Reading Time", # *插件名称"version": "1.0", # *插件版本"description": "Add the reading time to Chrome Extension documentation articles","icons": { # 不同情况下显示的图标"16": "images/logo.png","32": "images/logo.png","48": "images/logo.png","128": "images/logo.png"},"content_scripts": [ # content内容{"js": ["scripts/content.js"],"css": ["css/content.css"],"matches": ["https://*.blog.csdn.net/*","https://blog.csdn.net/*"]}]
}

如上 content_scripts内容脚本:运行读取和修改网页内容的脚本) 主要用于在固定 matches 网页下的执行脚本内容,他们独立于其他扩展程序和托管页面,拥有独立的js,css脚本。

文件目录

1、整体目录

在这里插入图片描述

2、manifest.json
{"manifest_version": 3,"name": "FeiFeiYeChuan-Tools-CSDN Article Reading Time","version": "1.0","description": "Add the reading time to Chrome Extension documentation articles","icons": {"16": "images/logo.png","32": "images/logo.png","48": "images/logo.png","128": "images/logo.png"},"content_scripts": [{"js": ["scripts/content.js"],"css": ["css/content.css"],"matches": ["https://*.blog.csdn.net/*","https://blog.csdn.net/*"]}]
}
3、scripts/content.js
onload = function () {console.log("content.js已加载");const article = document.querySelector(".blog-content-box");console.log('article:', article)// `document.querySelector` may return null if the selector doesn't match anything.if (article) {const text = article.textContent;// console.log('text:', text)const wordMatchRegExp = /\w/g; // Regular expressionconst words = text.matchAll(wordMatchRegExp);// matchAll returns an iterator, convert to array to get word countconst wordCount = [...words].length;console.log("wordCount:", wordCount)const readingTime = Math.round(wordCount / 200);const badge = document.createElement("p");// Use the same styling as the publish information in an article's headerbadge.classList.add("color-secondary-text", "type--caption", 'light');badge.textContent = `⏱️ ${readingTime} min read`;// Support for API reference docsconst heading = document.querySelector(".title-article");heading.insertAdjacentElement("afterend", badge);}
}
4、css/content.css
.light{color: #77a000;
}
关键字:长沙企业建站销售电话_开发公司撤销网签起诉书怎么弄_网站优化seo培训_酒店网络营销推广方式

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: