d63074be71
- 所有自动化脚本、测试文件路径从旧工作区迁移到 /root/openclaw-workspace/projects/yu-zhi-ran/ - 保持项目独立于 OpenClaw 工作区管理 - 后端 run.sh 路径更新
69 lines
3.0 KiB
JavaScript
69 lines
3.0 KiB
JavaScript
// 微信公众号编辑器自动填充脚本
|
||
// 使用方法:在VNC的Chrome中打开编辑器,按F12 → Console → 粘贴此代码 → Enter
|
||
|
||
const markdownTitle = "种菜一年,焦虑降了43%:我在阳台治愈了自己";
|
||
const markdownBody = `[此处粘贴2600字正文]
|
||
|
||
(请从 content/drafts/001-wechat.md 复制正文内容)`;
|
||
|
||
// 查找标题输入框
|
||
const titleInput = document.querySelector('.rich_media_title input[type="text"]')
|
||
|| document.querySelector('input[placeholder*="标题"]')
|
||
|| document.querySelector('[data-role="title"] input');
|
||
|
||
if (!titleInput) {
|
||
console.error("❌ 未找到标题输入框,请确认已打开编辑器");
|
||
console.log("尝试查找所有 inputs:", document.querySelectorAll('input').length);
|
||
console.log("页面标题:", document.title);
|
||
console.log("URL:", window.location.href);
|
||
} else {
|
||
console.log("✅ 找到标题输入框:", titleInput);
|
||
titleInput.focus();
|
||
titleInput.value = markdownTitle;
|
||
titleInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||
console.log("✅ 标题已填写");
|
||
}
|
||
|
||
// 查找正文编辑器(微信公众号使用 contenteditable)
|
||
const editor = document.querySelector('.rich_media_content [contenteditable="true"]')
|
||
|| document.querySelector('[data-role="editor"]')
|
||
|| document.querySelector('.editor')
|
||
|| document.querySelector('#js_content')
|
||
|| document.querySelector('.weui-desktop-editor__editable');
|
||
|
||
if (!editor) {
|
||
console.error("❌ 未找到正文编辑器");
|
||
console.log(".rich_media_content:", !!document.querySelector('.rich_media_content'));
|
||
console.log("contenteditable elements:", document.querySelectorAll('[contenteditable]').length);
|
||
} else {
|
||
console.log("✅ 找到正文编辑器:", editor);
|
||
editor.focus();
|
||
// 清空现有内容
|
||
editor.innerHTML = '';
|
||
|
||
// 将Markdown段落转换为HTML(简单处理:段落间用<p>,换行用<br>)
|
||
const paragraphs = markdownBody.split('\n\n').filter(p => p.trim());
|
||
editor.innerHTML = paragraphs.map(p => {
|
||
// 处理列表、粗体等基础Markdown
|
||
let html = p
|
||
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>') // 粗体
|
||
.replace(/\*(.*?)\*/g, '<em>$1</em>') // 斜体
|
||
.replace(/^[\*\-]\s+(.*)$/gm, '<li>$1</li>') // 列表
|
||
.replace(/^(\d+)\.\s+(.*)$/gm, '<li>$2</li>') // 有序列表
|
||
.replace(/\n/g, '<br>'); // 换行
|
||
return `<p>${html}</p>`;
|
||
}).join('');
|
||
|
||
console.log("✅ 正文已填充(长度:", editor.innerText.length, "字)");
|
||
}
|
||
|
||
// 上传封面图(如需自动上传)
|
||
const coverPath = "/root/openclaw-workspace/projects/yu-zhi-ran/content/publishing/images/05-封面图.png";
|
||
console.log("📸 封面上传:请手动点击编辑器图片按钮,选择封面图文件");
|
||
console.log(" 文件路径:", coverPath);
|
||
|
||
console.log("\n✅ 自动填充完成!请手动:");
|
||
console.log(" 1. 点击编辑器右侧'从正文选择'设置封面");
|
||
console.log(" 2. 填写摘要和标签");
|
||
console.log(" 3. 保存草稿");
|