油猴插件开发必备:VSCode中高效使用Tampermonkey API的10个技巧

news2026/4/4 4:49:26
油猴插件开发必备VSCode中高效使用Tampermonkey API的10个技巧在浏览器扩展开发领域Tampermonkey油猴以其轻量级和灵活性赢得了大量开发者的青睐。作为一款用户脚本管理器它允许开发者通过JavaScript快速定制网页行为而无需构建完整的浏览器扩展。对于已经熟悉VSCode的开发者来说将Tampermonkey API与这款强大的编辑器结合使用能够显著提升开发效率和脚本质量。本文将分享10个在VSCode环境中高效使用Tampermonkey API的实用技巧这些方法都来自实际项目经验能够帮助开发者避免常见陷阱写出更健壮、更易维护的用户脚本。无论你是想自动化日常网页操作还是构建复杂的网页增强工具这些技巧都能为你提供实质性帮助。1. 搭建高效的VSCode开发环境1.1 配置本地开发工作流传统油猴脚本开发往往需要在浏览器插件界面直接编辑代码这种方式既不便于版本控制也缺乏现代IDE的强大功能。通过以下配置可以实现VSCode本地开发与浏览器实时调试的无缝衔接在VSCode中创建专用工作区文件夹安装Tampermonkey浏览器扩展配置脚本元数据头部特别关注require字段// UserScript // name MyCustomScript // namespace http://your-domain.com // version 1.0 // description 自定义功能脚本 // author YourName // match https://target-website.com/* // grant GM_xmlhttpRequest // require file:///path/to/your/local/script.js // /UserScript关键点require字段指向本地脚本文件路径确保浏览器有权限访问本地文件系统需在Tampermonkey设置中启用允许访问本地文件。1.2 必备VSCode扩展推荐提升开发体验的几个关键扩展扩展名称功能描述适用场景ESLintJavaScript代码质量检查保持代码风格一致Prettier代码自动格式化节省手动调整格式时间Live Server本地开发服务器测试需要本地资源的脚本GitLensGit版本控制集成团队协作与版本管理提示配置.vscode/settings.json确保ESLint和Prettier规则一致避免格式冲突。2. 掌握核心API的高效用法2.1 GM_xmlhttpRequest的进阶技巧Tampermonkey的GM_xmlhttpRequest比原生fetch/XHR更强大特别是在跨域请求和处理特殊响应时。以下是一个包含错误处理和超时机制的生产级实现function safeRequest(url, options {}) { return new Promise((resolve, reject) { const details { url, method: options.method || GET, headers: options.headers || {}, timeout: options.timeout || 10000, onload: (response) { if (response.status 200 response.status 300) { try { const data response.responseText; resolve(options.json ? JSON.parse(data) : data); } catch (e) { reject(new Error(解析响应失败: ${e.message})); } } else { reject(new Error(请求失败: ${response.status})); } }, onerror: (error) reject(error), ontimeout: () reject(new Error(请求超时)) }; GM_xmlhttpRequest(details); }); } // 使用示例 async function fetchUserData() { try { const data await safeRequest(https://api.example.com/users, { method: POST, json: true, headers: { Content-Type: application/json } }); console.log(获取数据:, data); } catch (error) { console.error(请求出错:, error.message); } }2.2 GM_addElement的DOM操作最佳实践GM_addElement是动态修改DOM的利器但不当使用可能导致性能问题或内存泄漏。以下是优化建议批量操作减少单独插入元素的次数使用文档片段对复杂结构先构建再插入清理引用移除元素时同时解除事件绑定// 高效批量插入示例 function insertMultipleItems(items) { const fragment document.createDocumentFragment(); items.forEach(item { GM_addElement(fragment, div, { className: item-card, textContent: item.name, onclick: () handleItemClick(item.id) }); }); document.getElementById(container).appendChild(fragment); } // 清理示例 function cleanupDynamicElements() { const elements document.querySelectorAll(.temp-element); elements.forEach(el { el.removeEventListener(click, clickHandler); el.remove(); }); }3. 调试与错误处理策略3.1 利用VSCode调试能力虽然Tampermonkey脚本在浏览器中运行但可以结合VSCode实现更强大的调试在Chrome中启用远程调试chrome.exe --remote-debugging-port9222在VSCode中安装Debugger for Chrome扩展配置.vscode/launch.json{ version: 0.2.0, configurations: [ { type: chrome, request: attach, name: Attach to Chrome, port: 9222, urlFilter: https://target-website.com/*, webRoot: ${workspaceFolder} } ] }3.2 健壮的错误监控实现脚本级的错误捕获和报告// 全局错误处理 window.addEventListener(error, (event) { GM_notification({ text: 脚本错误: ${event.message}, title: 错误报告, silent: false }); // 记录错误到存储 const errors GM_getValue(script_errors, []); errors.push({ message: event.message, stack: event.error.stack, timestamp: Date.now() }); GM_setValue(script_errors, errors.slice(-10)); // 只保留最近10个 }); // API调用包装器 function safeGMCall(method, ...args) { try { if (typeof GM[method] ! function) { throw new Error(GM方法${method}不存在); } return GM[method](...args); } catch (error) { console.error(调用${method}失败:, error); throw error; } }4. 性能优化与资源管理4.1 高效使用GM_setValue/GM_getValue键值存储是Tampermonkey提供的持久化方案但过度使用会影响性能。优化建议批量操作减少单独读写次数数据压缩对大对象使用JSON压缩缓存策略对频繁访问的数据实现内存缓存const valueCache new Map(); function getCachedValue(key, defaultValue) { if (valueCache.has(key)) { return Promise.resolve(valueCache.get(key)); } return new Promise(resolve { const value GM_getValue(key, defaultValue); valueCache.set(key, value); resolve(value); }); } function setCachedValue(key, value) { valueCache.set(key, value); return new Promise(resolve { GM_setValue(key, value); resolve(); }); } // 使用示例 async function updateUserSettings(settings) { await setCachedValue(user_settings, JSON.stringify(settings)); console.log(设置已保存); }4.2 资源加载优化通过require和resource预加载关键资源// UserScript // resource importantCSS https://example.com/styles.css // require https://code.jquery.com/jquery-3.6.0.min.js // /UserScript // 在脚本中使用预加载资源 const css GM_getResourceText(importantCSS); GM_addStyle(css); // 检查jQuery是否加载成功 if (typeof jQuery function) { console.log(jQuery已加载); } else { console.error(jQuery加载失败); }5. 高级功能实现技巧5.1 跨脚本通信方案实现不同Tampermonkey脚本间的安全通信// 发送方脚本 function sendMessageToOtherScript(message) { const event new CustomEvent(TMCrossScriptMsg, { detail: { sender: GM_info.script.name, message, timestamp: Date.now() } }); document.dispatchEvent(event); } // 接收方脚本 document.addEventListener(TMCrossScriptMsg, (event) { const { sender, message } event.detail; if (sender ! GM_info.script.name) { // 避免处理自己发送的消息 console.log(收到来自${sender}的消息:, message); // 处理消息... } });5.2 响应式UI组件构建利用GM_addElement创建可复用的UI组件class ModalDialog { constructor(options) { this.options { title: 提示, content: , buttons: [], ...options }; this.modal null; this.createModal(); } createModal() { this.modal GM_addElement(div, { className: tm-modal, style: position: fixed; z-index: 9999; ... }); GM_addElement(this.modal, div, { className: tm-modal-header, textContent: this.options.title }); const body GM_addElement(this.modal, div, { className: tm-modal-body, innerHTML: this.options.content }); const footer GM_addElement(this.modal, div, { className: tm-modal-footer }); this.options.buttons.forEach(btn { GM_addElement(footer, button, { textContent: btn.text, onclick: () { btn.action(); this.close(); } }); }); document.body.appendChild(this.modal); } close() { if (this.modal this.modal.parentNode) { this.modal.parentNode.removeChild(this.modal); } } } // 使用示例 new ModalDialog({ title: 操作确认, content: p确定要执行此操作吗/p, buttons: [ { text: 取消, action: () console.log(取消操作) }, { text: 确认, action: () console.log(确认操作) } ] });6. 安全最佳实践6.1 输入验证与净化处理用户输入或外部数据时的安全措施function sanitizeInput(input) { if (typeof input ! string) return ; // 移除潜在危险的HTML标签 return input.replace(/script\b[^]*(?:(?!\/script)[^]*)*\/script/gi, ) .replace(/[^]*(|$)/g, ); } // 安全的HTML插入 function safeHTMLInsert(container, html) { const temp document.createElement(div); temp.textContent html; // 自动转义HTML container.innerHTML temp.innerHTML; } // 使用示例 const userInput scriptalert(XSS)/scriptpHello/p; const safeOutput sanitizeInput(userInput); // pHello/p6.2 敏感数据处理安全地处理认证信息和敏感数据// 加密敏感数据 async function encryptData(data, password) { const encoder new TextEncoder(); const dataBuffer encoder.encode(data); const passwordBuffer encoder.encode(password); const keyMaterial await crypto.subtle.importKey( raw, passwordBuffer, { name: PBKDF2 }, false, [deriveKey] ); const salt crypto.getRandomValues(new Uint8Array(16)); const key await crypto.subtle.deriveKey( { name: PBKDF2, salt, iterations: 100000, hash: SHA-256 }, keyMaterial, { name: AES-GCM, length: 256 }, false, [encrypt, decrypt] ); const iv crypto.getRandomValues(new Uint8Array(12)); const encrypted await crypto.subtle.encrypt( { name: AES-GCM, iv }, key, dataBuffer ); return { encrypted: Array.from(new Uint8Array(encrypted)), salt: Array.from(salt), iv: Array.from(iv) }; } // 存储加密数据 async function storeSecureData(key, value, password) { const encrypted await encryptData(value, password); GM_setValue(key, JSON.stringify(encrypted)); }7. 自动化测试策略7.1 单元测试配置在VSCode中设置Tampermonkey脚本的单元测试环境安装测试框架npm install --save-dev jest types/jest配置jest.config.jsmodule.exports { testEnvironment: jsdom, setupFilesAfterEnv: [./jest.setup.js], moduleNameMapper: { ^/(.*)$: rootDir/src/$1 } };创建模拟GM环境的jest.setup.jsglobal.GM { info: { script: { name: test-script, version: 1.0 } }, getValue: jest.fn(), setValue: jest.fn(), xmlhttpRequest: jest.fn() };7.2 测试示例测试GM_xmlhttpRequest的封装函数// 测试代码 describe(safeRequest, () { beforeEach(() { GM.xmlhttpRequest.mockClear(); }); it(应该成功解析JSON响应, async () { GM.xmlhttpRequest.mockImplementation(({ onload }) { onload({ status: 200, responseText: {success: true} }); }); const result await safeRequest(https://api.example.com, { json: true }); expect(result).toEqual({ success: true }); }); it(应该处理请求失败, async () { GM.xmlhttpRequest.mockImplementation(({ onerror }) { onerror(new Error(Network error)); }); await expect(safeRequest(https://api.example.com)) .rejects .toThrow(Network error); }); });8. 构建与发布流程8.1 自动化构建脚本使用Node.js创建构建脚本build.jsconst fs require(fs); const path require(path); const { minify } require(terser); async function buildScript() { const srcPath path.join(__dirname, src, main.js); const metaPath path.join(__dirname, src, meta.js); const distPath path.join(__dirname, dist, script.user.js); // 读取源文件和元数据 const [srcCode, metaCode] await Promise.all([ fs.promises.readFile(srcPath, utf8), fs.promises.readFile(metaPath, utf8) ]); // 代码压缩 const result await minify(srcCode, { compress: true, mangle: true, format: { comments: false } }); if (result.error) { throw result.error; } // 合并元数据和压缩后的代码 const output ${metaCode}\n\n${result.code}; // 确保dist目录存在 await fs.promises.mkdir(path.dirname(distPath), { recursive: true }); await fs.promises.writeFile(distPath, output); console.log(构建成功:, distPath); } buildScript().catch(console.error);8.2 版本管理与更新策略实现智能的脚本更新检查// 在元数据中定义更新URL // updateURL https://example.com/updates/myscript.meta.js // downloadURL https://example.com/updates/myscript.user.js // 在脚本中添加更新检查逻辑 function checkForUpdates() { const lastCheck GM_getValue(last_update_check, 0); const now Date.now(); // 每24小时检查一次更新 if (now - lastCheck 86400000) return; GM_xmlhttpRequest({ method: HEAD, url: GM_info.script.updateURL, onload: function(response) { const remoteLastModified new Date(response.responseHeaders.match(/last-modified:\s*(.*)/i)[1]); const localLastModified new Date(GM_info.script.lastModified); if (remoteLastModified localLastModified) { GM_notification({ title: 脚本更新可用, text: 点击此处安装新版本, onclick: () window.open(GM_info.script.downloadURL) }); } GM_setValue(last_update_check, now); } }); } // 在脚本初始化时调用 checkForUpdates();9. 用户配置与自定义9.1 创建友好的配置界面利用GM_registerMenuCommand构建用户配置系统class ScriptConfig { constructor(defaults) { this.defaults defaults; this.current { ...defaults }; this.loadConfig(); this.setupMenu(); } loadConfig() { const saved GM_getValue(script_config); if (saved) { this.current { ...this.defaults, ...JSON.parse(saved) }; } } saveConfig() { GM_setValue(script_config, JSON.stringify(this.current)); } setupMenu() { GM_registerMenuCommand(⚙️ 脚本设置, () this.showConfigDialog()); } showConfigDialog() { const dialog new ModalDialog({ title: 脚本设置, content: form idconfigForm ${Object.entries(this.current).map(([key, value]) div classform-group label for${key}${key}:/label input type${typeof value boolean ? checkbox : text} id${key} name${key} ${typeof value boolean value ? checked : } ${typeof value ! boolean ? value${value} : } /div ).join()} /form , buttons: [ { text: 保存, action: () this.saveForm() }, { text: 重置, action: () this.resetConfig() } ] }); } saveForm() { const form document.getElementById(configForm); const newConfig { ...this.current }; Object.keys(newConfig).forEach(key { const input form.querySelector([name${key}]); newConfig[key] typeof this.defaults[key] boolean ? input.checked : input.value; }); this.current newConfig; this.saveConfig(); GM_notification({ text: 设置已保存 }); } resetConfig() { this.current { ...this.defaults }; this.saveConfig(); GM_notification({ text: 已恢复默认设置 }); } get(key) { return this.current[key]; } } // 使用示例 const config new ScriptConfig({ darkMode: true, refreshInterval: 30, apiEndpoint: https://api.example.com }); // 获取配置值 if (config.get(darkMode)) { GM_addStyle(body { background: #222; color: #eee; }); }9.2 国际化支持实现多语言脚本界面// 语言资源文件 const i18n { en: { greeting: Hello, settings: Settings, save: Save }, zh: { greeting: 你好, settings: 设置, save: 保存 } }; // 获取用户语言偏好 function getUserLanguage() { const navLang navigator.language.split(-)[0]; return Object.keys(i18n).includes(navLang) ? navLang : en; } // 翻译函数 function t(key) { const lang getUserLanguage(); return i18n[lang][key] || i18n.en[key] || key; } // 使用示例 GM_registerMenuCommand(t(settings), showSettings); function showSettings() { const dialog new ModalDialog({ title: t(settings), buttons: [{ text: t(save), action: saveSettings }] }); }10. 高级集成技巧10.1 与浏览器扩展通信实现Tampermonkey脚本与浏览器扩展的交互// 发送消息到扩展 function sendToExtension(message) { return new Promise((resolve) { const eventId ext_response_${Date.now()}; document.addEventListener(eventId, (e) { resolve(e.detail); }, { once: true }); document.dispatchEvent(new CustomEvent(to_extension, { detail: { message, eventId } })); }); } // 扩展端的content script应监听to_extension事件并响应 // 使用示例 async function fetchExtensionData() { try { const data await sendToExtension({ type: get_data }); console.log(从扩展获取的数据:, data); } catch (error) { console.error(与扩展通信失败:, error); } }10.2 与网页内容脚本协同工作安全地与页面原有脚本交互// 注入内容脚本 function injectContentScript(code) { const script document.createElement(script); script.textContent (function() { ${code} })();; document.documentElement.appendChild(script); script.remove(); } // 与页面上下文通信 function callPageFunction(funcName, ...args) { return new Promise((resolve) { const callbackName callback_${Date.now()}; window[callbackName] (result) { resolve(result); delete window[callbackName]; }; injectContentScript( try { const result window.${funcName}(${args.map(a JSON.stringify(a)).join(,)}); window.parent.postMessage({ type: ${callbackName}, result }, *); } catch (error) { window.parent.postMessage({ type: ${callbackName}, error: error.message }, *); } ); window.addEventListener(message, function listener(event) { if (event.data.type callbackName) { if (event.data.error) { reject(new Error(event.data.error)); } else { resolve(event.data.result); } window.removeEventListener(message, listener); } }); }); } // 使用示例 async function getPageData() { try { const data await callPageFunction(getUserData); console.log(获取页面数据:, data); } catch (error) { console.error(调用页面函数失败:, error); } }在实际项目中我发现将Tampermonkey脚本拆分为多个功能模块通过require引入能大幅提升代码可维护性。每个模块专注于特定功能主脚本只负责协调和初始化。这种架构特别适合复杂脚本的开发也便于团队协作。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2476387.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…