Add tests && add img lazy async
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
|
||||||
|
|||||||
@@ -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
10
src/test/runTest.ts
Normal 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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user