Skip to content

Commit

Permalink
show github issues to users
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprovedTube committed Dec 30, 2023
1 parent 247b52a commit e4c646c
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 107 deletions.
72 changes: 35 additions & 37 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,25 @@
# Message listener
# Uninstall URL
--------------------------------------------------------------*/
/*
// For Manifest3:
/*-----# Persistent Serviceworker:
"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 */
/*
chrome.storage.local.get('improvedTubeSidebar', function (result) {
if ( result.improvedTubeSidebar) { if ( result.ImprovedTubeSidebar === 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;
Expand All @@ -29,7 +44,7 @@ chrome.storage.local.get('limit_page_width', function (result) {
}});
}
});
}
}
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){chrome.storage.local.set({below_player_pip: false})};
Expand All @@ -45,11 +60,13 @@ if(navigator.userAgent.indexOf("Safari") != -1){chrome.storage.local.set({below_
--------------------------------------------------------------*/
function getLocale(language, callback) {
language = language.replace('-', '_');

fetch('_locales/' + language + '/messages.json').then(function (response) {
if (response.ok) {
response.json().then(callback);
} else {
fetch('_locales/' + language.substring(0,2) + '/messages.json').then(function (response) {
if (response.ok) {response.json().then(callback);
} else {
fetch('_locales/' + language.substring(0,2) + '/messages.json').then(function (response) {
if (response.ok) { response.json().then(callback);
} else { getLocale('en', callback); } }).catch(function (){getLocale('en', callback);
});
getLocale('en', callback);
}
}).catch(function () {
Expand All @@ -63,14 +80,12 @@ function updateContextMenu(language) {
if (!language) {
language = chrome.i18n.getUILanguage();
}

getLocale(language, function (response) {
var items = [
'donate',
'rateMe',
'GitHub'
];

chrome.contextMenus.removeAll();

for (var i = 0; i < 3; i++) {
Expand All @@ -86,10 +101,10 @@ function updateContextMenu(language) {
chrome.contextMenus.create({
id: String(i),
title: text,
contexts: ['browser_action'] //manifest3 : 'action'
// contexts: ['action'] //manifest3
contexts: ['browser_action'] //manifest2
});
}

chrome.contextMenus.onClicked.addListener(function (info) {
var links = [
'https://www.improvedtube.com/donate',
Expand All @@ -101,28 +116,22 @@ function updateContextMenu(language) {
});
});
}

chrome.runtime.onInstalled.addListener(function (details) {
chrome.storage.local.get(function (items) {
var language = items.language;

updateContextMenu(language);
});
});

chrome.storage.onChanged.addListener(function (changes) {
for (var key in changes) {
if (key === 'language') {
updateContextMenu(changes[key].newValue);
}
if (key === 'language') {updateContextMenu(changes[key].newValue);}
if (key === 'improvedTubeSidebar') { chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: changes[key].newValue }); }
}
});


/*--------------------------------------------------------------
# TAB FOCUS/BLUR
--------------------------------------------------------------*/

chrome.tabs.onActivated.addListener(function (activeInfo) {
chrome.tabs.sendMessage(activeInfo.tabId, {
action: 'focus'
Expand All @@ -142,7 +151,6 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
}
});
});

chrome.windows.onFocusChanged.addListener(function (windowId) {
chrome.windows.getAll(function (windows) {
for (var i = 0, l = windows.length; i < l; i++) {
Expand Down Expand Up @@ -180,12 +188,9 @@ chrome.windows.onFocusChanged.addListener(function (windowId) {
}
});
});


/*--------------------------------------------------------------
# MESSAGE LISTENER
--------------------------------------------------------------*/

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
var name = request.name;

Expand Down Expand Up @@ -216,7 +221,6 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
});

let prevTabsLength = 0;

chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
var action = message.action || message;

Expand Down Expand Up @@ -252,8 +256,7 @@ try{ sendResponse({
hostname: new URL(sender.url).hostname,
tabId: sender.tab.id
}); } catch (error) { console.error("invalid url?", error);}
} else if (action === 'fixPopup')
{
} else if (action === 'fixPopup') {
//~ 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({
Expand All @@ -265,15 +268,14 @@ try{ sendResponse({
state: w.state,
width: parseInt(message.width, 10),
height: parseInt(message.height, 10),
left: -3,
top: 3
left: 0,
top: 20
};

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

//append to title

//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);
Expand All @@ -286,7 +288,6 @@ try{ sendResponse({

};
});

/*------ search results in new tab ---------
chrome.storage.local.get('open_new_tab', function (result)
{if (result.open_new_tab === true){
Expand All @@ -299,8 +300,5 @@ chrome.runtime.onMessage.addListener(function (request) {
}}); */

/*--------------------------------------------------------------
# UNINSTALL URL
--------------------------------------------------------------*/

/*-----# UNINSTALL URL-----------------------------------*/
chrome.runtime.setUninstallURL('https://improvedtube.com/uninstalled');
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name" : "ImprovedTube",
"name": "'Improve YouTube!' 🎧 (for YouTube & Videos)",
"description": "__MSG_description_ext__",
"version": "4.506",
"version": "4.580",
"default_locale": "en",
"icons": {
"16": "stuff/icons/16.png",
Expand Down Expand Up @@ -83,3 +83,4 @@
"js&css/web-accessible/mutations.js"
]
}

24 changes: 16 additions & 8 deletions manifest3.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"manifest_version": 3,
"short_name" : "ImprovedTube",
"name": "'Improve YouTube!'🎧(for YouTube & Videos)",
"name": "'Improve YouTube!' 🎧 (for YouTube & Videos)",
"description": "__MSG_description_ext__",
"version": "4.6",
"version": "4.620",
"default_locale": "en",
"icons": {
"128": "stuff/icons/128.png",
Expand All @@ -15,9 +15,16 @@
"service_worker": "background.js"
},
"action": {
"default_popup": "menu/index.html"
"default_popup": "menu/index.html",
"default_area": "navbar"
},
"side_panel": {
"default_path": "menu/index.html"
},
"options_page": "menu/index.html",
"options_ui": {
"page": "menu/index.html"
},
"content_scripts": [
{
"all_frames": true,
Expand All @@ -36,8 +43,7 @@
"https://www.youtube.com/audiolibrary/*",
"https://www.youtube.com/tv*"
],
"js": [
"js&css/satus.js",
"js": [
"js&css/extension/core.js",
"js&css/extension/functions.js",
"js&css/extension/www.youtube.com/night-mode/night-mode.js",
Expand All @@ -60,17 +66,18 @@
],
"permissions": [
"contextMenus",
"storage"
"storage",
"sidePanel"
],
"web_accessible_resources": [
{
"resources": [
"menu/index.html",
"js&css/web-accessible/core.js",
"js&css/web-accessible/functions.js",
"js&css/web-accessible/www.youtube.com/appearance.js",
"js&css/web-accessible/www.youtube.com/themes.js",
"js&css/web-accessible/www.youtube.com/appearance.js",
"js&css/web-accessible/www.youtube.com/player.js",
"js&css/web-accessible/www.youtube.com/themes.js",
"js&css/web-accessible/www.youtube.com/playlist.js",
"js&css/web-accessible/www.youtube.com/channel.js",
"js&css/web-accessible/www.youtube.com/shortcuts.js",
Expand All @@ -85,3 +92,4 @@
}
]
}

3 changes: 1 addition & 2 deletions menu/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width">
<title>ImprovedTube</title><style>body{width:320px;margin:0;height: max(600px, 100vh) }</style>
<title>ImprovedTube</title><style>body{width:320px;max-width:320px; margin:0; height:600px;max-height:600px;"}</style>
<script src="satus.js"></script>
<script src="index.js"></script>
<script src="skeleton.js"></script>
Expand Down Expand Up @@ -32,4 +32,3 @@
<link rel="stylesheet" href="styles/themes.css"></head><body></body></html>



Loading

0 comments on commit e4c646c

Please sign in to comment.