diff --git a/js&css/extension/functions.js b/js&css/extension/functions.js index cc7ac242e..4b6c9f742 100644 --- a/js&css/extension/functions.js +++ b/js&css/extension/functions.js @@ -5,4 +5,5 @@ --------------------------------------------------------------*/ extension.functions.getUrlParameter = function (url, parameter) { var match = url.match(new RegExp('(\\?|\\&)' + parameter + '=[^&]+')); - if (match) {return match[0].substr(3);}}; \ No newline at end of file + if (match) {return match[0].substr(3);} +}; \ No newline at end of file diff --git a/js&css/extension/www.youtube.com/general/general.js b/js&css/extension/www.youtube.com/general/general.js index 374627927..ca9f80a45 100644 --- a/js&css/extension/www.youtube.com/general/general.js +++ b/js&css/extension/www.youtube.com/general/general.js @@ -356,7 +356,8 @@ extension.features.markWatchedVideos = function (anything) { target.itMarkWatchedVideosButton.appendChild(svg); target.itMarkWatchedVideosButton.appendChild(svg2); if (extension.storage.get('watched') && extension.storage.get('watched')[id]) { - target.itMarkWatchedVideosButton.setAttribute('watched', '')}; + target.itMarkWatchedVideosButton.setAttribute('watched', '') + }; target.appendChild(target.itMarkWatchedVideosButton); target.itMarkWatchedVideosButton.addEventListener('click', function (event) { var id = this.dataset.id, @@ -379,7 +380,8 @@ extension.features.markWatchedVideos = function (anything) { chrome.storage.local.set({ watched: extension.storage.get('watched') - });}); + }); + }); } else { var button = target.itMarkWatchedVideosButton; diff --git a/js&css/web-accessible/core.js b/js&css/web-accessible/core.js index e0546cc26..a84a23e31 100644 --- a/js&css/web-accessible/core.js +++ b/js&css/web-accessible/core.js @@ -397,7 +397,8 @@ document.addEventListener('it-message-from-extension', function () { break case 'playerlistUpNextAutoplay': if (this.storage.playlist_up_next_autoplay !== false) { - if (playlistData.currentIndex != playlistData.localCurrentIndex) { playlistData.currentIndex = playlistData.localCurrentIndex;} } + if (playlistData.currentIndex != playlistData.localCurrentIndex) { playlistData.currentIndex = playlistData.localCurrentIndex;} + } break } diff --git a/js&css/web-accessible/functions.js b/js&css/web-accessible/functions.js index eb4d029ac..5cede0fcf 100644 --- a/js&css/web-accessible/functions.js +++ b/js&css/web-accessible/functions.js @@ -129,8 +129,7 @@ ImprovedTube.ytElementsHandler = function (node) { this.improvedtubeYoutubeIcon(); } - } - else if (name === 'TP-YT-APP-DRAWER') { + } else if (name === 'TP-YT-APP-DRAWER') { if (!this.elements.app_drawer) { this.elements.app_drawer = {start: node.querySelector('div#header'), logo: node.querySelector('a#logo') @@ -416,9 +415,26 @@ ImprovedTube.playerOnEnded = function (event) { ImprovedTube.played_time = 0; }; +// https://github.com/code-charity/youtube/pull/2431 ImprovedTube.onkeydown = function () { ImprovedTube.pauseWhileTypingOnYoutube() window.addEventListener('keydown', function () { + ImprovedTube.user_interacted = true; + }, true); +}; + +ImprovedTube.onmousedown = function (event) { + window.addEventListener('mousedown', function (event) { + ImprovedTube.user_interacted = true; + } +} +/* +ImprovedTube.onkeydown = function () { + ImprovedTube.pauseWhileTypingOnYoutube() + window.addEventListener('keydown', function () { + if (!ImprovedTube.user_interacted) { + setTimeout(function () {ImprovedTube.user_interacted = true}, 2500); + } if (ImprovedTube.elements.player && ImprovedTube.elements.player.classList.contains('ad-showing') === false) { ImprovedTube.user_interacted = true; } @@ -428,7 +444,7 @@ ImprovedTube.onkeydown = function () { ImprovedTube.onmousedown = function () { window.addEventListener('mousedown', function (event) { if (!ImprovedTube.user_interacted) { - setTimeout(function () {ImprovedTube.user_interacted = true}, 3000); + setTimeout(function () {ImprovedTube.user_interacted = true}, 2500); if (ImprovedTube.elements.player && ImprovedTube.elements.player.classList.contains('ad-showing') === false) { var path = event.composedPath(); for (var i = 0, l = path.length; i < l; i++) { @@ -441,6 +457,7 @@ ImprovedTube.onmousedown = function () { } }, true); }; +*/ ImprovedTube.getParam = function (query, name) { var params = query.split('&'), diff --git a/js&css/web-accessible/www.youtube.com/channel.js b/js&css/web-accessible/www.youtube.com/channel.js index f341886eb..084139b33 100644 --- a/js&css/web-accessible/www.youtube.com/channel.js +++ b/js&css/web-accessible/www.youtube.com/channel.js @@ -61,8 +61,8 @@ ImprovedTube.channelCompactTheme = function () { document.querySelector("#sections #items") ? styleWithListeners() : styleWithInterval(); } else if (compact.hasApplied) { //cleanup - try {clearInterval(compact.listener)} - catch (err) {console.log("ERR: We couldn't clear listener. Reload page")} + try {clearInterval(compact.listener) + } catch (err) {console.log("ERR: We couldn't clear listener. Reload page")} if (compact.eventHandlerFns.length) removeListeners(); if (compact.styles.length) removeStyles() compact = {} @@ -92,8 +92,7 @@ ImprovedTube.channelCompactTheme = function () { if (!isCompact) { sub.style.display = "none" isCompact = true - } - else { + } else { sub.style.display = "" isCompact = false } diff --git a/js&css/web-accessible/www.youtube.com/player.js b/js&css/web-accessible/www.youtube.com/player.js index 3b2222d0e..20f913590 100644 --- a/js&css/web-accessible/www.youtube.com/player.js +++ b/js&css/web-accessible/www.youtube.com/player.js @@ -9,14 +9,14 @@ ImprovedTube.autoplayDisable = function (videoElement) { if (this.video_url !== location.href) { this.user_interacted = false; } - // if (there is a player) and (no user clicks) and (no ads playing) + //if (there is a player) and (no user clicks) and (no ads playing) // and( ((auto play is off and it is not in a playlist) // or (playlist auto play is off and in a playlist)) // or (we are in a channel and the channel trailer autoplay is off) ) - if (player && !this.user_interacted // (=user didnt click or type) - & !player.classList.contains('ad-showing') // (=no ads playing, needs an update?) - && ((location.href.includes('/watch?') // #1703 // (=video page) + if (player && !this.user_interacted // (=user didnt click or type) + && !player.classList.contains('ad-showing') // (=no ads playing, needs an update?) + && ((location.href.includes('/watch?') // #1703 // (=video page) // player_autoplay_disable & not playlist && (this.storage.player_autoplay_disable && !location.href.includes('list=')) // !playlist_autoplay & playlist @@ -877,8 +877,7 @@ ImprovedTube.playerCinemaModeButton = function () { player.style.zIndex = 1; svg.parentNode.style.opacity = 0.64; svg.parentNode.style.zIndex = 1; - } - else { + } else { player.style.zIndex = 10000; svg.parentNode.style.opacity = 1; } @@ -936,55 +935,56 @@ ImprovedTube.playerCinemaModeEnable = function () { /*------------------------------------------------------------------------------ HAMBURGER MENU ------------------------------------------------------------------------------*/ -ImprovedTube.playerHamburgerButton = function () { if (this.storage.player_hamburger_button === true) { - const videoPlayer = document.querySelector('.html5-video-player'); - - if (!videoPlayer) { - return; - } +ImprovedTube.playerHamburgerButton = function () { + if (this.storage.player_hamburger_button === true) { + const videoPlayer = document.querySelector('.html5-video-player'); - const controlsContainer = videoPlayer.querySelector('.ytp-right-controls'); + if (!videoPlayer) { + return; + } - if (!controlsContainer) { - return; - } + const controlsContainer = videoPlayer.querySelector('.ytp-right-controls'); - let hamburgerMenu = document.querySelector('.custom-hamburger-menu'); - if (!hamburgerMenu) { - hamburgerMenu = document.createElement('div'); - hamburgerMenu.className = 'custom-hamburger-menu'; - hamburgerMenu.style.position = 'absolute'; - hamburgerMenu.style.right = '0'; - hamburgerMenu.style.marginTop = '8px'; - hamburgerMenu.style.cursor = 'pointer'; + if (!controlsContainer) { + return; + } - const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); - svg.setAttributeNS(null, 'viewBox', '0 0 24 24'); - svg.setAttribute('style', 'width: 32px; height: 32px;'); + let hamburgerMenu = document.querySelector('.custom-hamburger-menu'); + if (!hamburgerMenu) { + hamburgerMenu = document.createElement('div'); + hamburgerMenu.className = 'custom-hamburger-menu'; + hamburgerMenu.style.position = 'absolute'; + hamburgerMenu.style.right = '0'; + hamburgerMenu.style.marginTop = '8px'; + hamburgerMenu.style.cursor = 'pointer'; - const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); - path.setAttributeNS(null, 'd', 'M3 18h18v-2H3v2zM3 13h18v-2H3v2zM3 6v2h18V6H3z'); - path.setAttributeNS(null, 'fill', 'white'); + const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + svg.setAttributeNS(null, 'viewBox', '0 0 24 24'); + svg.setAttribute('style', 'width: 32px; height: 32px;'); - svg.appendChild(path); - hamburgerMenu.appendChild(svg); + const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); + path.setAttributeNS(null, 'd', 'M3 18h18v-2H3v2zM3 13h18v-2H3v2zM3 6v2h18V6H3z'); + path.setAttributeNS(null, 'fill', 'white'); - controlsContainer.style.paddingRight = '40px'; - controlsContainer.parentNode.appendChild(hamburgerMenu); + svg.appendChild(path); + hamburgerMenu.appendChild(svg); - let controlsVisible = true; - controlsContainer.style.display = controlsVisible ? 'none' : 'flex'; - controlsVisible = false; + controlsContainer.style.paddingRight = '40px'; + controlsContainer.parentNode.appendChild(hamburgerMenu); - hamburgerMenu.addEventListener('click', function () { + let controlsVisible = true; controlsContainer.style.display = controlsVisible ? 'none' : 'flex'; - controlsVisible = !controlsVisible; + controlsVisible = false; - // Change the opacity of hamburgerMenu based on controls visibility - hamburgerMenu.style.opacity = controlsVisible ? '0.85' : '0.65'; - }); + hamburgerMenu.addEventListener('click', function () { + controlsContainer.style.display = controlsVisible ? 'none' : 'flex'; + controlsVisible = !controlsVisible; + + // Change the opacity of hamburgerMenu based on controls visibility + hamburgerMenu.style.opacity = controlsVisible ? '0.85' : '0.65'; + }); + } } -} }; /*------------------------------------------------------------------------------ POPUP PLAYER @@ -1437,61 +1437,62 @@ ImprovedTube.miniPlayer = function () { /*------------------------------------------------------------------------------ CUSTOM PAUSE FUNCTIONS ------------------------------------------------------------------------------*/ -ImprovedTube.pauseWhileTypingOnYoutube = function () { if (ImprovedTube.storage.pause_while_typing_on_youtube === true) { - var timeoutId; // Declare a variable to hold the timeout ID +ImprovedTube.pauseWhileTypingOnYoutube = function () { + if (ImprovedTube.storage.pause_while_typing_on_youtube === true) { + var timeoutId; // Declare a variable to hold the timeout ID - // Add event listener to the whole document - document.addEventListener('keydown', function (e) { + // Add event listener to the whole document + document.addEventListener('keydown', function (e) { // Check on the storage for pause_while_typing_on_youtube_storage is false - // If player is NOT in the viewport, return - if (!isPlayerInViewport()) { - return; - } + // If player is NOT in the viewport, return + if (!isPlayerInViewport()) { + return; + } - var player = ImprovedTube.elements.player; + var player = ImprovedTube.elements.player; - if (player) { - if ( - (/^[a-z0-9]$/i.test(e.key) || e.key === "Backspace") && + if (player) { + if ( + (/^[a-z0-9]$/i.test(e.key) || e.key === "Backspace") && !(e.ctrlKey && (e.key === "c" || e.key === "x" || e.key === "a")) && - ( document.activeElement.tagName === "INPUT" || document.activeElement.tagName === "TEXTAREA" || document.activeElement.tagName === "DIV" )) - { + ( document.activeElement.tagName === "INPUT" || document.activeElement.tagName === "TEXTAREA" || document.activeElement.tagName === "DIV" )) { // Pause the video // Check if player is paused - if (!player.paused) { - player.pauseVideo(); - } + if (!player.paused) { + player.pauseVideo(); + } - // Clear any existing timeout - if (timeoutId) { - clearTimeout(timeoutId); - } + // Clear any existing timeout + if (timeoutId) { + clearTimeout(timeoutId); + } - // Set a new timeout to play the video after 1 second - timeoutId = setTimeout(function () { - player.playVideo(); - }, 2000); // 2000 milliseconds = 2 seconds + // Set a new timeout to play the video after 1 second + timeoutId = setTimeout(function () { + player.playVideo(); + }, 2000); // 2000 milliseconds = 2 seconds + } } - } - }); + }); - function isPlayerInViewport () { - var player = ImprovedTube.elements.player; - if (player) { - var rect = player.getBoundingClientRect(); - var windowHeight = (window.innerHeight || document.documentElement.clientHeight); - var windowWidth = (window.innerWidth || document.documentElement.clientWidth); + function isPlayerInViewport () { + var player = ImprovedTube.elements.player; + if (player) { + var rect = player.getBoundingClientRect(); + var windowHeight = (window.innerHeight || document.documentElement.clientHeight); + var windowWidth = (window.innerWidth || document.documentElement.clientWidth); - // Check if the player is in the viewport - return ( - rect.top != 0 && + // Check if the player is in the viewport + return ( + rect.top != 0 && rect.left != 0 && rect.bottom <= windowHeight && rect.right <= windowWidth - ); + ); + } + return false; } - return false; - } -}}; + } +}; \ No newline at end of file diff --git a/js&css/web-accessible/www.youtube.com/playlist.js b/js&css/web-accessible/www.youtube.com/playlist.js index 3f08d54c4..79628849f 100644 --- a/js&css/web-accessible/www.youtube.com/playlist.js +++ b/js&css/web-accessible/www.youtube.com/playlist.js @@ -10,9 +10,9 @@ ImprovedTube.playlistUpNextAutoplay = function () { if (this.storage.playlist_up && playlistData.currentIndex && playlistData.totalVideos && playlistData.localCurrentIndex) { - playlistData.currentIndex = playlistData.totalVideos; + playlistData.currentIndex = playlistData.totalVideos; + } } -} }; /*------------------------------------------------------------------------------ 4.5.2 REVERSE @@ -183,11 +183,12 @@ ImprovedTube.playlistPopupCreateButton = function (playlistID, altButtonStyle, c } : function () { let width = ImprovedTube.elements.player.offsetWidth * 0.7 ?? innerWidth * 0.45; let height = ImprovedTube.elements.player.offsetHeight * 0.7 ?? innerHeight * 0.45; - if (!ImprovedTube.elements.player) { - shorts = /short/.test(this.parentElement.href); - if ( width / height < 1 ) { vertical = true } else { vertical = false } - if ( !vertical && shorts ) { width = height * 0.6} - if ( vertical && !shorts ) { height = width * 0.6} } + if (!ImprovedTube.elements.player) { + shorts = /short/.test(this.parentElement.href); + if ( width / height < 1 ) { vertical = true } else { vertical = false } + if ( !vertical && shorts ) { width = height * 0.6} + if ( vertical && !shorts ) { height = width * 0.6} + } "use strict"; window.open(`${location.protocol}//www.youtube.com/embed/videoseries?autoplay=${ImprovedTube.storage.player_autoplay_disable ? '0' : '1'}&list=${this.dataset.list}`, '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${width / 3},height=${height / 3}`); //~ change focused tab to URL-less popup @@ -245,4 +246,5 @@ ImprovedTube.playlistPopup = function () { else panelItemButtons.appendChild(this.elements.buttons['it-popup-playlist-button-panel'] = this.playlistPopupCreateButton(playlistID, true, true)); } else if (playlistID != null && this.elements.buttons['it-popup-playlist-button-panel'].dataset.list !== playlistID) this.elements.buttons['it-popup-playlist-button-panel'].dataset.list = playlistID; } catch (error) { console.error("Error appending playlist button panel:", error);} - }}; + } +}; diff --git a/js&css/web-accessible/www.youtube.com/settings.js b/js&css/web-accessible/www.youtube.com/settings.js index 20bd387dd..7771cfb3e 100644 --- a/js&css/web-accessible/www.youtube.com/settings.js +++ b/js&css/web-accessible/www.youtube.com/settings.js @@ -113,8 +113,7 @@ ImprovedTube.improvedtubeYoutubeIcon = function () { if (option === 'header_left') { if (this.storage.header_position === 'normal' && this.elements.masthead.start) { this.elements.masthead.start.appendChild(button); - } - else if (this.elements.app_drawer.start) { + } else if (this.elements.app_drawer.start) { this.elements.app_drawer.start.appendChild(button); } } else if (option === 'header_right') { diff --git a/menu/index.js b/menu/index.js index 00617bcfb..24238322a 100644 --- a/menu/index.js +++ b/menu/index.js @@ -7,7 +7,7 @@ --------------------------------------------------------------*/ satus.storage.import(function (items) { var language = items.language; - if (!language || language === 'default') { language = false;} + if (!language || language === 'default') { language = false;} satus.locale.import(language, function () { satus.render(extension.skeleton); diff --git a/menu/satus.js b/menu/satus.js index 556c651db..1295a22b9 100644 --- a/menu/satus.js +++ b/menu/satus.js @@ -252,10 +252,10 @@ satus.isNumber = function (t) { return (typeof t ==='number' && !isNaN(t)); }; satus.isObject = function (t) { return (t instanceof Object && t !== null); }; satus.isElement = function (t) { return (t instanceof Element || t instanceof HTMLDocument); }; satus.isNodeList = function (t) { return t instanceof NodeList; }; -satus.isBoolean = function (t) { return (t === false || t === true); }; +satus.isBoolean = function (t) { return (t === false || t === true); }; /*---LOG------------------------------------------------------*/ -satus.log = function () { console.log.apply(null, arguments);}; +satus.log = function () { console.log.apply(null, arguments);}; /*-------------------------------------------------------------- @@ -1050,27 +1050,29 @@ satus.locale.import = function (code, callback, path) { importLocale(language, () => importLocale('en', callback)); } } else { // try chrome://settings/languages: - try {chrome.i18n.getAcceptLanguages(function (languages) { - languages = languages.map(language => language.replace('-', '_')); - for (let i = languages.length - 1; i >= 0; i--) { - if (languages[i].includes('_')) { - let languageWithoutCountryCode = languages[i].substring(0, 2); - - if (!languages.includes(languageWithoutCountryCode)) { - languages.splice(i + 1, 0, languageWithoutCountryCode); + try { + chrome.i18n.getAcceptLanguages(function (languages) { + languages = languages.map(language => language.replace('-', '_')); + for (let i = languages.length - 1; i >= 0; i--) { + if (languages[i].includes('_')) { + let languageWithoutCountryCode = languages[i].substring(0, 2); + + if (!languages.includes(languageWithoutCountryCode)) { + languages.splice(i + 1, 0, languageWithoutCountryCode); + } } } - } - languages.includes("en") || languages.push("en"); + languages.includes("en") || languages.push("en"); - languages.forEach((language, index) => index === languages.length - 1 ? importLocale(language, callback) : importLocale(language, () => {})); + languages.forEach((language, index) => index === languages.length - 1 ? importLocale(language, callback) : importLocale(language, () => {})); /* equals: languages.length === 1 && importLocale(languages[0], callback); languages.length === 2 && importLocale(languages[0], () => importLocale(languages[1], callback)); languages.length === 3 && importLocale(languages[0], () => importLocale(languages[1], () => importLocale(languages[2], callback))); ... */ // console.log(languages); - });} catch (error) { + }); + } catch (error) { // Finally, if code nor chrome://settings/languages are available, use window.navigator.language: let language = window.navigator.language.replace('-', '_'); diff --git a/menu/skeleton-parts/appearance.js b/menu/skeleton-parts/appearance.js index 9711cbef8..b3da19d60 100644 --- a/menu/skeleton-parts/appearance.js +++ b/menu/skeleton-parts/appearance.js @@ -838,10 +838,11 @@ extension.skeleton.main.layers.section.appearance.on.click.sidebar = { click: function () { setTimeout(() => { if (satus.storage.get('related_videos')==="Titles" - && satus.storage.get("relatedVideosPrev") ==="Titles") {if (!satus.storage.get('thumbnails_right')) { - this.nextSibling.nextSibling.click(); - satus.storage.set('relatedVideosPrev', "notTitles") - } + && satus.storage.get("relatedVideosPrev") ==="Titles") { + if (!satus.storage.get('thumbnails_right')) { + this.nextSibling.nextSibling.click(); + satus.storage.set('relatedVideosPrev', "notTitles") + } } }, 650) @@ -866,13 +867,15 @@ extension.skeleton.main.layers.section.appearance.on.click.sidebar = { value: false, id: 'transcript', on: { - click: function () { setTimeout(() => { - if (satus.storage.get('transcript')) { - if (satus.storage.get('no_page_margin')) { - this.nextSibling.nextSibling.click(); + click: function () { + setTimeout(() => { + if (satus.storage.get('transcript')) { + if (satus.storage.get('no_page_margin')) { + this.nextSibling.nextSibling.click(); + } } - } - }, 250); } + }, 250); + } } }, compact_spacing: { @@ -886,13 +889,15 @@ extension.skeleton.main.layers.section.appearance.on.click.sidebar = { value: false, on: { - click: function () { setTimeout(() => { - if (satus.storage.get('no_page_margin')) { - if (satus.storage.get('transcript')) { - this.previousSibling.previousSibling.click(); + click: function () { + setTimeout(() => { + if (satus.storage.get('no_page_margin')) { + if (satus.storage.get('transcript')) { + this.previousSibling.previousSibling.click(); + } } - } - }, 250); } + }, 250); + } } }, chapters: { diff --git a/menu/skeleton-parts/general.js b/menu/skeleton-parts/general.js index 4fdf67374..a12841953 100644 --- a/menu/skeleton-parts/general.js +++ b/menu/skeleton-parts/general.js @@ -229,13 +229,15 @@ extension.skeleton.main.layers.section.general = { component: 'switch', text: 'markWatchedVideos', on: { - click: function () { setTimeout(() => { - if (satus.storage.get('mark_watched_videos')) { - if (!satus.storage.get('track_watched_videos')) { - this.nextSibling.click(); + click: function () { + setTimeout(() => { + if (satus.storage.get('mark_watched_videos')) { + if (!satus.storage.get('track_watched_videos')) { + this.nextSibling.click(); + } } - } - }, 250); } + }, 250); + } } }, track_watched_videos: {