当前位置: 首页 > news >正文

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

【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;
}
http://www.lryc.cn/news/508982.html

相关文章:

  • C语言——数据在内存中的存储
  • Python(二)str、list、tuple、dict、set
  • 如何在谷歌浏览器中设置邮件客户端
  • Robot Framework搭建自动化测试框架
  • Linux——字符设备驱动控制LED
  • 云边端架构的优势是什么?面临哪些挑战?
  • Effective C++ 条款 01:视 C++ 为一个语言联邦
  • Redis分布式锁释放锁是否必须用lua脚本?
  • JVM系列(十三) -常用调优工具介绍
  • 数据中心虚拟化与高可用性架构实施指南
  • 对文件内的文件名生成目录,方便查阅
  • leetcode hot100 轮转数组
  • 定位方式:css
  • 谷歌浏览器的网络连接问题解决方案
  • 保护模式基本概念
  • Linux程序设计(第四版)| 学习笔记
  • 【Python-中级】Python中的线程池:ThreadPoolExecutor
  • 医疗信息系统有哪些
  • JVM系列(十二) -常用调优命令汇总
  • 修改采购订单BAPI学习研究-BAPI_PO_CHANGE
  • 使用uniapp开发微信小程序-框架搭建
  • 雅思真题短语(九)
  • 系统压力测试助手——stress-ng
  • java如何使用poi-tl在word模板里渲染多张图片
  • UE5 UHT GENERATED_BODY() GENERATED_USTRUCT_BODY()
  • 内网穿透ubuntu20 docker coplar
  • windows C++ TCP客户端
  • Linux xargs 命令使用教程
  • 什么是异步处理
  • 【解决问题】Java2DRenderer生成图片时中文乱码 Linux安装字体