From 07788b4e5ea96e6d5a8d0fc49aa8f0dac52bba88 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Fri, 30 Aug 2024 14:07:23 -0300 Subject: [PATCH] Inject vendor.js via loader --- packages/typescript/postman/src/postman/request.ts | 2 +- src/html/main/random.html.erb | 1 - src/html/main/redirect.html.erb | 1 - src/html/main/surah-index.html.erb | 1 - src/html/main/surah-stream.html.erb | 1 - src/js/loaders/SurahIndexLoader.ts | 11 +++++++---- src/js/loaders/SurahStreamLoader.ts | 11 +++++++---- src/js/main/surah-index.tsx | 5 +---- src/js/main/surah-stream.tsx | 5 +---- 9 files changed, 17 insertions(+), 21 deletions(-) diff --git a/packages/typescript/postman/src/postman/request.ts b/packages/typescript/postman/src/postman/request.ts index 7937ad3e7..11caec9d2 100644 --- a/packages/typescript/postman/src/postman/request.ts +++ b/packages/typescript/postman/src/postman/request.ts @@ -10,7 +10,7 @@ export default { const { href } = item; return fetch(href, options) .then((res) => res.text()) - .then((text) => ({ type: 'application/javascript', text })) + .then((text) => ({ type: 'application/javascript', text, ...item.props })) .then((props) => Object.assign(document.createElement('script'), props)); }, diff --git a/src/html/main/random.html.erb b/src/html/main/random.html.erb index 0d4990ad5..171f8fb52 100644 --- a/src/html/main/random.html.erb +++ b/src/html/main/random.html.erb @@ -18,7 +18,6 @@ <%= erb("_favicon.html.erb") %> - diff --git a/src/html/main/redirect.html.erb b/src/html/main/redirect.html.erb index ebf6d2d20..27484624d 100644 --- a/src/html/main/redirect.html.erb +++ b/src/html/main/redirect.html.erb @@ -15,7 +15,6 @@ <%= erb("_favicon.html.erb") %> - diff --git a/src/html/main/surah-index.html.erb b/src/html/main/surah-index.html.erb index a8a670c1b..f8b993c08 100644 --- a/src/html/main/surah-index.html.erb +++ b/src/html/main/surah-index.html.erb @@ -22,7 +22,6 @@ <%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
- diff --git a/src/html/main/surah-stream.html.erb b/src/html/main/surah-stream.html.erb index 91600c450..ecf1ca2c7 100644 --- a/src/html/main/surah-stream.html.erb +++ b/src/html/main/surah-stream.html.erb @@ -25,7 +25,6 @@ data-surah-id="<%= context.surah.id %>" data-audio-base-url="<%= audio_base_url %>"> - diff --git a/src/js/loaders/SurahIndexLoader.ts b/src/js/loaders/SurahIndexLoader.ts index 5bd0282dd..f2af082d4 100644 --- a/src/js/loaders/SurahIndexLoader.ts +++ b/src/js/loaders/SurahIndexLoader.ts @@ -18,7 +18,8 @@ import { formatNumber } from "~/lib/t"; const progressBar: HTMLProgressElement = loader.querySelector("progress")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; postman( - item.script(`/js/main/surah-index.js?v=${rev}`), + item.script(`/js/main/vendor.js?v=${rev}`, { id: 0 }), + item.script(`/js/main/surah-index.js?v=${rev}`, { id: 1 }), item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"), item.font("Mada Regular", "url(/fonts/mada-regular.ttf"), item.progress((percent: number) => { @@ -34,8 +35,10 @@ import { formatNumber } from "~/lib/t"; [loader, style].forEach((el) => el.remove()); pkg.fonts.forEach((f) => document.fonts.add(f)); pkg.css.forEach((s) => document.head.appendChild(s)); - pkg.scripts.forEach((s) => - document.body.removeChild(document.body.appendChild(s)), - ); + pkg.scripts + .sort((s) => s.id) + .forEach((s) => { + document.body.removeChild(document.body.appendChild(s)); + }); }); })(); diff --git a/src/js/loaders/SurahStreamLoader.ts b/src/js/loaders/SurahStreamLoader.ts index faec60ff6..16215d72b 100644 --- a/src/js/loaders/SurahStreamLoader.ts +++ b/src/js/loaders/SurahStreamLoader.ts @@ -19,7 +19,8 @@ import { formatNumber } from "~/lib/t"; const progressBar = loader.querySelector("progress")!; const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!; postman( - item.script(`/js/main/surah-stream.js?v=${rev}`), + item.script(`/js/main/vendor.js?v=${rev}`, { id: 0 }), + item.script(`/js/main/surah-stream.js?v=${rev}`, { id: 1 }), item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)"), item.font("Mada Regular", "url(/fonts/mada-regular.ttf"), /* eslint-disable */ @@ -41,8 +42,10 @@ import { formatNumber } from "~/lib/t"; pkg.fonts.forEach((f) => document.fonts.add(f)); pkg.css.forEach((s) => document.head.appendChild(s)); pkg.json.forEach((o) => document.body.appendChild(o)); - pkg.scripts.forEach((s) => - document.body.removeChild(document.body.appendChild(s)), - ); + pkg.scripts + .sort((s) => s.id) + .forEach((s) => { + document.body.removeChild(document.body.appendChild(s)); + }); }); })(); diff --git a/src/js/main/surah-index.tsx b/src/js/main/surah-index.tsx index 2d6a899c8..a5aa05e2c 100644 --- a/src/js/main/surah-index.tsx +++ b/src/js/main/surah-index.tsx @@ -14,8 +14,5 @@ import { SurahIndex } from "~/components/SurahIndex"; (e: TSurah) => new Surah(e), ); - render( - , - root - ); + render(, root); })(); diff --git a/src/js/main/surah-stream.tsx b/src/js/main/surah-stream.tsx index fc2e16f4d..1346730da 100644 --- a/src/js/main/surah-stream.tsx +++ b/src/js/main/surah-stream.tsx @@ -30,8 +30,5 @@ import { SurahStream } from "~/components/SurahStream"; ayah.ms = ms * 1000; } - render( - , - root - ); + render(, root); })();