diff --git a/content.js b/content.js new file mode 100644 index 0000000..92dfe0e --- /dev/null +++ b/content.js @@ -0,0 +1,187 @@ +// Banner +console.log('%cYou%ctube%c %cPop%c\nBetter youtube', 'color:#f00;font-size:40px;font-weight:bold;font-family:Arial', 'background:#f00;color:#fff;border-radius:0.5rem;font-size:40px;font-weight:bold;font-family:Arial', 'font-size:40px', 'color:#b7f;font-size:40px;font-weight:bold;font-family:Arial', 'font-family:Arial'); + +const delay = ms => new Promise(res => setTimeout(res, ms)); + +function id() { + return (window.location.href.split('v=')[1] || '').split('&')[0]; +} + +function shut() { + document.querySelector('.video-stream.html5-main-video').pause(); + document.querySelector('.video-stream.html5-main-video').muted = true +} + +async function change() { + if (window.location.href.includes('/embed/')) return; + while (!document.querySelector('#player-container-inner')) { + await delay(500) + } + while (!document.querySelector('.video-stream.html5-main-video')) { + await delay(500) + } + shut() + document.getElementById('player-container-inner').style.display = 'none'; + document.querySelector('#container.style-scope.ytd-player').style.display = 'none'; + fetch('https://api.fsh.plus/video?id='+id()).then(async res => { + let ytv = await res.json(); + shut() + ytv = ytv.video; + document.querySelector('#player-container-outer.style-scope.ytd-watch-flexy').insertAdjacentHTML("afterbegin", ``); + let player = document.getElementById('ytpop'); + + let previousUrl = ''; + const observer = new MutationObserver(function(mutations) { + if (window.location.href !== previousUrl) { + previousUrl = window.location.href; + if (window.location.href.split('v=').length<2) { + player.pause(); + } else { + fetch('https://api.fsh.plus/video?id='+id()).then(async ress => { + ress = await ress.json(); + player.src = ress.video; + shut(); + player.pause(); + player.play(); + }) + } + } else { + shut() + } + }); + observer.observe(document, {subtree: true, childList: true}); + + document.body.onkeyup = function(e) { + if (e.target.tagName.toLowerCase() === 'input') return; + if (e.detail.simulated) return; + shut() + switch(e.key) { + case ' ': + player.paused ? player.play() : player.pause() + break; + case 'ArrowLeft': + player.currentTime = player.currentTime-5; + break; + case 'ArrowRight': + player.currentTime = player.currentTime+5; + break; + case ',': + player.currentTime = player.currentTime-0.1 + if(player.paused){player.play();player.pause()} + break; + case '.': + player.currentTime = player.currentTime+0.1 + if(player.paused){player.play();player.pause()} + break; + case 'ArrowUp': + if (ytpop.volume<1)ytpop.volume = ytpop.volume+0.05; + break; + case 'ArrowDown': + if (ytpop.volume>0)ytpop.volume = ytpop.volume-0.05; + break; + case 't': + document.querySelector('#full-bleed-container.style-scope.ytd-watch-flexy').style.display = 'none'; + document.querySelector('#player.style-scope.ytd-watch-flexy').style.display = 'block'; + break; + } + } + }) +} + +chrome.storage.sync.get('enabled', function (data) { + if (data.enabled) { + change() + } +}); + +async function down() { + if (window.location.href.includes('/embed/')) return; + while (!document.querySelector('ytd-menu-renderer.style-scope.ytd-watch-metadata')) { + await delay(500) + } + document.querySelector('#actions ytd-menu-renderer yt-button-shape#button-shape.style-scope.ytd-menu-renderer').insertAdjacentHTML("beforebegin", ` + + +

YT Pop

+

Download this youtube video

+
+ + +
+ + +
`) + const observer = new MutationObserver(function(mutations) { + document.querySelectorAll('#flexible-item-buttons.style-scope.ytd-menu-renderer ytd-download-button-renderer').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('tp-yt-paper-listbox.style-scope.ytd-menu-popup-renderer ytd-menu-service-item-download-renderer').forEach(t => {t.style.display = 'none';}) + }); + observer.observe(document, {subtree: true, childList: true}); +} + +chrome.storage.sync.get('down', function (data) { + if (data.down) { + down() + } +}); + +function noads() { + const observer = new MutationObserver(function(mutations) { + document.querySelectorAll('#player-ads').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('.ytd-page-top-ad').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('.ytd-ad-slot-renderer').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('ytd-rich-item-renderer:has(.ytd-ad-slot-renderer)').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('ytd-banner-promo-renderer').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('yt-mealbar-promo-renderer').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('ytd-rich-item-renderer:has(ytd-feed-nudge-renderer)').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('#attached-survey').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('div.ytp-suggested-action').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('ytd-brand-video-singleton-renderer').forEach(t => {t.style.display = 'none';}) + document.querySelectorAll('.ytp-ad-player-overlay-flyout-cta').forEach(t=>{document.querySelector('video').playbackRate = 16.0;document.querySelector('video').currentTime = document.querySelector('video').duration;document.querySelector('.ytp-ad-skip-button-modern').click()}) + document.querySelectorAll('.ytp-ad-skip-button-modern').forEach(t => { + t.click() + }) + }); + observer.observe(document, {subtree: true, childList: true}); +} + +chrome.storage.sync.get('noads', function (data) { + if (data.noads) { + noads() + } +}); + +chrome.storage.sync.get('nocurves', function (data) { + if (data.nocurves) { + document.head.insertAdjacentHTML("beforeend", ``) + } +}); + +chrome.storage.sync.get('noshorts', function (data) { + if (data.noshorts) { + document.head.insertAdjacentHTML("beforeend", ``) + } +}); + +chrome.storage.sync.get('nothanks', function (data) { + if (data.nothanks) { + document.head.insertAdjacentHTML("beforeend", ``) + } +}); + +chrome.storage.sync.get('nomix', function (data) { + if (data.nomix) { + const observer = new MutationObserver(function(mutations) { + document.querySelectorAll('ytd-rich-item-renderer:has(ytd-thumbnail-overlay-bottom-panel-renderer.ytd-playlist-thumbnail)').forEach(t => {t.style.display = 'none';}) + }); + observer.observe(document, {subtree: true, childList: true}); + } +}); \ No newline at end of file