add official Chrome feature demos
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
export function logTo(target, title, payload) {
|
||||
const el = typeof target === "string" ? document.querySelector(target) : target;
|
||||
if (!el) return;
|
||||
const stamp = new Date().toLocaleTimeString("zh-CN", { hour12: false });
|
||||
const entry = {
|
||||
time: stamp,
|
||||
event: title,
|
||||
...payload,
|
||||
};
|
||||
el.textContent = `${JSON.stringify(entry, null, 2)}\n\n${el.textContent}`.trim();
|
||||
}
|
||||
|
||||
export function setText(selector, value) {
|
||||
const el = document.querySelector(selector);
|
||||
if (el) el.textContent = value;
|
||||
}
|
||||
|
||||
export function escapeHtml(value) {
|
||||
return String(value)
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">")
|
||||
.replaceAll('"', """);
|
||||
}
|
||||
Reference in New Issue
Block a user