|
1 | 1 | // import { allScripts } from "../index.js"; |
2 | | -// import { Events } from "../helpers/constants.js"; |
3 | | -// import { MsgType } from "../helpers/constants.js"; |
4 | | -// import { |
5 | | -// checkBlackWhiteList, |
6 | | -// isActiveScript, |
7 | | -// isEmptyFunction, |
8 | | -// isFunction, |
9 | | -// runScriptInTab, |
10 | | -// } from "../helpers/utils.js"; |
11 | | - |
12 | | -// const CACHED = { |
13 | | -// runCount: {}, |
14 | | -// }; |
15 | | - |
16 | | -// chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { |
17 | | -// console.log("> Received message:", message, sender?.tab?.url); |
18 | | - |
19 | | -// switch (message.type) { |
20 | | -// case MsgType.runScript: |
21 | | -// runScript(message.event, sender.tab); |
22 | | -// break; |
23 | | -// } |
24 | | -// }); |
25 | | - |
26 | | -// async function runScript(event, tab) { |
27 | | -// let funcName = event, |
28 | | -// tabId = tab.id, |
29 | | -// url = tab.url; |
30 | | - |
31 | | -// if (!(tabId in CACHED.runCount) || event === Events.onDocumentStart) |
32 | | -// CACHED.runCount[tabId] = 0; |
33 | | - |
34 | | -// for (let script of Object.values(allScripts)) { |
35 | | -// try { |
36 | | -// if (!checkBlackWhiteList(script, url)) continue; |
37 | | - |
38 | | -// let func = script[funcName]; |
39 | | -// if (isFunction(func) && !isEmptyFunction(func)) { |
40 | | -// let isActive = (await isActiveScript(script.id)) ?? true; |
41 | | -// if (isActive) { |
42 | | -// runScriptInTab({ func, tabId }); |
43 | | -// console.log( |
44 | | -// `%c > Run ${script.id} ${funcName} in ${url}`, |
45 | | -// "background: #222; color: #bada55" |
46 | | -// ); |
47 | | -// CACHED.runCount[tabId]++; |
48 | | -// } |
49 | | -// } |
50 | | -// } catch (e) { |
51 | | -// console.log("ERROR at script " + script?.id, e); |
52 | | -// } |
| 2 | +// import { Events, EventMap } from "../helpers/constants.js"; |
| 3 | + |
| 4 | +// chrome.scripting.registerContentScripts( |
| 5 | +// [ |
| 6 | +// { |
| 7 | +// id: "ufs_global_webpage_context", |
| 8 | +// allFrames: true, |
| 9 | +// matches: ["<all_urls>"], |
| 10 | +// js: ["scripts/content-scripts/scripts/ufs_global_webpage_context.js"], |
| 11 | +// runAt: "document_start", |
| 12 | +// world: chrome.scripting.ExecutionWorld.MAIN, |
| 13 | +// }, |
| 14 | +// ], |
| 15 | +// () => { |
| 16 | +// console.log("Register content script DONE."); |
53 | 17 | // } |
| 18 | +// ); |
| 19 | + |
| 20 | +// (() => { |
| 21 | +// let scripts = Object.values(allScripts) |
| 22 | +// .map((s) => |
| 23 | +// Object.values(Events).map((e) => { |
| 24 | +// if (!e in s) return null; |
| 25 | +// let isString = typeof s[e] === "string"; |
| 26 | +// let isArray = Array.isArray(s[e]); |
| 27 | +// if (!(isString || isArray)) return null; |
| 28 | + |
| 29 | +// let js = isString ? [getscriptURL(s[e])] : s[e].map(getscriptURL); |
| 30 | + |
| 31 | +// // add global helper to head of array |
| 32 | +// js.unshift( |
| 33 | +// getscriptURL("content-scripts/scripts/ufs_global_webpage_context.js") |
| 34 | +// ); |
| 35 | +// return { |
| 36 | +// id: s.id + "-" + e, |
| 37 | +// allFrames: true, |
| 38 | +// matches: s.whiteList || ["<all_urls>"], |
| 39 | +// excludeMatches: s.blackList || [], |
| 40 | +// js: js, |
| 41 | +// runAt: EventMap[e], |
| 42 | +// world: chrome.scripting.ExecutionWorld.MAIN, |
| 43 | +// }; |
| 44 | +// }) |
| 45 | +// ) |
| 46 | +// .flat() |
| 47 | +// .filter((_) => _); |
| 48 | + |
| 49 | +// console.log(scripts); |
| 50 | + |
| 51 | +// chrome.scripting.registerContentScripts(scripts, () => { |
| 52 | +// console.log("Register content script DONE."); |
| 53 | +// }); |
| 54 | +// })(); |
54 | 55 |
|
55 | | -// updateBadge(tabId, CACHED.runCount[tabId]); |
| 56 | +// function getscriptURL(fileName) { |
| 57 | +// return "scripts/" + fileName; |
56 | 58 | // } |
57 | 59 |
|
58 | 60 | // function updateBadge(tabId, text = "", bgColor = "#666") { |
|
0 commit comments