FluentReader/dist/article/article.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-06-06 13:48:08 +02:00
function get(name) {
if (name = (new RegExp('[?&]' + encodeURIComponent(name) + '=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
2020-08-05 13:03:05 +02:00
async function getArticle(url) {
let article = get("a")
if (get("m") === "1") {
return (await Mercury.parse(url, {html: article})).content || ""
} else {
return article
}
2020-06-10 05:33:25 +02:00
}
2020-08-05 13:03:05 +02:00
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
})