Skip to content

Instantly share code, notes, and snippets.

@Xunnamius
Created May 2, 2024 22:41
Show Gist options
  • Save Xunnamius/419684155f317f086ceb52ceb66a870a to your computer and use it in GitHub Desktop.
Save Xunnamius/419684155f317f086ceb52ceb66a870a to your computer and use it in GitHub Desktop.
Regain control by popping the shaka player video element out of the Next.js app that MSNBC uses to stream their live content.
// ==UserScript==
// @name Remove the trash from MSNBC navbar
// @namespace http://tampermonkey.net/
// @version 2024-01-27
// @description try to take over the world!
// @author You
// @match https://*.msnbc.com/*
// @exclude https://*.msnbc.com/sigma.html*
// @noframes
// @icon https://www.google.com/s2/favicons?sz=64&domain=msnbc.com
// @grant none
// ==/UserScript==
(async function() {
'use strict';
document.querySelectorAll('.shortcuts-list-item:nth-child(3), .shortcuts-list-item:nth-child(4), .shortcuts-list-item:nth-child(5)').forEach(x => x.parentElement.removeChild(x));
const oldFirstChild = document.querySelector('.shortcuts-list-item:first-child');
if(!oldFirstChild) {
alert('assertion failed: cannot find first child');
return;
}
oldFirstChild.parentElement.innerHTML = oldFirstChild.outerHTML + oldFirstChild.parentElement.innerHTML;
console.log('upgraded nav bar');
console.log('added escape hatch');
const newFirstChild = document.querySelector('.shortcuts-list-item:first-child');
const newFirstChildAnchor = newFirstChild.querySelector('a');
newFirstChildAnchor.href = '#';
newFirstChildAnchor.innerText = '...';
let msnbcVideoElement;
for(let count = 0; !(msnbcVideoElement = document.querySelector('#core-video-shaka')); count++) {
if(count >= 5) {
alert('assertion failed: could not find video element after 5 attempts');
return;
}
console.log('waiting 5 seconds for iframe element to appear...');
await new Promise((resolve) => setTimeout(resolve, 5000));
}
console.log('video element loaded');
newFirstChildAnchor.addEventListener('click', function(event) {
event.preventDefault();
event.stopPropagation();
const htmlElement = document.querySelector('html');
const bodyElement = document.querySelector('body');
if(!htmlElement || !bodyElement) {
alert('assertion failed: missing html/body element (???)');
return;
}
htmlElement.style.width = '100%';
htmlElement.style.height = '100%';
htmlElement.style.overflow = 'hidden';
bodyElement.style.width = '100%';
bodyElement.style.height = '100%';
bodyElement.style.overflow = 'hidden';
msnbcVideoElement.style.width = '100%';
msnbcVideoElement.style.height = '100%';
msnbcVideoElement.style.maxHeight = '100vh';
msnbcVideoElement.style.overflow = 'hidden';
msnbcVideoElement.style.objectFit = 'contain';
bodyElement.textContent = '';
bodyElement.appendChild(msnbcVideoElement);
console.log('committed baseline styles');
msnbcVideoElement.style.zIndex = 'unset';
console.log('removed z-index from player');
msnbcVideoElement.setAttribute('controls', true);
console.log('added controls to player');
msnbcVideoElement.muted = false;
console.log('unmuted player');
msnbcVideoElement.currentTime -= 30_000;
console.log('rewound stream by 30 seconds');
console.log('escape complete!');
});
newFirstChildAnchor.innerText = 'ESCAPE';
console.log('escape ready');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment