Fix YouTube fullscreen on iOS devices

This commit is contained in:
Maurice Parker
2023-04-13 15:59:36 -05:00
parent f21cd774db
commit eefd5d79da
6 changed files with 95 additions and 12 deletions

View File

@@ -0,0 +1,44 @@
function fixYouTube() {
var checkForVideoTimer = null;
function callback(event) {
var fullScreenButtonOld = document.querySelector("button.ytp-fullscreen-button");
var fullScreenButton = fullScreenButtonOld.cloneNode(true);
fullScreenButton.style = false;
fullScreenButton.setAttribute("aria-disabled", "false");
fullScreenButton.onclick = function() {
var player = document.querySelector("video");
player.webkitRequestFullScreen();
};
fullScreenButtonOld.parentNode.replaceChild(fullScreenButton, fullScreenButtonOld);
}
function checkForVideo() {
var video = document.querySelector("video");
if (video) {
clearInterval(checkForVideoTimer);
var goFullScreen = function() {
video.webkitRequestFullScreen();
};
var fullScreenButtonOld = document.querySelector("button.ytp-fullscreen-button");
var fullScreenButton = fullScreenButtonOld.cloneNode(true);
fullScreenButton.style = false;
fullScreenButton.setAttribute("aria-disabled", "false");
fullScreenButton.onclick = goFullScreen;
fullScreenButtonOld.parentNode.replaceChild(fullScreenButton, fullScreenButtonOld);
}
}
const hostname = window.location.hostname;
if (hostname.endsWith(".youtube.com") || hostname.endsWith(".youtube-nocookie.com")) {
checkForVideoTimer = setInterval(checkForVideo, 100);
}
document.addEventListener('webkitfullscreenchange', fullScreenChange, true);
}
document.addEventListener("DOMContentLoaded", function(event) {
fixYouTube();
});

View File

@@ -156,19 +156,18 @@ function removeWpSmiley() {
}
}
function addYouTubeVideos() {
function addYouTubeVideo() {
const titleURL = document.querySelector(".articleTitle A").getAttribute("href")
const youTubeLink = "https://www.youtube.com/watch?v="
if (!titleURL.startsWith(youTubeLink)) {
return;
}
// Dynamically add the YouTube frame
const bodyContainer = document.querySelector("#bodyContainer");
bodyContainer.setAttribute("style", "position: relative; padding-bottom: 56.25%; height: 100%; max-width: 100% !important; overflow: hidden;")
var youTubeFrame = document.createElement("iFrame");
youTubeFrame.setAttribute("src", "https://www.youtube.com/embed/" + titleURL.substring(youTubeLink.length));
youTubeFrame.setAttribute("src", "https://www.youtube.com/embed/" + titleURL.substring(youTubeLink.length) + "?fs=0&rel=0");
youTubeFrame.setAttribute("style", "position: absolute; top: 0; left: 0; width: 100%; height: 100%;");
youTubeFrame.setAttribute("title", "YouTube video player");
youTubeFrame.setAttribute("frameborder", "0");
@@ -186,6 +185,6 @@ function processPage() {
flattenPreElements();
styleLocalFootnotes();
removeWpSmiley();
addYouTubeVideos();
addYouTubeVideo();
postRenderProcessing();
}

View File

@@ -0,0 +1,21 @@
//
// WKUserContentController-Extensions.swift
// NetNewsWire
//
// Created by Maurice Parker on 4/5/23.
// Copyright © 2023 Ranchero Software. All rights reserved.
//
import Foundation
import WebKit
extension WKUserContentController {
func addUserScript(forResource res: String, withExtension ext: String) {
if let url = Bundle.main.url(forResource: res, withExtension: ext), let source = try? String(contentsOf: url) {
let userScript = WKUserScript(source: source, injectionTime: WKUserScriptInjectionTime.atDocumentStart, forMainFrameOnly: false)
addUserScript(userScript)
}
}
}