36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
function get(name) {
|
|
if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(location.search))
|
|
return decodeURIComponent(name[1]);
|
|
}
|
|
async function getArticle(url) {
|
|
let article = get("a")
|
|
if (get("m") === "1") {
|
|
return (await Mercury.parse(url, {html: article})).content || ""
|
|
} else {
|
|
return article
|
|
}
|
|
}
|
|
document.documentElement.style.fontSize = get("s") + "px"
|
|
let url = get("u")
|
|
getArticle(url).then(article => {
|
|
let domParser = new DOMParser()
|
|
let dom = domParser.parseFromString(get("h"), "text/html")
|
|
dom.getElementsByTagName("article")[0].innerHTML = article
|
|
let baseEl = dom.createElement('base')
|
|
baseEl.setAttribute('href', url.split("/").slice(0, 3).join("/"))
|
|
dom.head.append(baseEl)
|
|
for (let s of dom.getElementsByTagName("script")) {
|
|
s.parentNode.removeChild(s)
|
|
}
|
|
for (let e of dom.querySelectorAll("*[src]")) {
|
|
e.src = e.src
|
|
}
|
|
for (let e of dom.querySelectorAll("*[href]")) {
|
|
e.href = e.href
|
|
}
|
|
let main = document.getElementById("main")
|
|
main.innerHTML = dom.body.innerHTML
|
|
main.classList.add("show")
|
|
})
|
|
|