-
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.
[gem-devtools] Support gem panel edit value
- Loading branch information
Showing
12 changed files
with
150 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
export const isFirefox = navigator.userAgent.includes('Firefox'); | ||
import { devtools } from 'webextension-polyfill'; | ||
|
||
/** | ||
* execution script in page | ||
* @param func A function that can be converted into a string and does not rely on external variables | ||
* @param args Array serializable using JSON | ||
*/ | ||
export async function execution<Func extends (...rest: any) => any>( | ||
func: Func, | ||
args: Parameters<Func>, | ||
): Promise<ReturnType<Func>> { | ||
const source = func.toString(); | ||
const [data, errorInfo] = await devtools.inspectedWindow.eval(`(${source}).apply(null, ${JSON.stringify(args)})`); | ||
if (errorInfo) { | ||
throw { | ||
source, | ||
...errorInfo, | ||
}; | ||
} | ||
return data; | ||
} |
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
File renamed without changes.
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,28 @@ | ||
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); | ||
|
||
obj[key] = value; | ||
}; |
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