Skip to content

Commit

Permalink
keep'm one-liners
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Jul 7, 2024
1 parent 0143f8e commit be504b7
Show file tree
Hide file tree
Showing 19 changed files with 469 additions and 807 deletions.
17 changes: 5 additions & 12 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@ chrome.runtime.onInstalled.addListener(function (installed) {
});
} else if (installed.reason == 'install') {
if (navigator.userAgent.indexOf("Firefox") != -1) {
chrome.storage.local.set({below_player_pip: false})
}
chrome.storage.local.set({below_player_pip: false})}

Check failure on line 98 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
if (navigator.userAgent.indexOf('Safari') !== -1
&& (!/Windows|Chrom/.test(navigator.userAgent)
|| /Macintosh|iPhone/.test(navigator.userAgent))) {
chrome.storage.local.set({below_player_pip: false})
// still needed? (are screenshots broken in Safari?):
chrome.storage.local.set({below_player_screenshot: false})
}
chrome.storage.local.set({below_player_screenshot: false})}

Check failure on line 104 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
// console.log('Thanks for installing!');
}
});
Expand Down Expand Up @@ -282,18 +280,14 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
top: 20
}

if (tID) {
data.tabId = tID;
}
if (tID) {data.tabId = tID;}
chrome.windows.create(data);

//append to title?
chrome.tabs.onUpdated.addListener(function listener (tabId, changeInfo) {
if (tabId === tID && changeInfo.status === 'complete' && !message.title.startsWith("undefined")) {
chrome.tabs.onUpdated.removeListener(listener);
chrome.scripting.executeScript({ target: { tabId: tID }, func: () => {
document.title = `${message.title} - ImprovedTube`;
} }); //manifest3
chrome.scripting.executeScript({ target: { tabId: tID }, func: () => { document.title = `${message.title} - ImprovedTube`; } }); //manifest3
// chrome.tabs.executeScript(tID, {code: `document.title = "${message.title} - ImprovedTube";`}); //manifest2
}
});
Expand All @@ -320,8 +314,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
}
} else {
console.error('Permission is not granted.');
}
})
}})

Check failure on line 317 in background.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
break
}
});
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions js&css/extension/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@
--------------------------------------------------------------*/
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);}};

