@@ -50,28 +50,29 @@ export type Request = MessageRequest & {
5050
5151export type Api = ( request : Request , connect ?: Channel ) => Promise < any > ;
5252
53- export default class GMApi {
54- static executionMap = new Map <
55- string ,
56- { scriptIds : Set < number > ; tabId : number }
57- > ( ) ;
58-
59- static registerScriptExecution ( scriptIds : number [ ] , tabId : number ) {
60- const token = uuidv4 ( ) ;
61- this . executionMap . set ( token , {
62- scriptIds : new Set ( scriptIds ) ,
63- tabId,
64- } ) ;
65- return token ;
66- }
53+ const executionMap = new Map <
54+ string ,
55+ { scriptIds : Set < number > ; tabId : number }
56+ > ( ) ;
57+
58+ export const registerScriptExecution = ( scriptIds : number [ ] , tabId : number ) : string => {
59+ const token = uuidv4 ( ) ;
60+ executionMap . set ( token , {
61+ scriptIds : new Set ( scriptIds ) ,
62+ tabId,
63+ } ) ;
64+ return token ;
65+ } ;
6766
68- static removeTabExecutions ( tabId : number ) {
69- this . executionMap . forEach ( ( execution , token ) => {
70- if ( execution . tabId === tabId ) {
71- this . executionMap . delete ( token ) ;
72- }
73- } ) ;
74- }
67+ export const removeTabExecutions = ( tabId : number ) => {
68+ executionMap . forEach ( ( execution , token ) => {
69+ if ( execution . tabId === tabId ) {
70+ executionMap . delete ( token ) ;
71+ }
72+ } ) ;
73+ } ;
74+
75+ export default class GMApi {
7576
7677 message : MessageHander ;
7778
@@ -191,7 +192,7 @@ export default class GMApi {
191192 if ( ! request . executionToken ) {
192193 throw new Error ( "script execution is not trusted" ) ;
193194 }
194- const execution = GMApi . executionMap . get ( request . executionToken ) ;
195+ const execution = executionMap . get ( request . executionToken ) ;
195196 if ( ! execution || ! execution . scriptIds . has ( request . scriptId ) ) {
196197 throw new Error ( "script execution is not trusted" ) ;
197198 }
0 commit comments