FluentReader/dist/article/article.js

46 lines
1.5 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]);
}
let dir = get("d")
if (dir === "1") {
document.body.classList.add("rtl")
} else if (dir === "2") {
document.body.classList.add("vertical")
document.body.addEventListener("wheel", (evt) => {
document.scrollingElement.scrollLeft -= evt.deltaY;
});
}
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"
2021-12-16 08:00:48 +01:00
let font = get("f")
if (font) document.body.style.fontFamily = `"${font}"`
2020-08-05 13:03:05 +02:00
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
2020-08-16 13:33:47 +02:00
main.classList.add("show")
2020-08-05 13:03:05 +02:00
})