Skip to content

Commit 4e32015

Browse files
authored
feat: add popup page for extension installation guide (#236)
1 parent 2cb144e commit 4e32015

6 files changed

Lines changed: 107 additions & 14 deletions

File tree

apps/extension/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"48": "icons/cose_48.png",
6464
"128": "icons/cose_128.png"
6565
},
66-
"default_title": "COSE"
66+
"default_title": "COSE",
67+
"default_popup": "popup.html"
6768
},
6869
"background": {
6970
"service_worker": "bundles/background.js",

apps/extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cose-extension",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"description": "Create Once, Sync Everywhere. 一键将文章同步到多个平台",
55
"type": "module",
66
"scripts": {

apps/extension/src/background.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,6 @@ chrome.runtime.onStartup.addListener(() => {
350350
initDynamicRules()
351351
})
352352

353-
// 点击扩展图标时打开 md.doocs.org
354-
chrome.action.onClicked.addListener(() => {
355-
chrome.tabs.create({ url: 'https://md.doocs.org' })
356-
})
357-
358353
// 当前同步任务的 Tab Group ID
359354
let currentSyncGroupId = null
360355
// 存储平台用户信息
@@ -1088,8 +1083,11 @@ async function syncToPlatform(platformId, content) {
10881083
html = html.replace(/^> (.+)$/gm, '<blockquote>$1</blockquote>')
10891084

10901085
// 处理水平分割线
1091-
html = html.replace(/^---$/gm, '<hr />')
1092-
html = html.replace(/^\*\*\*$/gm, '<hr />')
1086+
// 注意: X Articles 忽略 <hr> 标签,需要通过 Insert > Divider 菜单插入
1087+
// 自动同步无法使用菜单,这里保留 hr 但用户可能需要手动调整
1088+
// 或者可以考虑用视觉分隔符如 --- 文本替代
1089+
html = html.replace(/^---$/gm, '<p>---</p>')
1090+
html = html.replace(/^\*\*\*$/gm, '<p>***</p>')
10931091

10941092
// 处理图片
10951093
html = html.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '<img src="$2" alt="$1" style="max-width: 100%;" />')
@@ -1104,7 +1102,8 @@ async function syncToPlatform(platformId, content) {
11041102

11051103
// ========== 第三阶段:恢复保护的内容 ==========
11061104

1107-
// 恢复代码块(使用样式化的 pre/code)
1105+
// 恢复代码块 - X Articles 不支持 <pre><code>,转换为 blockquote
1106+
// 参考 x-article-publisher skill 的实现
11081107
codeBlocks.forEach((block, index) => {
11091108
const escapedCode = block.code
11101109
.replace(/&/g, '&amp;')
@@ -1113,19 +1112,25 @@ async function syncToPlatform(platformId, content) {
11131112
.replace(/"/g, '&quot;')
11141113
.replace(/'/g, '&#039;')
11151114

1116-
const langLabel = block.lang ? `<div style="background: #e1e4e8; padding: 4px 12px; font-size: 12px; color: #586069; border-radius: 6px 6px 0 0;">${block.lang}</div>` : ''
1117-
const codeHtml = `<div style="margin: 16px 0;">${langLabel}<pre style="background: #f6f8fa; padding: 16px; border-radius: ${block.lang ? '0 0 6px 6px' : '6px'}; overflow-x: auto; font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 14px; line-height: 1.45; margin: 0; white-space: pre-wrap; word-wrap: break-word;"><code>${escapedCode}</code></pre></div>`
1115+
// 将代码行用 <br> 连接,包装在 blockquote 中
1116+
// X Articles 原生支持 blockquote,这是最可靠的代码块显示方式
1117+
const lines = escapedCode.split('\n').filter(line => line.trim())
1118+
const formattedCode = lines.join('<br>')
1119+
const langPrefix = block.lang ? `<strong>${block.lang}</strong><br>` : ''
1120+
const codeHtml = `<blockquote>${langPrefix}${formattedCode}</blockquote>`
11181121

11191122
html = html.replace(`__CODE_BLOCK_${index}__`, codeHtml)
11201123
})
11211124

1122-
// 恢复行内代码
1125+
// 恢复行内代码 - X Articles 对 inline style 支持有限
1126+
// 使用简单的 <code> 标签,依赖平台默认样式
11231127
inlineCodes.forEach((code, index) => {
11241128
const escapedCode = code
11251129
.replace(/&/g, '&amp;')
11261130
.replace(/</g, '&lt;')
11271131
.replace(/>/g, '&gt;')
1128-
const codeHtml = `<code style="background: #f6f8fa; padding: 2px 6px; border-radius: 3px; font-family: 'SF Mono', Consolas, monospace; font-size: 0.9em;">${escapedCode}</code>`
1132+
// 简化为纯 code 标签,X Articles 会应用默认样式
1133+
const codeHtml = `<code>${escapedCode}</code>`
11291134

11301135
html = html.replace(`__INLINE_CODE_${index}__`, codeHtml)
11311136
})

apps/extension/src/popup.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<style>
6+
* {
7+
margin: 0;
8+
padding: 0;
9+
box-sizing: border-box;
10+
}
11+
body {
12+
width: 320px;
13+
padding: 20px;
14+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
15+
background: #fff;
16+
color: #333;
17+
}
18+
.container {
19+
text-align: center;
20+
}
21+
h1 {
22+
font-size: 18px;
23+
font-weight: 600;
24+
margin-bottom: 12px;
25+
}
26+
p {
27+
font-size: 13px;
28+
line-height: 1.6;
29+
color: #333;
30+
margin-bottom: 16px;
31+
}
32+
p a {
33+
color: #FE5200;
34+
text-decoration: none;
35+
}
36+
p a:hover {
37+
text-decoration: underline;
38+
}
39+
.btn {
40+
display: inline-block;
41+
padding: 10px 20px;
42+
background: #FE5200;
43+
color: #fff;
44+
text-decoration: none;
45+
border-radius: 8px;
46+
font-size: 14px;
47+
font-weight: 500;
48+
transition: background 0.2s;
49+
border: 1px solid #e64a00;
50+
cursor: pointer;
51+
}
52+
.btn:hover {
53+
background: #e64a00;
54+
}
55+
.divider {
56+
margin: 16px 0;
57+
border-top: 1px solid #e5e5e5;
58+
}
59+
.hint {
60+
font-size: 12px;
61+
color: #666;
62+
}
63+
</style>
64+
</head>
65+
<body>
66+
<div class="container">
67+
<h1>COSE - 多平台文章同步</h1>
68+
<p>插件安装完成!</p>
69+
<p>打开<a href="https://github.com/doocs/md" target="_blank">自托管的编辑器</a>即可自动检测到,无需多余配置。</p>
70+
<div class="divider"></div>
71+
<p class="hint">没有自托管编辑器?</p>
72+
<a href="https://md.doocs.org" target="_blank" class="btn" id="openOfficial">也可使用官网编辑器</a>
73+
</div>
74+
<script src="bundles/popup.js" type="module"></script>
75+
</body>
76+
</html>

apps/extension/src/popup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Popup script for COSE extension
2+
document.getElementById('openOfficial').addEventListener('click', (e) => {
3+
e.preventDefault()
4+
chrome.tabs.create({ url: 'https://md.doocs.org' })
5+
window.close()
6+
})

apps/extension/vite.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default defineConfig({
2121
content: resolve(__dirname, 'src/content.js'),
2222
inject: resolve(__dirname, 'src/inject.js'),
2323
offscreen: resolve(__dirname, 'src/offscreen.js'),
24+
popup: resolve(__dirname, 'src/popup.js'),
2425
},
2526
output: {
2627
entryFileNames: 'bundles/[name].js',
@@ -42,6 +43,10 @@ export default defineConfig({
4243
src: 'src/offscreen.html',
4344
dest: '.',
4445
},
46+
{
47+
src: 'src/popup.html',
48+
dest: '.',
49+
},
4550
{
4651
src: 'assets',
4752
dest: '.',

0 commit comments

Comments
 (0)