Skip to content

Commit

Permalink
Migrated to manifest v3
Browse files Browse the repository at this point in the history
  • Loading branch information
adokseo committed Dec 7, 2021
1 parent 9fedd2e commit 8439778
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 138 deletions.
55 changes: 13 additions & 42 deletions content-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,12 @@ function attributes(items) {
3.0 INJECTION
------------------------------------------------------------------------------*/

function injectScript(string) {
function injectYoutubeScript() {
var script = document.createElement('script');

script.textContent = string;
script.src = chrome.runtime.getURL('youtube-scripts.js');

document.documentElement.appendChild(script);

script.remove();
}

function injectStyles(string, id) {
var style = document.createElement('style');

style.textContent = string;

if (id) {
style.id = id;
}

document.documentElement.appendChild(style);
}


Expand All @@ -70,7 +56,8 @@ function injectStyles(string, id) {

chrome.storage.onChanged.addListener(function (changes) {
for (var key in changes) {
var attribute = key.replace(/_/g, '-'),
var item = {},
attribute = key.replace(/_/g, '-'),
name = camelize(attribute),
value = changes[key].newValue;

Expand All @@ -80,15 +67,13 @@ chrome.storage.onChanged.addListener(function (changes) {
name = 'playerPlaybackSpeed';
}

ImprovedTube.storage[key] = value;

document.documentElement.setAttribute('it-' + attribute, value);

injectScript('ImprovedTube.storage[\'' + key + '\']=' + (typeof value === 'boolean' ? value : '\'' + value + '\'') + ';');
item.key = key;
item.func = name;
item.value = value;

if (typeof ImprovedTube[name] === 'function') {
injectScript('ImprovedTube.' + name + '();');
}
document.documentElement.setAttribute('it-message', '{"storage-update": ' + JSON.stringify(item) + '}');
}
});

Expand All @@ -98,7 +83,7 @@ chrome.storage.onChanged.addListener(function (changes) {
------------------------------------------------------------------------------*/

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === 'focus') {
/*if (request.action === 'focus') {
injectScript('ImprovedTube.focus = true;');
} else if (request.action === 'blur') {
injectScript(`
Expand Down Expand Up @@ -140,14 +125,16 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
injectScript('ImprovedTube.deleteYoutubeCookies();');
}
injectScript('ImprovedTube.pageOnFocus();');
injectScript('ImprovedTube.pageOnFocus();');*/
});


/*------------------------------------------------------------------------------
6.0 INITIALIZATION
------------------------------------------------------------------------------*/

injectYoutubeScript();

chrome.storage.local.get('youtube_home_page', function (items) {
var option = items.youtube_home_page;

Expand All @@ -174,23 +161,7 @@ chrome.storage.local.get('youtube_home_page', function (items) {
});

chrome.storage.local.get(function (items) {
var textContent = 'var ImprovedTube={';

ImprovedTube.storage = items;

for (var key in ImprovedTube) {
var value = ImprovedTube[key];

if (typeof value === 'object') {
value = JSON.stringify(value);
}

textContent += key + ': ' + value + ',';
}

textContent += '};ImprovedTube.init();';

injectScript(textContent);
document.documentElement.setAttribute('it-message', '{"storage": ' + JSON.stringify(items) + '}');

attributes(items);

Expand Down
24 changes: 10 additions & 14 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "'Improve YouTube!' (Video & YouTube Tools)🎧",
"short_name": "ImprovedTube",
"description": "__MSG_description_ext__",
"version": "3.810",
"version": "3.820",
"default_locale": "en",
"icons": {
"128": "icons/128.png",
Expand All @@ -12,12 +12,9 @@
"48": "icons/48.png"
},
"background": {
"persistent": false,
"scripts": [
"background.js"
]
"service_worker": "background.js"
},
"browser_action": {
"action": {
"default_popup": "ui/popup.html"
},
"options_page": "ui/options.html",
Expand All @@ -34,7 +31,6 @@
"http://studio.youtube.com/*"
],
"js": [
"youtube-scripts.js",
"content-scripts.js"
],
"matches": [
Expand Down Expand Up @@ -68,16 +64,16 @@
"run_at": "document_start"
}
],
"web_accessible_resources": [{
"resources": ["youtube-scripts.js"],
"matches": ["https://www.youtube.com/*"]
}],
"offline_enabled": true,
"optional_permissions": [
"downloads",
"https://*.youtube.com/*"
"downloads"
],
"permissions": [
"https://www.youtube.com/",
"contextMenus",
"storage"
],
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
"update_url": "https://clients2.google.com/service/update2/crx"
]
}
Loading

0 comments on commit 8439778

Please sign in to comment.