-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
65 lines (65 loc) · 2.61 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(() => {
const e = window.matchMedia("(prefers-color-scheme: dark)").matches
? "github-dark"
: "github-light",
t = new URL(location.href),
n = t.searchParams.get("utterances");
n &&
(localStorage.setItem("utterances-session", n),
t.searchParams.delete("utterances"),
history.replaceState(void 0, document.title, t.href));
let r = document.currentScript;
void 0 === r &&
(r = document.querySelector(
'script[src^="https://utteranc.es/client.js"],script[src^="http://localhost:4000/client.js"]'
));
const i = {};
for (let e = 0; e < r.attributes.length; e++) {
const t = r.attributes.item(e);
i[t.name.replace(/^data-/, "")] = t.value;
}
"preferred-color-scheme" === i.theme && (i.theme = e);
const a = document.querySelector("link[rel='canonical']");
(i.url = a ? a.href : t.origin + t.pathname + t.search),
(i.origin = t.origin),
(i.pathname =
t.pathname.length < 2
? "index"
: t.pathname.substr(1).replace(/\.\w+$/, "")),
(i.title = document.title);
const s = document.querySelector("meta[name='description']");
i.description = s ? s.content : "";
const o = encodeURIComponent(i.description).length;
o > 1e3 &&
(i.description = i.description.substr(
0,
Math.floor((1e3 * i.description.length) / o)
));
const c = document.querySelector(
"meta[property='og:title'],meta[name='og:title']"
);
(i["og:title"] = c ? c.content : ""),
(i.session = n || localStorage.getItem("utterances-session") || ""),
document.head.insertAdjacentHTML(
"afterbegin",
"<style>\n .utterances {\n position: relative;\n box-sizing: border-box;\n width: 100%;\n max-width: 760px;\n margin-left: auto;\n margin-right: auto;\n }\n .utterances-frame {\n color-scheme: light;\n position: absolute;\n left: 0;\n right: 0;\n width: 1px;\n min-width: 100%;\n max-width: 100%;\n height: 100%;\n border: 0;\n }\n </style>"
);
const l = r.src.match(/^https:\/\/utteranc\.es|http:\/\/localhost:\d+/)[0],
h = `${l}/utterances.html`;
r.insertAdjacentHTML(
"afterend",
`<div class="utterances">\n <iframe class="utterances-frame" title="Comments" scrolling="no" src="${h}?${new URLSearchParams(
i
)}" loading="lazy"></iframe>\n </div>`
);
const m = r.nextElementSibling;
r.parentElement.removeChild(r),
addEventListener("message", (e) => {
if (e.origin !== l) return;
const t = e.data;
t &&
"resize" === t.type &&
t.height &&
(m.style.height = `${t.height}px`);
});
})();