Files
web-context-extension/icons/generate-icons.js
hubian 7f7c13bf7f 初始化网页助手浏览器插件
功能:
- 右键菜单扩展(收藏、总结、深度研究)
- 智能页面内容提取(文本+图片)
- 收藏管理界面
- AI总结与深度研究
- 支持自定义API配置(OpenAI/Ollama)

技术:
- Chrome Extension Manifest V3
- Service Worker后台脚本
- Content Script内容提取
- 智能文章主体识别
- 本地Storage收藏存储

图标已生成,可替换为更好设计
2026-04-08 10:54:50 +08:00

105 lines
2.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 使用Node.js生成PNG图标
// 运行: node generate-icons.js
const fs = require('fs')
const path = require('path')
// 简单的PNG生成器使用PNG文件格式规范
function createSimplePNG(width, height, bgColor) {
// PNG文件签名
const signature = Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])
// IHDR chunk (图像头)
const ihdrData = Buffer.alloc(13)
ihdrData.writeUInt32BE(width, 0) // width
ihdrData.writeUInt32BE(height, 4) // height
ihdrData[8] = 8 // bit depth
ihdrData[9] = 2 // color type (RGB)
ihdrData[10] = 0 // compression method
ihdrData[11] = 0 // filter method
ihdrData[12] = 0 // interlace method
const ihdrChunk = createChunk('IHDR', ihdrData)
// IDAT chunk (图像数据)
// 创建简单的纯色图像
const rawData = Buffer.alloc(height * (1 + width * 3))
let offset = 0
const r = bgColor.r
const g = bgColor.g
const b = bgColor.b
for (let y = 0; y < height; y++) {
rawData[offset++] = 0 // filter type: none
for (let x = 0; x < width; x++) {
rawData[offset++] = r
rawData[offset++] = g
rawData[offset++] = b
}
}
// 使用zlib压缩
const zlib = require('zlib')
const compressedData = zlib.deflateSync(rawData)
const idatChunk = createChunk('IDAT', compressedData)
// IEND chunk (图像结束)
const iendChunk = createChunk('IEND', Buffer.alloc(0))
// 组合所有chunk
return Buffer.concat([signature, ihdrChunk, idatChunk, iendChunk])
}
function createChunk(type, data) {
const length = Buffer.alloc(4)
length.writeUInt32BE(data.length, 0)
const typeBuffer = Buffer.from(type, 'ascii')
// CRC32计算
const crcData = Buffer.concat([typeBuffer, data])
const crc = crc32(crcData)
const crcBuffer = Buffer.alloc(4)
crcBuffer.writeUInt32BE(crc >>> 0, 0)
return Buffer.concat([length, typeBuffer, data, crcBuffer])
}
// CRC32计算
function crc32(buffer) {
let crc = 0xFFFFFFFF
const table = getCrc32Table()
for (let i = 0; i < buffer.length; i++) {
crc = (crc >>> 8) ^ table[(crc ^ buffer[i]) & 0xFF]
}
return crc ^ 0xFFFFFFFF
}
function getCrc32Table() {
const table = new Uint32Array(256)
for (let i = 0; i < 256; i++) {
let c = i
for (let j = 0; j < 8; j++) {
c = (c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1)
}
table[i] = c
}
return table
}
// 生成图标
const sizes = [16, 48, 128]
const color = { r: 102, g: 126, b: 234 } // #667eea 紫色
sizes.forEach(size => {
const png = createSimplePNG(size, size, color)
const filename = path.join(__dirname, `icon${size}.png`)
fs.writeFileSync(filename, png)
console.log(`生成: ${filename} (${size}x${size})`)
})
console.log('图标生成完成!')
console.log('请替换为更好的图标设计,推荐使用 https://favicon.io/')