MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / GetInjected

Function GetInjected

src/background/utils/preinject.js:172–205  ·  view source on GitHub ↗

@return {Promise }

({ url, [FORCE_CONTENT]: forceContent, done }, src)

Source from the content-addressed store, hash-verified

170addPublicCommands({
171 /** @return {Promise<VMInjection>} */
172 async GetInjected({ url, [FORCE_CONTENT]: forceContent, done }, src) {
173 const { tab, [kFrameId]: frameId, [kTop]: isTop } = src;
174 const frameDoc = getFrameDocId(isTop, src[kDocumentId], frameId);
175 const tabId = tab.id;
176 if (!url) url = src.url || tab.url;
177 clearFrameData(tabId, frameDoc);
178 let skip = skippedTabs[tabId];
179 if (skip > 0) { // first time loading the tab after skipScripts was invoked
180 if (isTop) skippedTabs[tabId] = -1; // keeping a phantom for future iframes in this page
181 if (popupTabs[tabId]) sendPopupShown(tabId, frameDoc);
182 return { [INJECT_INTO]: SKIP_SCRIPTS };
183 }
184 if (skip) delete skippedTabs[tabId]; // deleting the phantom as we're in a new page
185 const bagKey = getKey(url, isTop);
186 const bagP = cache.get(bagKey) || prepare(bagKey, url, isTop);
187 const bag = bagP[INJECT] ? bagP : await bagP[PROMISE];
188 /** @type {VMInjection} */
189 const inject = bag[INJECT];
190 const scripts = inject[SCRIPTS];
191 if (scripts) {
192 triageRealms(scripts, bag[FORCE_CONTENT] || forceContent, tabId, frameId, bag);
193 addValueOpener(scripts, tabId, frameDoc);
194 addMenuConfig(inject);
195 if (isTop < 2/* skip prerendered pages*/ && scripts.length) {
196 updateVisitedTime(scripts);
197 }
198 }
199 if (popupTabs[tabId]) {
200 sendPopupShown(tabId, frameDoc);
201 }
202 return isApplied
203 ? !done && inject
204 : { [INJECT_INTO]: 'off', ...inject };
205 },
206 async InjectionFeedback({
207 [FORCE_CONTENT]: forceContent,
208 [CONTENT]: items,

Callers

nothing calls this directly

Calls 10

getFrameDocIdFunction · 0.90
addValueOpenerFunction · 0.90
addMenuConfigFunction · 0.90
updateVisitedTimeFunction · 0.90
clearFrameDataFunction · 0.85
sendPopupShownFunction · 0.85
getKeyFunction · 0.85
triageRealmsFunction · 0.85
prepareFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected