Skip to content

Commit

Permalink
fix: auto grants
Browse files Browse the repository at this point in the history
  • Loading branch information
Thinker-ljn committed May 15, 2022
1 parent 9c4eebc commit f5b6a8f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/lib/tampermonkey/grant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ export const grants = [
'GM_info',
]

const tampermonkeyGrantMapper = grants.reduce((mapper, grant) => {
mapper[grant] = true
return mapper
}, {} as Record<string, true>)
const tampermonkeyGrantSet = new Set(grants)

const usedGrants: Set<string> = new Set()
export const parserGrant: Plugin = {
Expand All @@ -42,13 +39,13 @@ export const parserGrant: Plugin = {
walkFull(moduleInfo.ast, (node: any) => {
if (node.type === 'CallExpression') {
const calleeName = node.callee.name
if (calleeName && tampermonkeyGrantMapper[calleeName]) {
if (calleeName && tampermonkeyGrantSet.has(calleeName)) {
usedGrants.add(calleeName)
}
}
if (
node.type === 'Identifier' &&
tampermonkeyGrantMapper[node.name]
tampermonkeyGrantSet.has(node.name)
) {
usedGrants.add(node.name)
}
Expand Down

0 comments on commit f5b6a8f

Please sign in to comment.