-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,694 additions
and
805 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const pkg = require('../extension/manifest.json'); | ||
|
||
require('fs').writeFileSync('./extension/manifest.json', JSON.stringify({ ...pkg, manifest_version: 2 }, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const isFirefox = navigator.userAgent.includes('Firefox'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
import type { DevToolsHook } from '@mantou/gem'; | ||
type DevToolsHookStore = { | ||
customElementMap: Map<string, CustomElementConstructor>; | ||
currentElementsMap: Map<string, Element>; | ||
}; | ||
declare global { | ||
interface Window { | ||
__GEM_DEVTOOLS__STORE__?: DevToolsHookStore; | ||
} | ||
} | ||
|
||
// 序列化后在 page 中执行 | ||
function initDevToolsHook() { | ||
window.__GEM_DEVTOOLS__HOOK__ = {} as DevToolsHook; | ||
// at document_start | ||
window.__GEM_DEVTOOLS__HOOK__ = {}; | ||
window.__GEM_DEVTOOLS__STORE__ = { | ||
customElementMap: new Map(), | ||
currentElementsMap: new Map(), | ||
}; | ||
|
||
const nativeDefineElement = window.customElements.define.bind(window.customElements); | ||
window.customElements.define = (...rest: Parameters<typeof customElements.define>) => { | ||
window.__GEM_DEVTOOLS__STORE__!.customElementMap.set(rest[0], rest[1]); | ||
nativeDefineElement(...rest); | ||
}; | ||
} | ||
|
||
// only MV2 | ||
if (navigator.userAgent.includes('Firefox')) { | ||
const script = document.createElement('script'); | ||
script.textContent = `(${initDevToolsHook.toString()})()`; | ||
document.documentElement.append(script); | ||
script.remove(); | ||
} else { | ||
initDevToolsHook(); | ||
} | ||
|
||
const script = document.createElement('script'); | ||
script.textContent = `(${initDevToolsHook.toString()})()`; | ||
document.documentElement.append(script); | ||
script.remove(); | ||
export {}; |
Oops, something went wrong.