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

chrome插件开发(二)

注:本文章中所有内容仅供学习交流,不可用于任何商业用途和非法用途,否则后果自负,如有侵权,请联系作者立即删除!

书接上文,我们还可以给插件增加一些功能
比如给插件加上一个页面,然后可以在这个页面上提交表单来修改配置,这样就不会每次填表都只能填代码中固定的数值了
于是我们添加popup.html已经popup.js分别用来当作插件的前端页面已经信息收集函数。

popul.html

<!DOCTYPE html>
<html>
<head><title>Auto-Filler Settings</title><style>body {width: 300px;padding: 15px;font-family: Arial, sans-serif;}.form-group {margin-bottom: 15px;}label {display: block;margin-bottom: 5px;font-weight: bold;}input {width: 100%;padding: 8px;box-sizing: border-box;}button {background-color: #4CAF50;color: white;border: none;padding: 10px 15px;text-align: center;text-decoration: none;display: inline-block;font-size: 14px;margin: 4px 2px;cursor: pointer;width: 100%;}.status {margin-top: 10px;padding: 8px;border-radius: 4px;display: none;}.success {background-color: #dff0d8;color: #3c763d;}</style>
</head>
<body>
<div class="form-group"><label for="full_name">Manager Group Name:</label><input type="text" id="full_name" placeholder="Enter Full Name">
</div><div class="form-group"><label for="phone">Manager phone:</label><input type="text" id="phone" placeholder="Enter phone">
</div><div class="form-group"><label for="birthdate">Manager birthdate:</label><input type="text" id="birthdate" placeholder="Enter birthdate">
</div><div class="form-group"><label for="password">password:</label><input type="text" id="password" placeholder="Enter password">
</div><div class="form-group"><label for="email">email:</label><input type="text" id="email" placeholder="Enter email">
</div><div class="form-group"><label for="confirm_password">Confirm Email:</label><input type="text" id="confirm_password" placeholder="Confirm password">
</div><div class="form-group"><label for="country">country:</label><input type="text" id="country" placeholder="Enter country">
</div><button id="save">Save Settings</button><div id="status" class="status success">Settings saved!</div><script src="popup.js"></script>
</body>
</html>

popup.js

document.addEventListener('DOMContentLoaded', function () {// Load saved settingschrome.storage.sync.get(['full_name', 'phone', 'birthdate', 'email', 'password', 'confirm_password', 'country'], function (data) {document.getElementById('full_name').value = data.full_name || 'Klook Travel';document.getElementById('phone').value = data.phone || 'Klook';document.getElementById('birthdate').value = data.birthdate || 'Italy';document.getElementById('password').value = data.password || 'Rome';document.getElementById('email').value = data.email || 'inventory@klook.com';document.getElementById('confirm_password').value = data.confirm_password || 'inventory@klook.com';document.getElementById('country').value = data.country || 'Inglese';});// Save settingsdocument.getElementById('save').addEventListener('click', function () {const full_name = document.getElementById('full_name').value;const confirm_password = document.getElementById('confirm_password').value;const phone = document.getElementById('phone').value;const country = document.getElementById('country').value;const email = document.getElementById('email').value;const birthdate = document.getElementById('birthdate').value;const password = document.getElementById('password').value;chrome.storage.sync.set({full_name: full_name,phone: phone,email: email,birthdate: birthdate,password: password,confirm_password: confirm_password,country: country});});
});

这里解释一下相关的几个函数
chrome.storage.sync.get主要用于从浏览器存储的数据中拿数据
chrome.storage.sync.set则是网浏览器中存数据
这俩相互配合就可以搞定我们想要的修改固定配置的操作

跟之前一里面的不是百分百配套,少了几个位置的填充,当作给大伙学习了

http://www.dtcms.com/a/350595.html

相关文章:

  • vue家教预约平台设计与实现(代码+数据库+LW)
  • 驱动-热插拔-Netlink广播监听内核状态
  • HarmonyOS实战(DevEco AI篇)—CodeGenie + DeepSeek构建鸿蒙开发的超级外挂工作流
  • rust语言 (1.88) egui (0.32.1) 学习笔记(逐行注释)(十九)子窗口
  • 您的连接不是私密连接问题解决
  • 借Copilot之力,实现办公效率的跃升
  • 数据库原理及应用_数据库基础_第2章关系数据库标准语言SQL_索引和视图
  • 软件使用教程(二):VS Code的Copilot、Git设置与使用
  • 复制和下载飞书文档的方法教程
  • Unity开发如何实现换装技术
  • Ubuntu 14.10 i386桌面版安装教程(U盘启动详细步骤-附安装包下载)​
  • LeetCode 100题(3)(10题)
  • 实用电脑小工具分享,守护电脑隐私与提升效率21/64
  • CANopen - DCF(Device Configuration File) 介绍
  • 平安产险青海分公司助力国家电投黄河公司安全生产
  • 2024鸿蒙样题需要掌握的知识点
  • Shopify 集合页实现自定义广告位插入(支持分页)
  • C++ 指针与引用面试深度解析
  • k8s数据存储
  • PMP项目管理知识点-④ 项⽬整合管理
  • 3-2.Python 函数 - None(None 概述、None 应用场景)
  • Flink的CheckPoint与SavePoint
  • 使用 Prometheus 监控服务器节点:Node Exporter 详解与配置
  • 【2025】政策变动
  • 从认识Docker到安装
  • 深分页实战
  • 服务注册信息丢失ERROR 2003 (HY000):Can‘t connect to MySQL server on ‘localhost’(10061)
  • 数据结构青铜到王者第三话---ArrayList与顺序表(1)
  • 【MTCNN网络结构记忆卡片】--003nets.py
  • STM32之DMA详解