-
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
6 changed files
with
62 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,12 @@ | ||
export function getAllFrames() { | ||
const result = []; | ||
|
||
// 同 dom-stat 迭代 | ||
const temp: Element[] = [document.documentElement]; | ||
while (!!temp.length) { | ||
const element = temp.pop()!; | ||
const result: string[] = []; | ||
|
||
window.__GEM_DEVTOOLS__PRELOAD__.traverseDom((element) => { | ||
if (element instanceof HTMLIFrameElement) { | ||
const frameURL = element.src; | ||
if (frameURL) result.push(frameURL); | ||
} | ||
|
||
if (element.shadowRoot?.firstElementChild) temp.push(element.shadowRoot.firstElementChild); | ||
if (element.firstElementChild) temp.push(element.firstElementChild); | ||
if (element.nextElementSibling) temp.push(element.nextElementSibling); | ||
} | ||
}); | ||
|
||
return result; | ||
} |
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,50 @@ | ||
import type { Path } from '../store'; | ||
|
||
type DevToolsHookPreload = { | ||
readProp: (path: Path) => any; | ||
traverseDom: (callback: (element: Element) => void) => void; | ||
}; | ||
declare global { | ||
interface Window { | ||
__GEM_DEVTOOLS__PRELOAD__: DevToolsHookPreload; | ||
} | ||
} | ||
|
||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/eval#helpers | ||
declare let $0: any; | ||
|
||
export function preload() { | ||
window.__GEM_DEVTOOLS__PRELOAD__ = { | ||
// [["shadowRoot", ""], "querySelector", "[ref=child-ref]"] | ||
// 只有 constructor 函数会当成对象读取 | ||
readProp(path) { | ||
return path.reduce((p, c, index) => { | ||
if (typeof p === 'function' && path[index - 1] !== 'constructor') { | ||
if (Array.isArray(c)) { | ||
return p(...c); | ||
} else { | ||
return p(c); | ||
} | ||
} else { | ||
if (Array.isArray(c)) { | ||
return c.reduce((pp, cc) => pp || (cc === '' ? p : p[cc]), undefined); | ||
} else { | ||
const value = p[c]; | ||
return typeof value === 'function' && c !== 'constructor' ? value.bind(p) : value; | ||
} | ||
} | ||
}, $0); | ||
}, | ||
traverseDom(callback) { | ||
// 同 dom-stat 迭代 | ||
const temp: Element[] = [document.documentElement]; | ||
while (!!temp.length) { | ||
const element = temp.pop()!; | ||
callback(element); | ||
if (element.shadowRoot?.firstElementChild) temp.push(element.shadowRoot.firstElementChild); | ||
if (element.firstElementChild) temp.push(element.firstElementChild); | ||
if (element.nextElementSibling) temp.push(element.nextElementSibling); | ||
} | ||
}, | ||
}; | ||
} |
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,28 +1,9 @@ | ||
import { Path } from '../store'; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/inspectedWindow/eval#helpers | ||
declare let $0: any; | ||
|
||
export const setValue = (path: Path, value: string | number | boolean | null) => { | ||
const key = String(path.pop()); | ||
|
||
// 同 inspect-value | ||
const obj = path.reduce((p, c, index) => { | ||
if (typeof p === 'function' && path[index - 1] !== 'constructor') { | ||
if (Array.isArray(c)) { | ||
return p(...c); | ||
} else { | ||
return p(c); | ||
} | ||
} else { | ||
if (Array.isArray(c)) { | ||
return c.reduce((pp, cc) => pp || (cc === '' ? p : p[cc]), undefined); | ||
} else { | ||
const value = p[c]; | ||
return typeof value === 'function' && c !== 'constructor' ? value.bind(p) : value; | ||
} | ||
} | ||
}, $0); | ||
const obj = window.__GEM_DEVTOOLS__PRELOAD__.readProp(path); | ||
|
||
obj[key] = value; | ||
}; |