@opentiny/webmcp-cli 0.0.4 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/dist/bin.cjs +188 -54
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +188 -54
- package/dist/bin.js.map +1 -1
- package/dist/index.cjs +107 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +107 -40
- package/dist/index.js.map +1 -1
- package/dist/inject-bundle.js +3860 -2035
- package/dist/webmcp-tools/creator.xiaohongshu.com.js +1 -1
- package/dist/webmcp-tools/editor.csdn.net.js +200 -10
- package/dist/webmcp-tools/excalidraw.com.js +1 -1
- package/dist/webmcp-tools/juejin.cn.js +24455 -9
- package/dist/webmcp-tools/my.oschina.net.js +176 -34
- package/dist/webmcp-tools/segmentfault.com.js +1012 -0
- package/dist/webmcp-tools/www.baidu.com.js +1 -1
- package/dist/webmcp-tools/xiaohongshu.com.js +1 -1
- package/dist/webmcp-tools/zhuanlan.zhihu.com.js +2493 -0
- package/package.json +11 -6
|
@@ -2,44 +2,56 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
(() => {
|
|
4
4
|
// webmcp-tools/my.oschina.net/index.ts
|
|
5
|
+
function sleep(ms) {
|
|
6
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
7
|
+
}
|
|
8
|
+
function toToolResult(data) {
|
|
9
|
+
return {
|
|
10
|
+
content: [{ type: "text", text: JSON.stringify(data) }]
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function isOschinaWritePage() {
|
|
14
|
+
return location.href.startsWith("https://my.oschina.net/u") && location.href.endsWith("/blog/ai-write");
|
|
15
|
+
}
|
|
16
|
+
function readArticleFromEditor() {
|
|
17
|
+
const titleInput = document.querySelector(".title-input-container .title-input");
|
|
18
|
+
const title = titleInput?.value?.trim() || "";
|
|
19
|
+
const editor = document.querySelector(".v-md-textarea-editor textarea");
|
|
20
|
+
const content = editor?.value || "";
|
|
21
|
+
return { title, content };
|
|
22
|
+
}
|
|
5
23
|
var mcp = navigator.modelContext;
|
|
6
24
|
if (!mcp || typeof mcp.registerTool !== "function") {
|
|
7
|
-
console.warn("[webmcp-tools] my.oschina.net:
|
|
25
|
+
console.warn("[webmcp-tools] my.oschina.net: document.modelContext.registerTool \u672A\u5C31\u7EEA\uFF0C\u8DF3\u8FC7\u6CE8\u5165");
|
|
8
26
|
} else if (!window.__webmcptools_myoschinanet) {
|
|
9
|
-
;
|
|
10
|
-
window.__webmcptools_myoschinanet = true;
|
|
11
27
|
try {
|
|
12
28
|
mcp.registerTool({
|
|
13
29
|
name: "create_article",
|
|
14
30
|
title: "\u53D1\u5E03\u65B0\u6587\u7AE0",
|
|
15
|
-
description: "\u63A5\u6536\u6587\u7AE0\u7684\u6807\u9898\u548C\u6B63\u6587\uFF0C\u5C06\u5B83\u4EEC\u586B\u5199\u5230\
|
|
31
|
+
description: "\u63A5\u6536\u6587\u7AE0\u7684\u6807\u9898\u548C\u6B63\u6587\uFF0C\u5C06\u5B83\u4EEC\u586B\u5199\u5230\u5F00\u6E90\u4E2D\u56FD\u7F16\u8F91\u5668\u4E2D\u3002",
|
|
16
32
|
inputSchema: {
|
|
17
33
|
type: "object",
|
|
18
34
|
properties: {
|
|
19
35
|
title: {
|
|
20
36
|
type: "string",
|
|
21
|
-
description: "\u6587\u7AE0\u6807\u9898\uFF0C\u5FC5\u586B\uFF0C
|
|
37
|
+
description: "\u6587\u7AE0\u6807\u9898\uFF0C\u5FC5\u586B\uFF0C\u5EFA\u8BAE\u4E0D\u8D85\u8FC7 100 \u5B57\uFF0C\u4E0D\u5141\u8BB8\u6709\u7279\u6B8A\u7B26\u53F7\u5F71\u54CD\u547D\u4EE4\u884C\u53C2\u6570\u89E3\u6790"
|
|
22
38
|
},
|
|
23
39
|
content: {
|
|
24
40
|
type: "string",
|
|
25
|
-
description: "\u6587\u7AE0\u5185\u5BB9\
|
|
41
|
+
description: "\u6587\u7AE0\u5185\u5BB9\u7684 Base64 \u7F16\u7801\u5B57\u7B26\u4E32\uFF0C\u5FC5\u586B\u3002"
|
|
26
42
|
}
|
|
27
43
|
},
|
|
28
44
|
required: ["title", "content"]
|
|
29
45
|
},
|
|
30
|
-
execute: async ({
|
|
31
|
-
uid,
|
|
32
|
-
title,
|
|
33
|
-
content
|
|
34
|
-
}) => {
|
|
46
|
+
execute: async ({ title, content }) => {
|
|
35
47
|
if (!title?.trim()) {
|
|
36
48
|
throw new Error("\u53C2\u6570 title \u4E0D\u80FD\u4E3A\u7A7A");
|
|
37
49
|
}
|
|
38
50
|
if (!content?.trim()) {
|
|
39
51
|
throw new Error("\u53C2\u6570 content \u4E0D\u80FD\u4E3A\u7A7A");
|
|
40
52
|
}
|
|
41
|
-
if (!(
|
|
42
|
-
throw new Error(
|
|
53
|
+
if (!isOschinaWritePage()) {
|
|
54
|
+
throw new Error("\u5F53\u524D\u9875\u9762\u4E0D\u662F\u53D1\u5E03\u9875\u9762\uFF0C\u8BF7\u5148\u6253\u5F00 https://my.oschina.net/u/<uid>/blog/ai-write");
|
|
43
55
|
}
|
|
44
56
|
let decodeContent;
|
|
45
57
|
try {
|
|
@@ -47,11 +59,11 @@
|
|
|
47
59
|
} catch {
|
|
48
60
|
throw new Error("content \u4E0D\u662F\u6709\u6548\u7684 Base64 \u7F16\u7801\uFF0C\u8BF7\u68C0\u67E5\u53C2\u6570\u6216\u4F7F\u7528 @base64file: \u5F15\u7528\u6587\u4EF6");
|
|
49
61
|
}
|
|
50
|
-
|
|
62
|
+
const switchBtn = document.querySelector(".editor-switch-btn");
|
|
51
63
|
if (switchBtn) {
|
|
52
64
|
switchBtn.click();
|
|
53
65
|
}
|
|
54
|
-
await
|
|
66
|
+
await sleep(300);
|
|
55
67
|
const titleInput = document.querySelector(".title-input-container .title-input");
|
|
56
68
|
if (!titleInput) {
|
|
57
69
|
throw new Error("\u672A\u627E\u5230\u6807\u9898\u8F93\u5165\u6846\uFF0C\u8BF7\u786E\u8BA4\u7F16\u8F91\u5668\u9875\u9762\u5DF2\u5B8C\u5168\u52A0\u8F7D");
|
|
@@ -59,37 +71,167 @@
|
|
|
59
71
|
titleInput.focus();
|
|
60
72
|
titleInput.value = title;
|
|
61
73
|
titleInput.dispatchEvent(
|
|
62
|
-
new InputEvent("input", {
|
|
63
|
-
bubbles: true,
|
|
64
|
-
cancelable: true,
|
|
65
|
-
data: title
|
|
66
|
-
})
|
|
74
|
+
new InputEvent("input", { bubbles: true, cancelable: true, data: title })
|
|
67
75
|
);
|
|
68
76
|
titleInput.dispatchEvent(new Event("change", { bubbles: true }));
|
|
69
77
|
titleInput.blur();
|
|
70
78
|
if (titleInput.value.trim() !== title.trim()) {
|
|
71
79
|
throw new Error("\u6807\u9898\u586B\u5199\u5931\u8D25\uFF0C\u8BF7\u5237\u65B0\u9875\u9762\u540E\u91CD\u8BD5");
|
|
72
80
|
}
|
|
73
|
-
await
|
|
74
|
-
|
|
75
|
-
if (editor) {
|
|
76
|
-
editor.value = decodeContent;
|
|
77
|
-
editor.dispatchEvent(new Event("change", { bubbles: true }));
|
|
78
|
-
editor.blur();
|
|
79
|
-
} else {
|
|
81
|
+
await sleep(300);
|
|
82
|
+
const editor = document.querySelector(".v-md-textarea-editor textarea");
|
|
83
|
+
if (!editor) {
|
|
80
84
|
throw new Error("\u672A\u627E\u5230\u6B63\u6587\u7F16\u8F91\u5668");
|
|
81
85
|
}
|
|
82
|
-
|
|
86
|
+
const nativeSetter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, "value")?.set;
|
|
87
|
+
editor.focus();
|
|
88
|
+
if (nativeSetter) {
|
|
89
|
+
nativeSetter.call(editor, decodeContent);
|
|
90
|
+
} else {
|
|
91
|
+
editor.value = decodeContent;
|
|
92
|
+
}
|
|
93
|
+
editor.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
94
|
+
editor.dispatchEvent(new Event("change", { bubbles: true }));
|
|
95
|
+
editor.blur();
|
|
96
|
+
return toToolResult({
|
|
97
|
+
success: true,
|
|
98
|
+
message: "\u6587\u7AE0\u6807\u9898\u548C\u6B63\u6587\u5DF2\u6210\u529F\u586B\u5199\u5230\u5F00\u6E90\u4E2D\u56FD\u7F16\u8F91\u5668\uFF0C\u8349\u7A3F\u5C06\u81EA\u52A8\u4FDD\u5B58",
|
|
99
|
+
title: title.trim(),
|
|
100
|
+
contentLength: decodeContent.length
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
mcp.registerTool({
|
|
105
|
+
name: "get_article_info",
|
|
106
|
+
title: "\u83B7\u53D6\u5F53\u524D\u5F00\u6E90\u4E2D\u56FD\u6587\u7AE0\u4FE1\u606F",
|
|
107
|
+
description: "\u5728\u5F00\u6E90\u4E2D\u56FD\u7F16\u8F91\u5668\u9875\u9762\u4E2D\u83B7\u53D6\u5F53\u524D\u6587\u7AE0\u7684\u6807\u9898\u548C\u6B63\u6587\uFF0C\u4EE5\u4FBF AI \u5206\u6790\u4E3B\u9898\u3001\u9009\u62E9\u5408\u9002\u7684\u5206\u7C7B\u4E0E\u6807\u7B7E\uFF0C\u6216\u751F\u6210\u6458\u8981\u3002",
|
|
108
|
+
inputSchema: { type: "object", properties: {} },
|
|
109
|
+
execute: async () => {
|
|
110
|
+
if (!isOschinaWritePage()) {
|
|
111
|
+
throw new Error("\u5F53\u524D\u9875\u9762\u4E0D\u662F\u53D1\u5E03\u9875\u9762\uFF0C\u8BF7\u5148\u6253\u5F00 https://my.oschina.net/u/<uid>/blog/ai-write");
|
|
112
|
+
}
|
|
113
|
+
const { title, content } = readArticleFromEditor();
|
|
114
|
+
return toToolResult({
|
|
115
|
+
success: true,
|
|
116
|
+
title,
|
|
117
|
+
contentLength: content.length,
|
|
118
|
+
content
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
mcp.registerTool({
|
|
123
|
+
name: "publish_current_draft",
|
|
124
|
+
title: "\u4E00\u952E\u53D1\u5E03\u5F53\u524D\u5F00\u6E90\u4E2D\u56FD\u8349\u7A3F",
|
|
125
|
+
description: "\u5728\u5F00\u6E90\u4E2D\u56FD\u7F16\u8F91\u5668\u4E2D\u81EA\u52A8\u586B\u5199\u6807\u7B7E\u3001\u5206\u7C7B\u5E76\u70B9\u51FB\u53D1\u5E03\u3002\u8C03\u7528\u524D AI \u5FC5\u987B\u5148\u4F7F\u7528 get_article_info \u83B7\u53D6\u6B63\u6587\uFF0C\u667A\u80FD\u63A8\u65AD category \u4E0E tags\uFF0C\u5E76\u751F\u6210 50~200 \u5B57\u6458\u8981\uFF0C\u5207\u52FF\u76F2\u76EE\u4F7F\u7528\u9ED8\u8BA4\u503C\u3002",
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: "object",
|
|
128
|
+
properties: {
|
|
129
|
+
category: {
|
|
130
|
+
type: "string",
|
|
131
|
+
description: "\u6587\u7AE0\u5206\u7C7B/\u4E13\u533A\uFF0C\u5982\u300C\u5F00\u6E90\u8D44\u8BAF\u300D\u300C\u8F6F\u4EF6\u67B6\u6784\u300D\u300C\u524D\u7AEF\u300D\u7B49\uFF0C\u9ED8\u8BA4\u300C\u5F00\u6E90\u8D44\u8BAF\u300D"
|
|
132
|
+
},
|
|
133
|
+
tags: {
|
|
134
|
+
type: "array",
|
|
135
|
+
items: { type: "string" },
|
|
136
|
+
description: "\u6587\u7AE0\u6807\u7B7E\u6570\u7EC4\uFF0C\u5FC5\u586B 1~5 \u4E2A\u3002AI \u5E94\u5148\u8BFB\u53D6\u6B63\u6587\u63D0\u70BC\u6838\u5FC3\u6280\u672F\u6808\u6807\u7B7E"
|
|
137
|
+
},
|
|
138
|
+
summary: {
|
|
139
|
+
type: "string",
|
|
140
|
+
description: "\u6587\u7AE0\u6458\u8981\uFF0C\u5FC5\u586B\uFF0C\u5EFA\u8BAE 50~200 \u5B57\u3002\u8C03\u7528\u524D AI \u987B\u57FA\u4E8E get_article_info \u81EA\u4E3B\u603B\u7ED3\u3002"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
required: ["tags", "summary"]
|
|
144
|
+
},
|
|
145
|
+
execute: async ({
|
|
146
|
+
category = "\u5F00\u6E90\u8D44\u8BAF",
|
|
147
|
+
tags,
|
|
148
|
+
summary
|
|
149
|
+
}) => {
|
|
150
|
+
if (!isOschinaWritePage()) {
|
|
151
|
+
throw new Error("\u5F53\u524D\u9875\u9762\u4E0D\u662F\u53D1\u5E03\u9875\u9762\uFF0C\u8BF7\u5148 tabs switch \u5230\u7F16\u8F91\u5668\u6807\u7B7E\u9875\u540E\u518D\u53D1\u5E03");
|
|
152
|
+
}
|
|
153
|
+
if (!tags?.length) {
|
|
154
|
+
throw new Error("\u53C2\u6570 tags \u4E0D\u80FD\u4E3A\u7A7A\uFF0C\u8BF7\u81F3\u5C11\u63D0\u4F9B\u4E00\u4E2A\u6807\u7B7E");
|
|
155
|
+
}
|
|
156
|
+
const finalSummary = summary?.trim() || "";
|
|
157
|
+
if (!finalSummary) {
|
|
158
|
+
throw new Error("\u53C2\u6570 summary \u4E0D\u80FD\u4E3A\u7A7A");
|
|
159
|
+
}
|
|
160
|
+
if (finalSummary.length < 20) {
|
|
161
|
+
throw new Error(`\u6458\u8981\u8FC7\u77ED\uFF08${finalSummary.length} \u5B57\uFF09\uFF0C\u5EFA\u8BAE\u81F3\u5C11 20 \u5B57`);
|
|
162
|
+
}
|
|
163
|
+
const summaryInput = document.querySelector('textarea[placeholder*="\u6458\u8981"]') || document.querySelector('input[placeholder*="\u6458\u8981"]') || document.querySelector('[class*="summary"] textarea');
|
|
164
|
+
if (summaryInput) {
|
|
165
|
+
const nativeSetter = Object.getOwnPropertyDescriptor(
|
|
166
|
+
summaryInput instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype,
|
|
167
|
+
"value"
|
|
168
|
+
)?.set;
|
|
169
|
+
summaryInput.focus();
|
|
170
|
+
if (nativeSetter) {
|
|
171
|
+
nativeSetter.call(summaryInput, finalSummary);
|
|
172
|
+
} else {
|
|
173
|
+
summaryInput.value = finalSummary;
|
|
174
|
+
}
|
|
175
|
+
summaryInput.dispatchEvent(new InputEvent("input", { bubbles: true }));
|
|
176
|
+
summaryInput.dispatchEvent(new Event("change", { bubbles: true }));
|
|
177
|
+
await sleep(300);
|
|
178
|
+
}
|
|
179
|
+
const catEl = Array.from(
|
|
180
|
+
document.querySelectorAll("select option, li, label, span, div, button")
|
|
181
|
+
).find((el) => el.textContent?.trim() === category && el.offsetParent !== null);
|
|
182
|
+
if (catEl) {
|
|
183
|
+
catEl.click();
|
|
184
|
+
await sleep(300);
|
|
185
|
+
}
|
|
186
|
+
const tagInput = document.querySelector('input[placeholder*="\u6807\u7B7E"]') || document.querySelector('[class*="tag"] input');
|
|
187
|
+
const addedTags = [];
|
|
188
|
+
if (tagInput) {
|
|
189
|
+
for (const tag of tags.slice(0, 5)) {
|
|
190
|
+
tagInput.focus();
|
|
191
|
+
tagInput.click();
|
|
192
|
+
const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
|
|
193
|
+
if (nativeSetter) {
|
|
194
|
+
nativeSetter.call(tagInput, tag);
|
|
195
|
+
} else {
|
|
196
|
+
tagInput.value = tag;
|
|
197
|
+
}
|
|
198
|
+
tagInput.dispatchEvent(new InputEvent("input", { bubbles: true, data: tag }));
|
|
199
|
+
await sleep(600);
|
|
200
|
+
const suggestion = Array.from(
|
|
201
|
+
document.querySelectorAll('[class*="suggestion"], [class*="dropdown"] li, .el-select-dropdown__item')
|
|
202
|
+
).find((el) => el.textContent?.trim().includes(tag));
|
|
203
|
+
if (suggestion) {
|
|
204
|
+
suggestion.click();
|
|
205
|
+
} else {
|
|
206
|
+
tagInput.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
|
207
|
+
}
|
|
208
|
+
addedTags.push(tag);
|
|
209
|
+
await sleep(400);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const publishBtn = Array.from(document.querySelectorAll("button, a")).find((el) => {
|
|
213
|
+
const text = el.textContent?.trim() || "";
|
|
214
|
+
return (text === "\u53D1\u5E03" || text === "\u53D1\u5E03\u535A\u5BA2" || text === "\u7ACB\u5373\u53D1\u5E03" || text.includes("\u53D1\u5E03\u6587\u7AE0")) && el.offsetParent !== null;
|
|
215
|
+
});
|
|
216
|
+
if (!publishBtn) {
|
|
217
|
+
throw new Error("\u672A\u627E\u5230\u300C\u53D1\u5E03\u300D\u6309\u94AE\uFF0C\u8BF7\u786E\u8BA4\u7F16\u8F91\u5668\u9875\u9762\u5DF2\u5B8C\u5168\u52A0\u8F7D");
|
|
218
|
+
}
|
|
219
|
+
publishBtn.click();
|
|
220
|
+
await sleep(2500);
|
|
221
|
+
return toToolResult({
|
|
83
222
|
success: true,
|
|
84
|
-
message:
|
|
85
|
-
|
|
86
|
-
|
|
223
|
+
message: `\u5F00\u6E90\u4E2D\u56FD\u53D1\u5E03\u6D41\u7A0B\u5DF2\u89E6\u53D1\uFF0C\u5206\u7C7B: ${category}\uFF0C\u6807\u7B7E: ${addedTags.join(", ") || tags.join(", ")}`,
|
|
224
|
+
category,
|
|
225
|
+
tags: addedTags.length ? addedTags : tags,
|
|
226
|
+
summary: finalSummary,
|
|
227
|
+
url: location.href
|
|
228
|
+
});
|
|
87
229
|
}
|
|
88
230
|
});
|
|
89
|
-
window.
|
|
90
|
-
console.log("[webmcp-tools]
|
|
231
|
+
window.__webmcptools_myoschinanet = true;
|
|
232
|
+
console.log("[webmcp-tools] my.oschina.net \u5DE5\u5177\u6CE8\u518C\u6210\u529F");
|
|
91
233
|
} catch (e) {
|
|
92
|
-
console.error("[webmcp-tools]
|
|
234
|
+
console.error("[webmcp-tools] my.oschina.net \u5DE5\u5177\u6CE8\u518C\u5931\u8D25:", e.message);
|
|
93
235
|
}
|
|
94
236
|
}
|
|
95
237
|
})();
|