Skip to content

Commit

Permalink
redo braces & spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Jul 8, 2024
1 parent a60bb38 commit e117dca
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 141 deletions.
3 changes: 2 additions & 1 deletion js&css/extension/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
--------------------------------------------------------------*/
extension.functions.getUrlParameter = function (url, parameter) {
var match = url.match(new RegExp('(\\?|\\&)' + parameter + '=[^&]+'));
if (match) {return match[0].substr(3);}};
if (match) {return match[0].substr(3);}
};
6 changes: 4 additions & 2 deletions js&css/extension/www.youtube.com/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -379,7 +380,8 @@ extension.features.markWatchedVideos = function (anything) {

chrome.storage.local.set({
watched: extension.storage.get('watched')
});});
});
});

} else {
var button = target.itMarkWatchedVideosButton;
Expand Down
3 changes: 2 additions & 1 deletion js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
23 changes: 20 additions & 3 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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;
}
Expand All @@ -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++) {
Expand All @@ -441,6 +457,7 @@ ImprovedTube.onmousedown = function () {
}
}, true);
};
*/

ImprovedTube.getParam = function (query, name) {
var params = query.split('&'),
Expand Down
7 changes: 3 additions & 4 deletions js&css/web-accessible/www.youtube.com/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -92,8 +92,7 @@ ImprovedTube.channelCompactTheme = function () {
if (!isCompact) {
sub.style.display = "none"
isCompact = true
}
else {
} else {
sub.style.display = ""
isCompact = false
}
Expand Down
167 changes: 84 additions & 83 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 12 in js&css/web-accessible/www.youtube.com/player.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
// 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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

}};
}
};
18 changes: 10 additions & 8 deletions js&css/web-accessible/www.youtube.com/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);}
}};
}
};
3 changes: 1 addition & 2 deletions js&css/web-accessible/www.youtube.com/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading

0 comments on commit e117dca

Please sign in to comment.