Skip to content

Commit dd22ef5

Browse files
authored
🐛 scriptcat.d.tpl & type 修正 (#1130)
* 跟随 TM 使用 "tab" 和 "tabs" 作 parameter 命名 * type 修正 * type 修正
1 parent 9c4c7dc commit dd22ef5

4 files changed

Lines changed: 30 additions & 22 deletions

File tree

src/app/service/content/content.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class ContentRuntime {
7676
case "GM_addElement": {
7777
const [parentNodeId, tagName, tmpAttr] = data.params;
7878
let attr = { ...tmpAttr };
79-
let parentNode: EventTarget | undefined;
79+
let parentNode: Node | undefined;
8080
// 判断是不是content脚本发过来的
8181
let msg: CustomEventMessage;
8282
if (this.contentScriptSet.has(data.uuid) || this.scriptExecutor.execMap.has(data.uuid)) {
@@ -85,7 +85,7 @@ export default class ContentRuntime {
8585
msg = this.senderToInject;
8686
}
8787
if (parentNodeId) {
88-
parentNode = msg.getAndDelRelatedTarget(parentNodeId);
88+
parentNode = msg.getAndDelRelatedTarget(parentNodeId) as Node | undefined;
8989
}
9090
const el = <Element>document.createElement(tagName);
9191

@@ -104,7 +104,7 @@ export default class ContentRuntime {
104104
if (textContent) {
105105
el.textContent = textContent;
106106
}
107-
(<Element>parentNode || document.head || document.body || document.querySelector("*")).appendChild(el);
107+
(parentNode || document.head || document.body || document.querySelector("*")).appendChild(el);
108108
const nodeId = msg.sendRelatedTarget(el);
109109
return nodeId;
110110
}

src/app/service/content/gm_api/gm_api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ export default class GMApi extends GM_Base {
690690

691691
@GMContext.API({ alias: "GM.addElement" })
692692
GM_addElement(
693-
parentNode: EventTarget | string,
693+
parentNode: Node | string,
694694
tagName: string | Record<string, string | number | boolean>,
695695
attrs: Record<string, string | number | boolean> = {}
696696
) {

src/template/scriptcat.d.tpl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ declare function GM_xmlhttpRequest(details: GMTypes.XHRDetails): GMTypes.AbortHa
171171
declare function GM_download(details: GMTypes.DownloadDetails<string | Blob | File>): GMTypes.AbortHandle<boolean>;
172172
declare function GM_download(url: string, filename: string): GMTypes.AbortHandle<boolean>;
173173

174-
declare function GM_getTab(callback: (obj: object) => void): void;
174+
declare function GM_getTab(callback: (tab: object) => void): void;
175175

176-
declare function GM_saveTab(obj: object): Promise<void>;
176+
declare function GM_saveTab(tab: object): Promise<void>;
177177

178-
declare function GM_getTabs(callback: (objs: { [key: number]: object }) => void): void;
178+
declare function GM_getTabs(callback: (tabs: { [key: number]: object }) => void): void;
179179

180180
declare function GM_notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): void;
181181
declare function GM_notification(
@@ -191,8 +191,12 @@ declare function GM_updateNotification(id: string, details: GMTypes.Notification
191191

192192
declare function GM_setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): void;
193193

194-
declare function GM_addElement(tag: string, attributes: any): HTMLElement;
195-
declare function GM_addElement(parentNode: Element, tag: string, attrs: any): HTMLElement;
194+
declare function GM_addElement(tag: string, attributes: Record<string, string | number | boolean>): HTMLElement;
195+
declare function GM_addElement(
196+
parentNode: Node,
197+
tag: string,
198+
attrs: Record<string, string | number | boolean>
199+
): HTMLElement;
196200

197201
declare function GM_addStyle(css: string): HTMLStyleElement;
198202

@@ -266,7 +270,7 @@ declare const GM: {
266270
unregisterMenuCommand(id: number | string): Promise<void>;
267271

268272
/** 样式注入 */
269-
addStyle(css: string): Promise<void>;
273+
addStyle(css: string): Promise<HTMLStyleElement>;
270274

271275
/** 通知 */
272276
notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): Promise<void>;
@@ -278,8 +282,8 @@ declare const GM: {
278282
setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): Promise<void>;
279283

280284
/** 添加元素 */
281-
addElement(tag: string, attributes: any): Promise<HTMLElement>;
282-
addElement(parentNode: Element, tag: string, attrs: any): Promise<HTMLElement>;
285+
addElement(tag: string, attributes: Record<string, string | number | boolean>): Promise<HTMLElement>;
286+
addElement(parentNode: Node, tag: string, attrs: Record<string, string | number | boolean>): Promise<HTMLElement>;
283287

284288
/** XMLHttpRequest */
285289
xmlHttpRequest(details: GMTypes.XHRDetails): Promise<GMTypes.XHRResponse>;
@@ -290,7 +294,7 @@ declare const GM: {
290294

291295
/** Tab 存储 */
292296
getTab(): Promise<object>;
293-
saveTab(obj: object): Promise<void>;
297+
saveTab(tab: object): Promise<void>;
294298
getTabs(): Promise<{ [key: number]: object }>;
295299

296300
/** 打开新标签页 */

src/types/scriptcat.d.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ declare function GM_xmlhttpRequest(details: GMTypes.XHRDetails): GMTypes.AbortHa
171171
declare function GM_download(details: GMTypes.DownloadDetails<string | Blob | File>): GMTypes.AbortHandle<boolean>;
172172
declare function GM_download(url: string, filename: string): GMTypes.AbortHandle<boolean>;
173173

174-
declare function GM_getTab(callback: (obj: object) => void): void;
174+
declare function GM_getTab(callback: (tab: object) => void): void;
175175

176-
declare function GM_saveTab(obj: object): Promise<void>;
176+
declare function GM_saveTab(tab: object): Promise<void>;
177177

178-
declare function GM_getTabs(callback: (objs: { [key: number]: object }) => void): void;
178+
declare function GM_getTabs(callback: (tabs: { [key: number]: object }) => void): void;
179179

180180
declare function GM_notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): void;
181181
declare function GM_notification(
@@ -191,8 +191,12 @@ declare function GM_updateNotification(id: string, details: GMTypes.Notification
191191

192192
declare function GM_setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): void;
193193

194-
declare function GM_addElement(tag: string, attributes: any): HTMLElement;
195-
declare function GM_addElement(parentNode: Element, tag: string, attrs: any): HTMLElement;
194+
declare function GM_addElement(tag: string, attributes: Record<string, string | number | boolean>): HTMLElement;
195+
declare function GM_addElement(
196+
parentNode: Node,
197+
tag: string,
198+
attrs: Record<string, string | number | boolean>
199+
): HTMLElement;
196200

197201
declare function GM_addStyle(css: string): HTMLStyleElement;
198202

@@ -266,7 +270,7 @@ declare const GM: {
266270
unregisterMenuCommand(id: number | string): Promise<void>;
267271

268272
/** 样式注入 */
269-
addStyle(css: string): Promise<void>;
273+
addStyle(css: string): Promise<HTMLStyleElement>;
270274

271275
/** 通知 */
272276
notification(details: GMTypes.NotificationDetails, ondone?: GMTypes.NotificationOnDone): Promise<void>;
@@ -278,8 +282,8 @@ declare const GM: {
278282
setClipboard(data: string, info?: string | { type?: string; mimetype?: string }): Promise<void>;
279283

280284
/** 添加元素 */
281-
addElement(tag: string, attributes: any): Promise<HTMLElement>;
282-
addElement(parentNode: Element, tag: string, attrs: any): Promise<HTMLElement>;
285+
addElement(tag: string, attributes: Record<string, string | number | boolean>): Promise<HTMLElement>;
286+
addElement(parentNode: Node, tag: string, attrs: Record<string, string | number | boolean>): Promise<HTMLElement>;
283287

284288
/** XMLHttpRequest */
285289
xmlHttpRequest(details: GMTypes.XHRDetails): Promise<GMTypes.XHRResponse>;
@@ -290,7 +294,7 @@ declare const GM: {
290294

291295
/** Tab 存储 */
292296
getTab(): Promise<object>;
293-
saveTab(obj: object): Promise<void>;
297+
saveTab(tab: object): Promise<void>;
294298
getTabs(): Promise<{ [key: number]: object }>;
295299

296300
/** 打开新标签页 */

0 commit comments

Comments
 (0)