Skip to content

Commit

Permalink
Merge pull request #2370 from raszpl/patch-8
Browse files Browse the repository at this point in the history
Update background.js dead code parse error fix, formatting
  • Loading branch information
ImprovedTube authored Jun 12, 2024
2 parents 9925487 + f75ed84 commit d014e6f
Showing 1 changed file with 42 additions and 44 deletions.
86 changes: 42 additions & 44 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@
/*
// For Manifest3:
/*-----# Persistent Serviceworker:
"Manifest2 Background.js"-----*/
"Manifest2 Background.js"-----*/
// Periodic "keep-alive" message every 29.5 seconds
// const keepAliveInterval = setInterval(() => chrome.runtime.sendMessage({ status: 'keep-alive' }), 29.5 * 1000);

/* Sidepanel Option
/* Sidepanel Option
chrome.storage.local.get('improvedTubeSidePanel', function (result) {
if ( result.improvedTubeSidePanel && result.improvedTubeSidePanel === true) {
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true })
} else {chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false }) }
if ( result.improvedTubeSidePanel && result.improvedTubeSidePanel === true) {
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true })
} else {chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false }) }
});
*/
/*---------------------------
# IMPORTING OLD SETTINGS
-----------------------------*/
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('player_autoplay', function (result) {
if (result.player_autoplay === false) {
chrome.storage.local.set({player_autoplay_disable: true});
chrome.storage.local.remove(['player_autoplay'], (i) => {});
}
});
});
chrome.storage.local.get('channel_default_tab', function (result) {
if (result.channel_default_tab === '/home') {
chrome.storage.local.set({channel_default_tab: '/'});
Expand All @@ -45,12 +45,12 @@ chrome.runtime.onInstalled.addListener(function (installed) {
if (result.player_quality === 'auto') {
chrome.storage.local.get('player_quality_auto', function (result) {
if (result.player_quality_auto !== 'migrated') {
chrome.storage.local.set({player_quality: 'disabled'});
chrome.storage.local.set({player_quality_auto: 'migrated'});
chrome.storage.local.set({player_quality: 'disabled'});
chrome.storage.local.set({player_quality_auto: 'migrated'});
}
});
});
}
});
});
chrome.storage.local.get('hideSubscribe', function (result) {
if (result.hideSubscribe === true) {
chrome.storage.local.set({subscribe: 'hidden'});
Expand All @@ -70,14 +70,14 @@ 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})}
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})}
// console.log('Thanks for installing!');
chrome.storage.local.set({below_player_pip: false})}
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})}
// console.log('Thanks for installing!');
}
});
/*--------------------------------------------------------------
Expand Down Expand Up @@ -130,7 +130,7 @@ function updateContextMenu(language) {
chrome.contextMenus.create({
id: String(i),
title: text,
contexts: ['action'] //manifest3
contexts: ['action'] //manifest3
// contexts: ['browser_action'] //manifest2
});
}
Expand Down Expand Up @@ -249,20 +249,20 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
break

case 'fixPopup':
//~ get the current focused tab and convert it to a URL-less popup (with same state and size)
//~ get the current focused tab and convert it to a URL-less popup (with same state and size)
chrome.windows.getLastFocused(w => {
chrome.tabs.query({
windowId: w.id,
active: true
}, ts => {
const tID = ts[0]?.id,
data = { type: 'popup',
state: w.state,
width: parseInt(message.width, 10),
height: parseInt(message.height, 10),
left: 0,
top: 20
}
data = { type: 'popup',
state: w.state,
width: parseInt(message.width, 10),
height: parseInt(message.height, 10),
left: 0,
top: 20
}

if (tID) {data.tabId = tID;}
chrome.windows.create(data, pw => {});
Expand All @@ -280,29 +280,27 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
break
case 'download':
chrome.permissions.request({
permissions: ['downloads'],
origins: ['https://www.youtube.com/*']
permissions: ['downloads'],
origins: ['https://www.youtube.com/*']
}, function (granted) {
if (granted) {
try {
var blob = new Blob([JSON.stringify(request.value)], {
var blob = new Blob([JSON.stringify(message.value)], {
type: 'application/json;charset=utf-8'
});
chrome.downloads.download({
url: URL.createObjectURL(blob),
filename: request.filename,
saveAs: true
});
} catch (error) {
console.error(error);
chrome.downloads.download({
url: URL.createObjectURL(blob),
filename: message.filename,
saveAs: true
});
} catch (error) {
console.error(error);
}
} else {
console.error('Permission is not granted.');
}
})
console.error('Permission is not granted.');
}})
break
}
});
/*-----# UNINSTALL URL-----------------------------------*/
chrome.runtime.setUninstallURL('https://improvedtube.com/uninstalled');


0 comments on commit d014e6f

Please sign in to comment.