2019-09-21 23:11:09 +02:00
|
|
|
// These mouse functions are used by NetNewsWire for Mac to display link previews
|
2019-09-21 11:34:11 +02:00
|
|
|
function mouseDidEnterLink(anchor) {
|
|
|
|
window.webkit.messageHandlers.mouseDidEnter.postMessage(anchor.href);
|
|
|
|
}
|
|
|
|
function mouseDidExitLink(anchor) {
|
|
|
|
window.webkit.messageHandlers.mouseDidExit.postMessage(anchor.href);
|
|
|
|
}
|
|
|
|
|
2019-09-21 23:11:09 +02:00
|
|
|
// Add the mouse listeners for the above functions
|
|
|
|
function linkHover() {
|
|
|
|
document.querySelectorAll("a").forEach(element => {
|
|
|
|
element.addEventListener("mouseenter", function() { mouseDidEnterLink(this) });
|
|
|
|
element.addEventListener("mouseleave", function() { mouseDidExitLink(this) });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here we are making iframes responsive. Particularly useful for inline Youtube videos.
|
2019-09-21 11:34:11 +02:00
|
|
|
function wrapFrames() {
|
|
|
|
document.querySelectorAll("iframe").forEach(element => {
|
|
|
|
var wrapper = document.createElement("div");
|
|
|
|
wrapper.classList.add("iframeWrap");
|
|
|
|
element.parentNode.insertBefore(wrapper, element);
|
|
|
|
wrapper.appendChild(element);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-21 23:11:09 +02:00
|
|
|
// Strip out all styling so that we have better control over layout
|
2019-09-21 11:34:11 +02:00
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2019-09-21 23:11:09 +02:00
|
|
|
// Add the playsinline attribute to any HTML5 videos that don't have it.
|
|
|
|
// Without this attribute videos may autoplay and take over the whole screen
|
|
|
|
// on an iphone when viewing an article.
|
2019-09-21 22:59:51 +02:00
|
|
|
function inlineVideos() {
|
|
|
|
document.querySelectorAll("video").forEach(element => {
|
|
|
|
element.setAttribute("playsinline", true)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-21 11:34:11 +02:00
|
|
|
function error() {
|
|
|
|
document.body.innerHTML = "error";
|
|
|
|
}
|
|
|
|
|
|
|
|
function render(data) {
|
|
|
|
document.getElementsByTagName("style")[0].innerHTML = data.style;
|
|
|
|
document.body.innerHTML = data.body;
|
2019-09-21 23:11:09 +02:00
|
|
|
|
2019-09-21 11:34:11 +02:00
|
|
|
window.scrollTo(0, 0);
|
|
|
|
|
|
|
|
wrapFrames()
|
|
|
|
stripStyles()
|
|
|
|
linkHover()
|
2019-09-21 22:59:51 +02:00
|
|
|
inlineVideos()
|
2019-09-21 11:34:11 +02:00
|
|
|
}
|