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

改写自己的浏览器插件工具 myChromeTools - 详解

1. 起因, 目的:

前面我写过, 自己的一个浏览器插件小工具

2. 先看效果

请添加图片描述

3. 过程:

代码 1, 模拟鼠标自然滚动
// 处理滚动控制逻辑,响应 popup.js 发送的 startScroll 和 stopScroll 消息。
(
function (
) {
let scrollInterval =
null
;
function smoothAutoScroll(
) {
if (scrollInterval) {
clearInterval(scrollInterval)
;
}
scrollInterval = setInterval((
) =>
{
const scrollHeight = document.documentElement.scrollHeight;
const windowHeight = window.innerHeight;
const currentScroll = window.scrollY;
if (currentScroll + windowHeight >= scrollHeight - 1
) {
window.scrollTo({
top: 0
, behavior: 'smooth'
}
)
;
}
else {
window.scrollBy({
top: 2
, behavior: 'smooth'
}
)
;
}
}
, 16
)
;
// 每16毫秒滚动一次,约60fps
}
function stopScroll(
) {
if (scrollInterval) {
clearInterval(scrollInterval)
;
scrollInterval =
null
;
}
}
chrome.runtime.onMessage.addListener((message, sender, sendResponse
) =>
{
if (message.action === 'startScroll'
) {
smoothAutoScroll(
)
;
}
else
if (message.action === 'stopScroll'
) {
stopScroll(
)
;
}
}
)
;
}
)(
)
;

4. 结论 + todo


希望对大家有帮助。

http://www.jsqmd.com/news/9483/

相关文章:

  • 通过litestream 进行sqlite-vec 数据备份以及恢复
  • 对于路由使用的ref的疑问
  • Paypal 设置不自动换汇
  • 诺贝尔生理与医学奖颁给这项革命技术,多家中国公司已布局!(附名单)
  • 钱璐璐,唯一通讯发Nature,作者仅2人!
  • 华为员工工资待遇表:
  • 体验mcp服务的开发集成和演示过程 - 智慧园区
  • AI技术全景解析:从架构设计到社会影响
  • 随手记 | 关于AI最新趋势和未来发展方向探讨
  • # Redis vs ElasticSearch 搜索性能对比
  • Redis部署策略
  • AI骚扰电话:技术发展的双刃剑效应
  • 早期白板编程案例
  • 【Claude 3.5 Sonnet 生成】AI时代软件行业发展趋势与开发者成长路径分析报告
  • 何夜无雨 - Ishar
  • caddy搭建静态+PHP+伪静态Web服务器
  • 全自动 AI 视频创作与发布工具:LuoGen-agent
  • 静态库.a与.so库文件的生成与使用
  • CF2145D Inversion Value of a Permutation
  • 牛客刷题-Day8
  • 高三闲话 #2
  • D. Inversion Value of a Permutation edu div2
  • 个人博客公告
  • 一个刚大一的普通大学生
  • 通过利用百度对于外链的检测算法上的缺陷
  • git常用助记
  • 云岚到家项目文字稿
  • 软件工程 第一次作业
  • 教会音控组侍奉中的工序主义实践
  • 用 Kotlin 调用 Tesseract 实现验证码识别