Skip to content

Commit

Permalink
🐛 修复chrome v127下GM_addElement相关问题 #299
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jul 12, 2024
1 parent e0130ec commit cd749af
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptcat",
"version": "0.16.4",
"version": "0.16.5",
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
"author": "CodFrm",
"license": "GPLv3",
Expand Down
25 changes: 9 additions & 16 deletions src/app/message/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ export default class MessageContent
this.nativeSend(data);
});
this.relatedTarget = new Map<number, Element>();
document.addEventListener(
window.addEventListener(
(isContent ? "ct" : "fd") + eventId,
(event: unknown) => {
if (event instanceof MutationEvent) {
this.relatedTarget.set(
parseInt(event.prevValue, 10),
<Element>event.relatedNode
);
if (event instanceof MouseEvent) {
this.relatedTarget.set(event.clientX, <Element>event.relatedTarget);
return;
}
const message = (<
Expand Down Expand Up @@ -116,15 +113,11 @@ export default class MessageContent
delete detail.data.relatedTarget;
detail.data.relatedTarget = Math.ceil(Math.random() * 1000000);
// 可以使用此种方式交互element
const ev = document.createEvent("MutationEvent");
ev.initMutationEvent(
(this.isContent ? "fd" : "ct") + this.eventId,
false,
false,
target,
detail.data.relatedTarget.toString()
);
document.dispatchEvent(ev);
const ev = new MouseEvent((this.isContent ? "fd" : "ct") + this.eventId, {
clientX: detail.data.relatedTarget,
relatedTarget: target,
});
window.dispatchEvent(ev);
}

if (typeof cloneInto !== "undefined") {
Expand All @@ -142,7 +135,7 @@ export default class MessageContent
const ev = new CustomEvent((this.isContent ? "fd" : "ct") + this.eventId, {
detail,
});
document.dispatchEvent(ev);
window.dispatchEvent(ev);
}

public send(action: string, data: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "__MSG_scriptcat__",
"version": "0.16.4",
"version": "0.16.5",
"author": "CodFrm",
"description": "__MSG_scriptcat_description__",
"options_ui": {
Expand Down

0 comments on commit cd749af

Please sign in to comment.