2025年3月

assume webstorm program location /opt/webstorm

sudo vim /usr/share/applications/webstorm.desktop

type in

[Desktop Entry]
Name=webstorm
Comment=Run My Program
Exec=/opt/webstorm/bin/webstorm
Icon=/opt/webstorm/icon.png
Terminal=false
Type=Application
Categories=Utility;Application;

manifest.json

{
  "name": "__MSG_name__",
  "default_locale": "en",
  "version": "1.0.0",
  "manifest_version": 3,
  "description": "__MSG_description__",
  "background": {
    "service_worker": "background.js"
  },
  "permissions": [
    "declarativeNetRequest",
    "declarativeNetRequestWithHostAccess"
  ],
  "host_permissions": [
    "*://*/*"
  ]
}

background.js

// 生成动态规则函数
const createCspRule = (extensionId) => ({
  id: 1001,
  priority: 1001,
  action: {
    type: "modifyHeaders",
    responseHeaders: [
      {
        header: "Content-Security-Policy",
        operation: "set",
        value: `frame-ancestors 'self' chrome-extension://${extensionId}`
      },
      { header: "X-Frame-Options", operation: "remove" }
    ]
  },
  condition: {
    urlFilter: "|*://*/*",
    resourceTypes: ["sub_frame"]
  }
});

// 安装时更新规则
chrome.runtime.onInstalled.addListener(async () => {
  const extensionId = chrome.runtime.id;

  await chrome.declarativeNetRequest.updateDynamicRules({
    removeRuleIds: [1001],
    addRules: [createCspRule(extensionId)]
  });

  console.log('动态规则已更新,当前扩展ID:', extensionId);
});

删除tag

# 删除本地tag
git tag --delete tagName
# 删除远程tag
git push origin --delete tag tagName

删除分支

# 删除本地分支
git tag --delete branchName
# 删除远程分支
git push origin --delete  branchName

目录结构

tree .
.
├── assets
│   ├── logo.png
│   └── upload.png
├── css
│   ├── chunk-vendors.css
│   ├── content.css
│   ├── popup.css
│   └── sidePanel.css
├── favicon.ico
├── index.html
├── js
│   ├── background.js
│   ├── content.js
├── manifest.json
├── options.html
├── popup.html

content.js

// content-script.js
//assets/img.avif是根目录下
async function autoUploadExtensionImage(imagePath = 'assets/upload.png') {
    try {
        // 1. 获取扩展内图片URL
        const imageUrl = chrome.runtime.getURL(imagePath);
        console.log('扩展资源URL:', imageUrl);

        // 2. 直接获取二进制数据
        const response = await fetch(imageUrl);
        if (!response.ok) throw new Error(`HTTP错误: ${response.status}`);

        // 3. 转换为File对象
        const blob = await response.blob();
        const file = new File([blob], 'auto_upload.png', {
            type: blob.type || 'image/png',
            lastModified: Date.now()
        });

        // 4. 执行上传操作
        const input = document.querySelector('input[type="file"]');
        const dataTransfer = new DataTransfer();
        dataTransfer.items.add(file);
        input.files = dataTransfer.files;

        // 5. 触发完整事件链
        ['input', 'change'].forEach(eventType => {
            input.dispatchEvent(new Event(eventType, {bubbles: true}));
        });
    } catch (error) {
        console.error('自动化上传失败:', error);
        throw error;
    }
}