Skip to content

Commit

Permalink
MV3: now order of extend_click_vc is reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Jul 20, 2024
1 parent 64e0c4f commit b043668
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion content/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ set_contentCommands_([
/* kFgCmd.visualMode: */ visualActivate,
/* kFgCmd.vomnibar: */ omniActivate,
/* kFgCmd.insertMode: */ (opt: CmdOptions[kFgCmd.insertMode]): void => {
if (opt.u) {
if (opt.u) { /*#__ENABLE_SCOPED__*/
const done = derefInDoc_(lastHovered_) ? 0 : 2
void catchAsyncErrorSilently(wrap_enable_bubbles(opt, unhover_async<1>, [])).then((): void => {
hudTip(kTip.didUnHoverLast)
Expand Down
7 changes: 5 additions & 2 deletions content/extend_click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,12 @@ export const ec_main_not_ff = (Build.BTypes !== BrowserType.Firefox as number ?
}
if (!kInjectManually) {
if (grabBackFocus) {
dispatchEvent(new Event(kVOnClick1)) // it seems MS Edge may get a wrong order between dynamic and static scripts
if (Build.BTypes & ~BrowserType.Chrome || Build.MinCVer < BrowserVer.MinCSAcceptWorldInManifest) {
// MS Edge may get a wrong order between dynamic and static scripts, but not reproduced on Chrome / Edge 126
dispatchEvent(new Event(kVOnClick1))
}
setupEventListener(0, kVOnClick1, onClick);
box || OnDocLoaded_(() => { // check CSP script-src or JS-disabled-in-CS
OnDocLoaded_(() => { // check CSP script-src or JS-disabled-in-CS
box || execute(kContentCmd.Destroy)
})
}
Expand Down
19 changes: 10 additions & 9 deletions content/extend_click_vc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
Build.MV3 && Build.BTypes & BrowserType.Chrome && (function VC(this: void): void {
Build.MV3 && Build.BTypes & BrowserType.Chrome && (function VC(this: void, delayed?: 1): void {
const enum InnerConsts {
MaxElementsInOneTickDebug = 1024,
MaxElementsInOneTickRelease = 512,
Expand Down Expand Up @@ -290,18 +290,20 @@ const onDocOpen = (isWrite?: 0 | 2, oriHref?: string): void => {
}
const noop = (): 1 => { return 1 }
const docEl = doc0.documentElement;
(function startHook(delayed?: 1): void {
if (!docEl || delayed && !(!docEl.lastChild && docEl.parentNode === doc0)) {
const defineProp = Object.defineProperty, dbgLoc = Build.NDEBUG ? null as never : location
const dataset = (root as Element as TypeToAssert<Element, HTMLElement, "dataset", "tagName">).dataset
if (!docEl || (Build.BTypes & ~BrowserType.Chrome || Build.MinCVer < BrowserVer.MinCSAcceptWorldInManifest)
&& delayed && !(!docEl.lastChild && docEl.parentNode === doc0)) {
return
}
const dataset = (root as Element as TypeToAssert<Element, HTMLElement, "dataset", "tagName">).dataset
}
if (dataset && (
dataset.vimium = kRC,

// only the below can affect outsides

_dispatch(new DECls(kOC, {relatedTarget: root})),
!dataset.vimium
)) {
const defineProp = Object.defineProperty, dbgLoc = Build.NDEBUG ? null as never : location
root[kAEL](InnerConsts.kCmd, executeCmd, !0)
timer = toRegister.length > 0 ? setTimeout_(next, InnerConsts.DelayForNext) : 0
ETP[kAEL] = myAEL
Expand Down Expand Up @@ -337,15 +339,14 @@ if (dataset && (
}
})
}
} else if (!delayed) {
} else if ((Build.BTypes & ~BrowserType.Chrome || Build.MinCVer < BrowserVer.MinCSAcceptWorldInManifest) && !delayed) {
const listenOpt: EventListenerOptions = { capture: true, once: true }
const postStart = (event: EventToPrevent): void => {
queueMicroTask_((): void => startHook(1))
queueMicroTask_((): void => VC(1))
call(StopProp, event)
}
_listen(kOC, postStart, listenOpt)
_listen("readystatechange", removeEventListener.bind(window, kOC, postStart, listenOpt), listenOpt)
}
})()

})()
16 changes: 10 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
"service_worker": "background/worker.js",
"type": "module"
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "119.0"
}
},
"commands": {
"createTab": { "description": "__MSG_createTab_s__" },
"goBack": { "description": "__MSG_goBack_s__" },
Expand Down Expand Up @@ -62,6 +56,16 @@
"match_origin_as_fallback": true,
"matches": [ "<all_urls>" ],
"run_at": "document_start"
}, {
"all_frames": true,
"js": [
"content/extend_click_vc.js"
],
"match_about_blank": true,
"match_origin_as_fallback": true,
"matches": [ "<all_urls>" ],
"run_at": "document_start",
"world": "MAIN"
} ],
"content_security_policy": {
"extension_pages": "script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/uglifyjs-mangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MIN_LONG_STRING = 20;
const MIN_STRING_LENGTH_TO_COMPUTE_GAIN = 2;
const MIN_EXPECTED_STRING_GAIN = 11;
const ALLOWED_SHORT_NAMES = new Set([
":SP:0", ":BU:0", ":V:0", ":I:0", ":V:1", ":I:1"
":SP:0", ":BU:0", ":V:0", ":I:0", ":V:1", ":I:1", ":VC:0"
])

// @ts-ignore
Expand Down

0 comments on commit b043668

Please sign in to comment.