Skip to content

Commit

Permalink
Use vscode format (can make code ugly)
Browse files Browse the repository at this point in the history
  • Loading branch information
4yman-0 committed Nov 3, 2024
1 parent df9b610 commit 1f0e708
Show file tree
Hide file tree
Showing 18 changed files with 601 additions and 532 deletions.
8 changes: 4 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/* Sidepanel Option
chrome.storage.local.get('improvedTubeSidePanel', function (result) {
if ( result.improvedTubeSidePanel && result.improvedTubeSidePanel ) {
if (result.improvedTubeSidePanel) {
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true })
} else {chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false }) }
});
Expand All @@ -28,16 +28,16 @@
-----------------------------*/
chrome.runtime.onInstalled.addListener(function (installed) {
if (installed.reason == 'update') {
// var thisVersion = chrome.runtime.getManifest().version;
// console.log("Updated from " + installed.previousVersion + " to " + thisVersion + "!");
//var thisVersion = chrome.runtime.getManifest().version;
//console.log("Updated from " + installed.previousVersion + " to " + thisVersion + "!");
chrome.storage.local.get('description', function (result) {
if (result.description === 'classic_expanded') {
chrome.storage.local.set({description: 'expanded'});
}
});

Check warning on line 37 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Trailing spaces not allowed
// Shortcut renames:
chrome.storage.local.get(['shortcut_auto', 'shortcut_144p', 'shortcut_240p', 'shortcut_360p', 'shortcut_480p', 'shortcut_720p', 'shortcut_1080p', 'shortcut_1440p', 'shortcut_2160p', 'shortcut_2880p', 'shortcut_4320p'], function (result) {
// validate and move to new name
// Validate and move to new name
for (let [name, keys] of Object.entries(result)) {
if (!keys) continue;
let newKeys = {},
Expand Down
8 changes: 4 additions & 4 deletions js&css/extension/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ extension.events.on = function (type, listener, options = {}) {
listeners[type] = [];
}

if (options.async ) {
if (options.async) {
listener = (function (original) {
return async function () {
return new Promise(original);
};
})(listener);
}

if (options.prepend ) {
if (options.prepend) {
listeners[type].unshift(listener);
} else {
listeners[type].push(listener);
Expand All @@ -100,7 +100,7 @@ extension.events.trigger = async function (type, data) {
var listener = listeners[i];

if (typeof listener === 'function') {
if (listener instanceof(async function () {}).constructor ) {
if (listener instanceof (async function () { }).constructor) {
await listener(data);
} else {
listener(data);
Expand Down Expand Up @@ -298,7 +298,7 @@ extension.storage.load = function (callback) {
// initialize theme in case YT is in Dark cookie mode
if (!extension.storage.data['theme'] && document.documentElement.hasAttribute('dark')) {
extension.storage.data['theme'] = 'dark';
chrome.storage.local.set({theme: 'dark'});
chrome.storage.local.set({ theme: 'dark' });
}

for (const key in items) {
Expand Down
2 changes: 1 addition & 1 deletion js&css/extension/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +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); }
};
24 changes: 12 additions & 12 deletions js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension.events.on('init', function (resolve) {
async: true
});

function bodyReady () {
function bodyReady() {

Check warning on line 27 in js&css/extension/init.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Missing space before function parentheses
if (extension.ready && extension.domReady) {
extension.features.addScrollToTop();
extension.features.font();
Expand Down Expand Up @@ -141,23 +141,23 @@ document.addEventListener('it-message-from-youtube', function () {

//console.log(message);

if (message.requestOptionsUrl ) {
if (message.requestOptionsUrl) {
extension.messages.send({
responseOptionsUrl: chrome.runtime.getURL('menu/index.html')
});
} else if (message.onlyOnePlayer ) {
} else if (message.onlyOnePlayer) {
chrome.runtime.sendMessage({
name: 'only-one-player'
});
} else if (message.action === 'fixPopup') {
chrome.runtime.sendMessage({
action: 'fixPopup',
width: message.width,
height: message.height,
height: message.height,
title: message.title,
});
} else if (message.action === 'analyzer') {
if (extension.storage.data.analyzer_activation ) {
if (extension.storage.data.analyzer_activation) {
var data = message.name,
date = new Date().toDateString(),
hours = new Date().getHours() + ':00';
Expand Down Expand Up @@ -186,7 +186,7 @@ document.addEventListener('it-message-from-youtube', function () {
}
} else if (message.action === 'blocklist') {
if (!extension.storage.data.blocklist || typeof extension.storage.data.blocklist !== 'object') {
extension.storage.data.blocklist = {videos: {}, channels: {}};
extension.storage.data.blocklist = { videos: {}, channels: {} };
}

switch (message.type) {
Expand Down Expand Up @@ -243,7 +243,7 @@ document.addEventListener('it-message-from-youtube', function () {
});
} else if (message.action === 'set') {
if (message.value) {
chrome.storage.local.set({[message.key]: message.value});
chrome.storage.local.set({ [message.key]: message.value });
} else {
chrome.storage.local.remove([message.key]);
}
Expand All @@ -252,17 +252,17 @@ document.addEventListener('it-message-from-youtube', function () {
});

document.addEventListener('it-play', function () {
// var videos = document.querySelectorAll('video');
// var videos = document.querySelectorAll('video');
try {
chrome.runtime.sendMessage({action: 'play'})
chrome.runtime.sendMessage({ action: 'play' })
} catch (error) {
console.log(error);
setTimeout(function () {
try {
chrome.runtime.sendMessage({action: 'play'}, function (response) {
chrome.runtime.sendMessage({ action: 'play' }, function (response) {
console.log(response)
} );
} catch {}
});
} catch { }
}, 321);
}
});
6 changes: 3 additions & 3 deletions js&css/extension/www.youtube.com/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ extension.features.popupWindowButtons = function (event) {
if (!ytPlayer) {
let shorts = /short/.test(this.parentElement.href);
let vertical = false;
if ( width / height < 1 ) { vertical = true }
if ( !vertical && shorts ) { width = height * 0.6}
if ( vertical && !shorts ) { height = width * 0.6}
if (width / height < 1) { vertical = true }
if (!vertical && shorts) { width = height * 0.6}
if (vertical && !shorts) { height = width * 0.6}
}

window.open('https://www.youtube.com/embed/' + this.dataset.id + '?autoplay=' + (extension.storage.get('player_autoplay_disable') ? '0' : '1'), '_blank', `directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no,scrollbars=no,resizable=no,width=${width / 3},height=${height / 3}`);
Expand Down
54 changes: 28 additions & 26 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ CODEC || 30FPS
file to patch HTMLMediaElement before YT player uses it.
--------------------------------------------------------------*/
if (localStorage['it-codec'] || localStorage['it-player30fps']) {
function overwrite (self, callback, mime) {
function overwrite(self, callback, mime) {

Check warning on line 103 in js&css/web-accessible/core.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Missing space before function parentheses
if (localStorage['it-codec']) {
var re = new RegExp(localStorage['it-codec']);
// /webm|vp8|vp9|av01/
Expand Down Expand Up @@ -184,9 +184,10 @@ document.addEventListener('it-message-from-extension', function () {
ImprovedTube.storage = message.storage;

if (ImprovedTube.storage.block_vp9 || ImprovedTube.storage.block_av1 || ImprovedTube.storage.block_h264) {
let atlas = {block_vp9:'vp9|vp09', block_h264:'avc1', block_av1:'av01'},
let atlas = { block_vp9: 'vp9|vp09', block_h264: 'avc1', block_av1: 'av01' },
codec = Object.keys(atlas).reduce(function (all, key) {
return ImprovedTube.storage[key] ? ((all?all+'|':'') + atlas[key]) : all}, '');
return ImprovedTube.storage[key] ? ((all ? all + '|' : '') + atlas[key]) : all
}, '');
if (localStorage['it-codec'] != codec) {
localStorage['it-codec'] = codec;
}
Expand All @@ -204,20 +205,21 @@ document.addEventListener('it-message-from-extension', function () {
ImprovedTube.init();
ImprovedTube.blocklistInit();

// REACTION OR VISUAL FEEDBACK WHEN THE USER CHANGES A SETTING (already automated for our CSS features):
// REACTION OR VISUAL FEEDBACK WHEN THE USER CHANGES A SETTING (already automated for our CSS features):
} else if (message.action === 'storage-changed') {
let camelized_key = message.camelizedKey;

ImprovedTube.storage[message.key] = message.value;
if (['block_vp9', 'block_h264', 'block_av1'].includes(message.key)) {
let atlas = {block_vp9:'vp9|vp09', block_h264:'avc1', block_av1:'av01'}
let atlas = { block_vp9: 'vp9|vp09', block_h264: 'avc1', block_av1: 'av01' }
localStorage['it-codec'] = Object.keys(atlas).reduce(function (all, key) {
return ImprovedTube.storage[key] ? ((all?all+'|':'') + atlas[key]) : all}, '');
return ImprovedTube.storage[key] ? ((all ? all + '|' : '') + atlas[key]) : all
}, '');
if (!localStorage['it-codec']) {
localStorage.removeItem('it-codec');
}
}
if (message.key==="player_60fps") {
if (message.key === "player_60fps") {
if (ImprovedTube.storage.player_60fps === false) {
localStorage['it-player30fps'] = true;
} else {
Expand All @@ -234,7 +236,7 @@ document.addEventListener('it-message-from-extension', function () {
case 'playerPlaybackSpeed':
case 'playerForcedPlaybackSpeed':
if (ImprovedTube.storage.player_forced_playback_speed && isFinite(Number(ImprovedTube.storage.player_playback_speed))) {
ImprovedTube.playbackSpeed (Number(ImprovedTube.storage.player_playback_speed)); //new
ImprovedTube.playbackSpeed(Number(ImprovedTube.storage.player_playback_speed)); //new
ImprovedTube.elements.player.setPlaybackRate(Number(ImprovedTube.storage.player_playback_speed));
// ImprovedTube.elements.player.querySelector('video').playbackRate = Number(ImprovedTube.storage.player_playback_speed.toFixed(2));
} else if (ImprovedTube.storage.player_forced_playback_speed === false) {
Expand All @@ -252,22 +254,22 @@ document.addEventListener('it-message-from-extension', function () {

case 'description':
if (ImprovedTube.storage.description === "expanded") {
try {document.querySelector("#more").click() || document.querySelector("#expand").click();} catch {}
try { document.querySelector("#more").click() || document.querySelector("#expand").click(); } catch { }
} else if (ImprovedTube.storage.description === "normal") {
try {document.querySelector("#less").click() || document.querySelector("#collapse").click();} catch {}
try { document.querySelector("#less").click() || document.querySelector("#collapse").click(); } catch { }
}
break

case 'transcript':
if (ImprovedTube.storage.transcript ) {
if (ImprovedTube.storage.transcript) {
document.querySelector('*[target-id*=transcript]')?.removeAttribute('visibility');
} else if (!ImprovedTube.storage.transcript) {
document.querySelector('*[target-id*=transcript] #visibility-button button')?.click();
}
break

case 'chapters':
if (ImprovedTube.storage.chapters ) {
if (ImprovedTube.storage.chapters) {
document.querySelector('*[target-id*=chapters]')?.removeAttribute('visibility');
} else if (!ImprovedTube.storage.chapters) {
document.querySelector('*[target-id*=chapters] #visibility-button button')?.click();
Expand All @@ -286,9 +288,9 @@ document.addEventListener('it-message-from-extension', function () {
case 'forcedTheaterMode':
if (ImprovedTube.storage.forced_theater_mode === false && ImprovedTube.elements.ytd_watch && ImprovedTube.elements.player) {
const button = ImprovedTube.elements.player.querySelector("button.ytp-size-button");
if (button && ImprovedTube.elements.ytd_watch.theater ) {
if (button && ImprovedTube.elements.ytd_watch.theater) {
ImprovedTube.elements.ytd_watch.theater = false;
setTimeout(function () { button.click();}, 100);
setTimeout(function () { button.click(); }, 100);
}
}
break
Expand Down Expand Up @@ -345,7 +347,7 @@ document.addEventListener('it-message-from-extension', function () {
case 'belowPlayerPip':
if (ImprovedTube.storage.below_player_pip === false) {
document.querySelector('.improvedtube-player-button[data-tooltip="PiP"]')?.remove();
} else if (ImprovedTube.storage.below_player_pip ) {
} else if (ImprovedTube.storage.below_player_pip) {
document.querySelectorAll('.improvedtube-player-button').forEach(e => e.remove());
ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer();
}
Expand All @@ -354,7 +356,7 @@ document.addEventListener('it-message-from-extension', function () {
case 'belowPlayerScreenshot':
if (ImprovedTube.storage.below_player_screenshot === false) {
document.querySelector('.improvedtube-player-button[data-tooltip="Screenshot"]')?.remove();
} else if (ImprovedTube.storage.below_player_screenshot ) {
} else if (ImprovedTube.storage.below_player_screenshot) {
document.querySelectorAll('.improvedtube-player-button').forEach(e => e.remove());
ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer();
}
Expand All @@ -363,7 +365,7 @@ document.addEventListener('it-message-from-extension', function () {
case 'belowPlayerLoop':
if (ImprovedTube.storage.below_player_loop === false) {
document.querySelector('.improvedtube-player-button[data-tooltip="Loop"]')?.remove();
} else if (ImprovedTube.storage.below_player_loop ) {
} else if (ImprovedTube.storage.below_player_loop) {
document.querySelectorAll('.improvedtube-player-button').forEach(e => e.remove());
ImprovedTube.improvedtubeYoutubeButtonsUnderPlayer();
}
Expand All @@ -372,15 +374,15 @@ document.addEventListener('it-message-from-extension', function () {
case 'dayOfWeek':
if (ImprovedTube.storage.day_of_week === false) {
document.querySelector(".ytd-day-of-week")?.remove();
} else if (ImprovedTube.storage.day_of_week ) {
} else if (ImprovedTube.storage.day_of_week) {
ImprovedTube.dayOfWeek();
}
break

case 'playerRemainingDuration':
if (ImprovedTube.storage.player_remaining_duration === false) {
document.querySelector(".ytp-time-remaining-duration")?.remove();
} else if (ImprovedTube.storage.player_remaining_duration ) {
} else if (ImprovedTube.storage.player_remaining_duration) {
ImprovedTube.playerRemainingDuration();
}
break
Expand All @@ -401,8 +403,8 @@ document.addEventListener('it-message-from-extension', function () {
ImprovedTube.playerControls();
break
case 'playerlistUpNextAutoplay':
if (this.storage.playlist_up_next_autoplay ) {
if (playlistData.currentIndex != playlistData.localCurrentIndex) { playlistData.currentIndex = playlistData.localCurrentIndex;}
if (this.storage.playlist_up_next_autoplay) {
if (playlistData.currentIndex != playlistData.localCurrentIndex) { playlistData.currentIndex = playlistData.localCurrentIndex; }
}
break
}
Expand All @@ -411,19 +413,19 @@ document.addEventListener('it-message-from-extension', function () {
if (message.key.startsWith('shortcut_')) camelized_key = 'shortcuts';

if (ImprovedTube[camelized_key]) {
try {ImprovedTube[camelized_key]()} catch {};
try { ImprovedTube[camelized_key]() } catch { };
}
} else if (message.focus && ImprovedTube.elements.player) {
} else if (message.focus && ImprovedTube.elements.player) {
ImprovedTube.focus = true;

ImprovedTube.pageOnFocus();
} else if (message.blur && ImprovedTube.elements.player) {
} else if (message.blur && ImprovedTube.elements.player) {
ImprovedTube.focus = false;

ImprovedTube.pageOnFocus();

document.dispatchEvent(new CustomEvent('improvedtube-blur'));
} else if (message.pause ) {
} else if (message.pause) {
if (ImprovedTube.elements.player) {
ImprovedTube.played_before_blur = ImprovedTube.elements.player.getPlayerState() === 1;
ImprovedTube.elements.player.pauseVideo();
Expand All @@ -432,7 +434,7 @@ document.addEventListener('it-message-from-extension', function () {
ImprovedTube.elements.player?.setVolume(message.setVolume);
} else if (message.setPlaybackSpeed) {
ImprovedTube.playbackSpeed(message.setPlaybackSpeed);
} else if (message.deleteCookies ) {
} else if (message.deleteCookies) {
ImprovedTube.deleteYoutubeCookies();
} else if (message.responseOptionsUrl) {
const iframe = document.querySelector('.it-button__iframe');
Expand Down
Loading

0 comments on commit 1f0e708

Please sign in to comment.