FluentReader/dist/article/article.js

27 lines
1.0 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-06-07 07:03:19 +02:00
document.documentElement.style.fontSize = get("s") + "px"
2020-06-10 05:33:25 +02:00
let html = decodeURIComponent(window.atob(get("h")))
let domParser = new DOMParser()
let dom = domParser.parseFromString(html, "text/html")
let baseEl = dom.createElement('base')
baseEl.setAttribute('href', get("u").split("/").slice(0, 3).join("/"))
dom.head.append(baseEl)
for (let i of dom.querySelectorAll("img")) {
i.src = i.src
}
for (let s of dom.querySelectorAll("script")) {
s.parentNode.removeChild(s)
}
2020-06-06 13:48:08 +02:00
let main = document.getElementById("main")
2020-06-10 05:33:25 +02:00
main.innerHTML = dom.body.innerHTML
2020-06-06 13:48:08 +02:00
document.addEventListener("click", event => {
event.preventDefault()
2020-06-07 07:03:19 +02:00
if (event.target.href) post("request-navigation", event.target.href)
2020-06-07 11:45:47 +02:00
})
document.addEventListener("contextmenu", event => {
let text = document.getSelection().toString()
if (text) post("context-menu", [event.clientX, event.clientY], text)
2020-06-06 13:48:08 +02:00
})