Add tests && add img lazy async

This commit is contained in:
kwaroran
2025-04-14 15:28:14 +09:00
parent 666e1f71b0
commit 35f0f8e1dc
4 changed files with 23 additions and 0 deletions

1
.gitignore vendored
View File

@@ -13,6 +13,7 @@ save/
dist-web/ dist-web/
dist-ssr dist-ssr
*.local *.local
test/test.ts
xplugin/ xplugin/
src-others/ src-others/
/memo.txt /memo.txt

View File

@@ -1,6 +1,7 @@
import "./ts/polyfill"; import "./ts/polyfill";
import "core-js/actual" import "core-js/actual"
import "./ts/storage/database.svelte" import "./ts/storage/database.svelte"
import {declareTest} from "./test/runTest"
import App from "./App.svelte"; import App from "./App.svelte";
import { loadData } from "./ts/globalApi.svelte"; import { loadData } from "./ts/globalApi.svelte";
import { initHotkey } from "./ts/hotkey"; import { initHotkey } from "./ts/hotkey";
@@ -13,6 +14,7 @@ let app = mount(App, {
}); });
loadData() loadData()
initHotkey() initHotkey()
declareTest()
document.getElementById('preloading').remove() document.getElementById('preloading').remove()
export default app; export default app;

10
src/test/runTest.ts Normal file
View File

@@ -0,0 +1,10 @@
export function declareTest() {
if(import.meta.env.DEV){
globalThis.test = async () => {
const d = await import("./test.js")
return d.test()
}
}
}

View File

@@ -45,6 +45,16 @@ DOMPurify.addHook("uponSanitizeElement", (node: HTMLElement, data) => {
return node.parentNode.removeChild(node); return node.parentNode.removeChild(node);
} }
} }
if(data.tagName === 'img'){
const loading = node.getAttribute("loading")
if(!loading){
node.setAttribute("loading","lazy")
}
const decoding = node.getAttribute("decoding")
if(!decoding){
node.setAttribute("decoding", "async")
}
}
}); });
DOMPurify.addHook("uponSanitizeAttribute", (node, data) => { DOMPurify.addHook("uponSanitizeAttribute", (node, data) => {