get manifest v3 to approximately work

This commit is contained in:
Tamius Han 2024-05-30 01:02:09 +02:00
parent 5ca9325e16
commit 12644bfbea
10 changed files with 1376 additions and 447 deletions

1633
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -71,6 +71,8 @@
"webpack": "^4.44.0", "webpack": "^4.44.0",
"webpack-chrome-extension-reloader": "^0.8.3", "webpack-chrome-extension-reloader": "^0.8.3",
"webpack-cli": "^3.3.12", "webpack-cli": "^3.3.12",
"webpack-shell-plugin": "^0.5.0" "webpack-shell-plugin": "^0.5.0",
"@vue/cli": "^4.5.15",
"@vue/cli-plugin-typescript": "^4.5.15"
} }
} }

View File

@ -71,11 +71,32 @@ export default class UWServer {
} }
async injectCss(css, sender) { async injectCss(css, sender) {
if (!css) {
return;
}
try { try {
if (BrowserDetect.firefox || BrowserDetect.edge) { if (BrowserDetect.firefox) {
browser.tabs.insertCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId}); browser.scripting.insertCSS({
} else if (BrowserDetect.anyChromium) { target: {
chrome.tabs.insertCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId}); tabId: sender.tab.id,
frameIds: [
sender.frameId
]
},
css,
origin: "USER"
});
} else {
await chrome.scripting.insertCSS({
target: {
tabId: sender.tab.id,
frameIds: [
sender.frameId
]
},
css,
origin: "USER"
});
} }
} catch (e) { } catch (e) {
this.logger.log('error','debug', '[UwServer::injectCss] Error while injecting css:', {error: e, css, sender}); this.logger.log('error','debug', '[UwServer::injectCss] Error while injecting css:', {error: e, css, sender});
@ -91,8 +112,8 @@ export default class UWServer {
async replaceCss(oldCss, newCss, sender) { async replaceCss(oldCss, newCss, sender) {
if (oldCss !== newCss) { if (oldCss !== newCss) {
this.injectCss(newCss, sender);
this.removeCss(oldCss, sender); this.removeCss(oldCss, sender);
this.injectCss(newCss, sender);
} }
} }

View File

@ -5,7 +5,11 @@ if (process.env.CHANNEL !== 'stable') {
} }
function detectEdgeUA() { function detectEdgeUA() {
return /Edg\/(\.?[0-9]*)*$/.test(window.navigator.userAgent); try {
return /Edg\/(\.?[0-9]*)*$/.test(window.navigator.userAgent);
} catch {
return undefined;
}
} }
function getBrowserObj() { function getBrowserObj() {

View File

@ -268,8 +268,18 @@ class Logger {
// return logfileStr; // return logfileStr;
// } // }
getFileLogJSONString() { getFileLogJSONString() {
let site;
// NOTE: no more window object on UWServer side of things!
// (or rather, we could get it, but we don't care enough to get it in this instance)
try {
site = window && window.location;
} catch {
site = 'uw-bg';
}
return { return {
site: window && window.location, site,
log: JSON.stringify(this.history), log: JSON.stringify(this.history),
} }
} }

View File

@ -1,22 +1,18 @@
{ {
"manifest_version": 2, "manifest_version": 3,
"name": "Ultrawidify", "name": "Ultrawidify",
"description": "Removes black bars on ultrawide videos and offers advanced options to fix aspect ratio.", "description": "Removes black bars on ultrawide videos and offers advanced options to fix aspect ratio.",
"version": "5.1.7", "version": "5.1.7",
"applications": {
"gecko": {
"id": "{cf02b1a7-a01a-4e37-a609-516a283f1ed3}"
}
},
"icons": { "icons": {
"32":"res/icons/uw-32.png", "32":"res/icons/uw-32.png",
"64":"res/icons/uw-64.png" "64":"res/icons/uw-64.png"
}, },
"browser_action": { "action": {
"default_title": "Ultrawidify", "default_title": "Ultrawidify",
"default_popup": "popup/popup.html" "default_popup": "popup/popup.html"
}, },
"content_scripts": [{ "content_scripts": [{
"matches": ["*://*/*"], "matches": ["*://*/*"],
"js": [ "js": [
@ -30,10 +26,12 @@
"all_frames": true "all_frames": true
}], }],
"minimum_chrome_version": "93",
"background": { "background": {
"persistent": true, "service_worker": "uw-bg.js",
"module": true,
"scripts": [ "scripts": [
"ext/uw-bg.js" "uw-bg.js"
] ]
}, },
@ -45,18 +43,29 @@
"web_accessible_resources": [ "web_accessible_resources": [
"./*", {
"ext/*", "resources": [
"res/fonts/*", "./*",
"res/css/*", "ext/*",
"res/img/settings/about-bg.png", "res/fonts/*",
"res/icons/*", "res/css/*",
"res/img/*" "res/img/settings/about-bg.png",
"res/icons/*",
"res/img/*",
"csui/*"
],
"matches": [
"*://*/*"
]
}
], ],
"permissions": [ "permissions": [
"storage", "storage",
"activeTab", "activeTab",
"<all_urls>" "scripting"
],
"host_permissions": [
"*://*/*"
], ],
"optional_permissions": [ "optional_permissions": [
"downloads" "downloads"

60
src/manifest.v2.json Normal file
View File

@ -0,0 +1,60 @@
{
"manifest_version": 2,
"name": "Ultrawidify",
"description": "Removes black bars on ultrawide videos and offers advanced options to fix aspect ratio.",
"version": "5.99.5",
"applications": {
"gecko": {
"id": "{cf02b1a7-a01a-4e37-a609-516a283f1ed3}"
}
},
"icons": {
"32":"res/icons/uw-32.png",
"64":"res/icons/uw-64.png"
},
"browser_action": {
"default_title": "Ultrawidify",
"default_popup": "popup/popup.html"
},
"content_scripts": [{
"matches": ["*://*/*"],
"js": [
"common/lib/browser-polyfill.js",
"ext/uw.js"
],
"all_frames": true
}],
"background": {
"persistent": true,
"scripts": [
"ext/uw-bg.js"
]
},
"options_ui": {
"page": "options/options.html",
"browser_style": false,
"open_in_tab": true
},
"web_accessible_resources": [
"./*",
"ext/*",
"res/fonts/*",
"res/css/*",
"res/img/settings/about-bg.png",
"res/icons/*",
"res/img/*",
"csui/*"
],
"permissions": [
"storage",
"activeTab",
"<all_urls>"
],
"optional_permissions": [
"downloads"
]
}

View File

@ -279,12 +279,12 @@ export default {
cmd: 'unmark-player', cmd: 'unmark-player',
forwardToAll: true, forwardToAll: true,
}); });
if (BrowserDetect.anyChromium) { // if (BrowserDetect.anyChromium) {
chrome.extension.getBackgroundPage().sendUnmarkPlayer({ // chrome.extension.getBackgroundPage().sendUnmarkPlayer({
cmd: 'unmark-player', // cmd: 'unmark-player',
forwardToAll: true, // forwardToAll: true,
}); // });
} // }
}); });
// get info about current site from background script // get info about current site from background script

View File

@ -3,7 +3,7 @@
* extension to work unless I kept this part of extension out of the ts file. * extension to work unless I kept this part of extension out of the ts file.
*/ */
import UWServer from './UWServer'; import UWServer from './ext/UWServer';
var BgVars = { var BgVars = {
arIsActive: true, arIsActive: true,
@ -12,7 +12,3 @@ var BgVars = {
} }
const server = new UWServer(); const server = new UWServer();
window.sendUnmarkPlayer = (message) => {
server.sendUnmarkPlayer(message)
}

View File

@ -139,9 +139,9 @@ const config = {
const jsonContent = JSON.parse(content); const jsonContent = JSON.parse(content);
// jsonContent.version = version; // jsonContent.version = version;
if (config.mode === 'development') { // if (config.mode === 'development') {
jsonContent['content_security_policy'] = "script-src 'self' 'unsafe-eval'; object-src 'self'"; // jsonContent['content_security_policy'] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
} // }
if (process.env.CHANNEL === 'nightly') { if (process.env.CHANNEL === 'nightly') {
jsonContent.name = "Ultrawidify - nightly"; jsonContent.name = "Ultrawidify - nightly";
@ -179,8 +179,10 @@ const config = {
if (process.env.BROWSER !== 'firefox') { if (process.env.BROWSER !== 'firefox') {
jsonContent.version = jsonContent.version.replace(/[a-zA-Z-]/g, ''); jsonContent.version = jsonContent.version.replace(/[a-zA-Z-]/g, '');
delete jsonContent.applications;
delete jsonContent.options_ui.browser_style; delete jsonContent.options_ui.browser_style;
delete jsonContent.background.scripts;
} else {
delete jsonContent.background.service_worker;
} }
return JSON.stringify(jsonContent, null, 2); return JSON.stringify(jsonContent, null, 2);