Merge branch 'feature/manifest-v3-v2' into feature/player-ui

This commit is contained in:
Tamius Han 2023-07-10 22:05:02 +02:00
commit 48f7e1f39c
12 changed files with 1875 additions and 573 deletions

2207
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -28,13 +28,7 @@
"@babel/plugin-proposal-class-properties": "^7.16.0", "@babel/plugin-proposal-class-properties": "^7.16.0",
"@mdi/font": "^6.5.95", "@mdi/font": "^6.5.95",
"@mdi/js": "^6.4.95", "@mdi/js": "^6.4.95",
"@types/chrome": "0.0.129",
"@types/core-js": "^2.5.5",
"@types/es6-promise": "^3.3.0",
"@types/firefox": "0.0.30",
"@types/resize-observer-browser": "^0.1.6", "@types/resize-observer-browser": "^0.1.6",
"@vue/cli": "^4.5.15",
"@vue/cli-plugin-typescript": "^4.5.15",
"bootstrap": "^4.6.1", "bootstrap": "^4.6.1",
"bootstrap-vue": "^2.21.2", "bootstrap-vue": "^2.21.2",
"concurrently": "^5.3.0", "concurrently": "^5.3.0",
@ -47,12 +41,16 @@
"vue-style-loader": "^4.1.3", "vue-style-loader": "^4.1.3",
"vuex": "^4.0.2", "vuex": "^4.0.2",
"vuex-webextensions": "^1.3.3", "vuex-webextensions": "^1.3.3",
"webextension-polyfill-ts": "^0.24.0" "webextension-polyfill-ts": "^0.26.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.16.0", "@babel/core": "^7.16.0",
"@babel/plugin-proposal-optional-chaining": "^7.16.0", "@babel/plugin-proposal-optional-chaining": "^7.16.0",
"@babel/preset-env": "^7.16.0", "@babel/preset-env": "^7.16.0",
"@types/chrome": "0.0.240",
"@types/core-js": "^2.5.5",
"@types/es6-promise": "^3.3.0",
"@types/firefox": "0.0.31",
"@types/lodash": "^4.14.176", "@types/lodash": "^4.14.176",
"@types/node": "^14.17.32", "@types/node": "^14.17.32",
"@vue/compiler-sfc": "^3.2.21", "@vue/compiler-sfc": "^3.2.21",
@ -76,6 +74,8 @@
"webpack": "^4.46.0", "webpack": "^4.46.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

@ -85,14 +85,13 @@ export default class UWServer {
this.settings = new Settings({logger: this.logger}); this.settings = new Settings({logger: this.logger});
await this.settings.init(); await this.settings.init();
this.eventBus = new EventBus(); this.eventBus = new EventBus({isUWServer: true});
for (const action in this.eventBusCommands) { for (const action in this.eventBusCommands) {
for (const command of this.eventBusCommands[action]) { for (const command of this.eventBusCommands[action]) {
this.eventBus.subscribe(action, command); this.eventBus.subscribe(action, command);
} }
} }
this.comms = new CommsServer(this); this.comms = new CommsServer(this);
this.eventBus.setComms(this.comms); this.eventBus.setComms(this.comms);
@ -109,11 +108,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});
@ -121,7 +141,30 @@ export default class UWServer {
} }
async removeCss(css, sender) { async removeCss(css, sender) {
try { try {
browser.tabs.removeCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId}); if (BrowserDetect.firefox) {
browser.scripting.removeCSS({
target: {
tabId: sender.tab.id,
frameIds: [
sender.frameId
]
},
css,
origin: "USER"
});
} else {
await chrome.scripting.removeCSS({
target: {
tabId: sender.tab.id,
frameIds: [
sender.frameId
]
},
css,
origin: "USER"
});
}
} catch (e) { } catch (e) {
this.logger.log('error','debug', '[UwServer::injectCss] Error while removing css:', {error: e, css, sender}); this.logger.log('error','debug', '[UwServer::injectCss] Error while removing css:', {error: e, css, sender});
} }
@ -129,8 +172,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() {
@ -31,10 +35,10 @@ const BrowserDetect = {
browserObj: getBrowserObj(), browserObj: getBrowserObj(),
runtime: getRuntime(), runtime: getRuntime(),
getURL: (url) => getURL(url), getURL: (url) => getURL(url),
} }
if (process.env.CHANNEL !== 'stable') { if (process.env.CHANNEL !== 'stable') {
console.info("BrowserDetect loaded:\n\nprocess.env.BROWSER:", process.env.BROWSER, "\nExporting BrowserDetect:", BrowserDetect); console.info("BrowserDetect loaded:\n\nprocess.env.BROWSER:", process.env.BROWSER, "\nExporting BrowserDetect:", BrowserDetect);
} }
export default BrowserDetect; export default BrowserDetect;

View File

@ -32,8 +32,10 @@ export default class EventBus {
private popupContext: any = {}; private popupContext: any = {};
// private uiUri = window.location.href; // private uiUri = window.location.href;
constructor() { constructor(options?: {isUWServer?: boolean}) {
this.setupIframeTunnelling(); if (!options?.isUWServer) {
this.setupIframeTunnelling();
}
} }
setupPopupTunnelWorkaround(context: EventBusContext): void { setupPopupTunnelWorkaround(context: EventBusContext): void {

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

@ -65,5 +65,5 @@ export class ExtensionStatus {
this.refreshExtensionStatus(); this.refreshExtensionStatus();
} }
updateFullScreen() updateFullScreen() {}
} }

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.99.5", "version": "5.99.5",
"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": [
@ -26,10 +22,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"
] ]
}, },
@ -40,19 +38,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",
"csui/*" "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

@ -129,12 +129,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

@ -1,9 +1,9 @@
/** /**
* NOTE: we cannot get rid of this js file. I tried for 30 seconds and I couldn't get * NOTE: we cannot get rid of this js file. I tried for 30 seconds and I couldn't get
* 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

@ -13,7 +13,7 @@ const config = {
context: __dirname + '/src', context: __dirname + '/src',
entry: { entry: {
'ext/uw': './ext/uw.js', 'ext/uw': './ext/uw.js',
'ext/uw-bg': './ext/uw-bg.js', 'uw-bg': './uw-bg.js',
'popup/popup': './popup/popup.js', 'popup/popup': './popup/popup.js',
'options/options': './options/options.js', 'options/options': './options/options.js',
'csui/csui': './csui/csui.js', 'csui/csui': './csui/csui.js',
@ -138,9 +138,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";
@ -178,8 +178,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);