1 2 3 4 5 6 7 8 9 10 11 12
type DataType = { [key: string]: string }; export const injectScriptHead = (src: string, data: DataType = {}) => { const s = document.createElement("script") as HTMLScriptElement; s.src = chrome.runtime.getURL(src); for (const i in data) { s.setAttribute(`data-${i}`, data[i]); } (document.head || document.documentElement).append(s); };