Ver código fonte

ref: css bundle injection

Sven 9 meses atrás
pai
commit
4c19701aa6
2 arquivos alterados com 7 adições e 6 exclusões
  1. 3 3
      src/index.ts
  2. 4 3
      src/tools/post-build.ts

+ 3 - 3
src/index.ts

@@ -124,7 +124,7 @@ async function onDomLoad() {
     initObservers();
 
     await Promise.allSettled([
-      insertGlobalStyle(),
+      injectCssBundle(),
       initVersionCheck(),
     ]);
   }
@@ -280,9 +280,9 @@ async function onDomLoad() {
 //#region css
 
 /** Inserts the bundled CSS files imported throughout the script into a <style> element in the <head> */
-async function insertGlobalStyle() {
+async function injectCssBundle() {
   if(!await addStyleFromResource("css-bundle"))
-    error("Couldn't add global CSS bundle due to an error");
+    error("Couldn't inject CSS bundle due to an error");
 }
 
 /** Initializes global CSS variables */

+ 4 - 3
src/tools/post-build.ts

@@ -107,8 +107,7 @@ ${localizedDescriptions ? "\n" + localizedDescriptions : ""}\
 // @grant             GM.xmlHttpRequest
 // @grant             GM.openInTab
 // @grant             unsafeWindow
-// @noframes
-// @resource          css-bundle              ${getResourceUrl("/dist/BetterYTM.css", buildNbr)}\
+// @noframes\
 ${resourcesDirectives ? "\n" + resourcesDirectives : ""}\
 ${requireDirectives ? "\n" + requireDirectives : ""}\
 ${devDirectives ? "\n" + devDirectives : ""}
@@ -208,7 +207,7 @@ function insertValues(userscript: string, replacements: Record<string, Stringifi
 /** Removes sourcemapping comments */
 function remSourcemapComments(input: string) {
   return input
-    .replace(/\/\/#\s?sourceMappingURL\s?=\s?.+$/gm, "");
+    .replace(/\/\/\s?#\s?sourceMappingURL\s?=\s?.+$/gm, "");
 }
 
 /**
@@ -244,6 +243,8 @@ async function getResourceDirectives(buildNbr: string) {
     const resourcesFile = String(await readFile(join(assetFolderPath, "resources.json")));
     const resources = JSON.parse(resourcesFile) as Record<string, string>;
 
+    resources["css-bundle"] = getResourceUrl("/dist/BetterYTM.css", buildNbr);
+
     for(const [locale] of Object.entries(locales))
       resources[`trans-${locale}`] = `translations/${locale}.json`;