Check failure on line 8 in js&css/extension/functions.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
13 changes: 2 additions & 11 deletions js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,6 @@ document.addEventListener('it-message-from-youtube', function () {

document.addEventListener('it-play', function (event) {

Check failure on line 244 in js&css/extension/init.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'event' is defined but never used
var videos = document.querySelectorAll('video');

Check failure on line 245 in js&css/extension/init.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'videos' is assigned a value but never used
try {
chrome.runtime.sendMessage({action: 'play'})
} catch (error) {
console.log(error); setTimeout(function () {
try {
chrome.runtime.sendMessage({action: 'play'}, function (response) {
console.log(response)
} );
} catch { }
}, 321)
}
try {chrome.runtime.sendMessage({action: 'play'})}

Check failure on line 246 in js&css/extension/init.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Closing curly brace does not appear on the same line as the subsequent block
catch (error) {console.log(error); setTimeout(function () { try { chrome.runtime.sendMessage({action: 'play'}, function (response) { console.log(response) } ); } catch { } }, 321) }
});
37 changes: 9 additions & 28 deletions js&css/extension/www.youtube.com/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ extension.features.addScrollToTop = function (event) {
path.setAttribute('d', 'M13 19V7.8l4.9 5c.4.3 1 .3 1.4 0 .4-.5.4-1.1 0-1.5l-6.6-6.6a1 1 0 0 0-1.4 0l-6.6 6.6a1 1 0 1 0 1.4 1.4L11 7.8V19c0 .6.5 1 1 1s1-.5 1-1z');
svg.appendChild(path);
this.addScrollToTop.button.appendChild(svg);
window.addEventListener('scroll', function () {
document.body.appendChild(extension.features.addScrollToTop.button);
});
window.addEventListener('scroll', function () { document.body.appendChild(extension.features.addScrollToTop.button); });
this.addScrollToTop.button.addEventListener('click', function () {
window.scrollTo(0, 0);
document.getElementById('it-scroll-to-top')?.remove();
Expand Down Expand Up @@ -251,30 +249,15 @@ extension.features.popupWindowButtons = function (event) {
target.itPopupWindowButton.addEventListener('click', function (event) {
event.preventDefault();
event.stopPropagation();
try {
this.parentElement.itPopupWindowButton.dataset.id = this.parentElement.href.match(/(?:[?&]v=|embed\/|shorts\/)([^&?]{11})/)[1]
} catch (error) {
console.log(error)
};
try { this.parentElement.itPopupWindowButton.dataset.id = this.parentElement.href.match(/(?:[?&]v=|embed\/|shorts\/)([^&?]{11})/)[1] } catch (error) { console.log(error)};
ytPlayer = document.querySelector("#movie_player");
if (ytPlayer) {
width = ytPlayer.offsetWidth * 0.65; height = ytPlayer.offsetHeight * 0.65
} else {
width = innerWidth * 0.4; height = innerHeight * 0.4;
}
if (ytPlayer) {width = ytPlayer.offsetWidth * 0.65; height = ytPlayer.offsetHeight * 0.65}
else { width = innerWidth * 0.4; height = innerHeight * 0.4; }
if (!ytPlayer) {
let shorts = /short/.test(this.parentElement.href);
if ( width / height < 1 ) {
let vertical = true
} else {
let vertical = false
}
if ( !vertical && shorts ) {
width = height * 0.6
}
if ( vertical && !shorts ) {
height = width * 0.6
}
if ( width / height < 1 ) { let vertical = true } else { let vertical = false }
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 Expand Up @@ -373,8 +356,7 @@ 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 @@ -397,8 +379,7 @@ extension.features.markWatchedVideos = function (anything) {

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

} else {
var button = target.itMarkWatchedVideosButton;
Expand Down
12 changes: 3 additions & 9 deletions js&css/extension/www.youtube.com/night-mode/night-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,10 @@ extension.features.bluelight = function () {

extension.features.dim = function () {
var value = extension.storage.get('dim');
if (extension.features.schedule() === false) {
return false;
}
if (extension.features.schedule() === false) { return false;}

if (!value) {
value = 0;
}
if (typeof value !== 'number') {
value = Number(value);
}
if (!value) { value = 0;}
if (typeof value !== 'number') {value = Number(value);}
if (value !== 0) {
if (!this.dim.element) {
var element = document.createElement('div');
Expand Down
27 changes: 7 additions & 20 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ document.addEventListener('it-message-from-extension', function () {
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'},
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 @@ -208,8 +207,7 @@ document.addEventListener('it-message-from-extension', function () {
if (['block_vp9', 'block_h264', 'block_av1'].includes(message.key)) {
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');
}
Expand Down Expand Up @@ -248,13 +246,9 @@ document.addEventListener('it-message-from-extension', function () {

case 'description':
if (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.description === "classic_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" || ImprovedTube.storage.description === "classic") {
try {
document.querySelector("#less").click() || document.querySelector("#collapse").click();
} catch {}
try {document.querySelector("#less").click() || document.querySelector("#collapse").click();} catch {}
}
break

Expand Down Expand Up @@ -288,9 +282,7 @@ document.addEventListener('it-message-from-extension', function () {
const button = ImprovedTube.elements.player.querySelector("button.ytp-size-button");
if (button && ImprovedTube.elements.ytd_watch.theater === true) {
ImprovedTube.elements.ytd_watch.theater = false;
setTimeout(function () {
button.click();
}, 100);
setTimeout(function () { button.click();}, 100);
}
}
break
Expand Down Expand Up @@ -404,20 +396,15 @@ 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
}

// dont trigger shortcuts on config change, reinitialize handler instead
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 === true && ImprovedTube.elements.player) {
ImprovedTube.focus = true;
Expand Down
Loading

0 comments on commit be504b7

Please sign in to comment.