mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-16 03:11:59 +01:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
// Here we are making iframes responsive. Particularly useful for inline Youtube videos.
|
|
function wrapFrames() {
|
|
document.querySelectorAll("iframe").forEach(element => {
|
|
var wrapper = document.createElement("div");
|
|
wrapper.classList.add("iframeWrap");
|
|
element.parentNode.insertBefore(wrapper, element);
|
|
wrapper.appendChild(element);
|
|
});
|
|
}
|
|
|
|
// Strip out all styling so that we have better control over layout
|
|
function stripStyles() {
|
|
document.getElementsByTagName("body")[0].querySelectorAll("style, link[rel=stylesheet]").forEach(element => element.remove());
|
|
document.getElementsByTagName("body")[0].querySelectorAll("[style]").forEach(element => element.removeAttribute("style"));
|
|
}
|
|
|
|
// Convert all image locations to be absolute
|
|
function convertImgSrc() {
|
|
document.querySelectorAll("img").forEach(element => {
|
|
element.src = new URL(element.src, document.baseURI).href;
|
|
});
|
|
}
|
|
|
|
function error() {
|
|
document.body.innerHTML = "error";
|
|
}
|
|
|
|
function render(data) {
|
|
document.getElementsByTagName("style")[0].innerHTML = data.style;
|
|
document.body.innerHTML = data.body;
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
wrapFrames()
|
|
stripStyles()
|
|
convertImgSrc()
|
|
|
|
postRenderProcessing()
|
|
}
|