diff --git a/manifest.v2.json b/manifest.v2.json new file mode 100644 index 0000000..9489f9c --- /dev/null +++ b/manifest.v2.json @@ -0,0 +1,56 @@ +{ + "manifest_version": 2, + "name": "Watch on LBRY", + "version": "2.0.0", + "icons": { + "16": "assets/icons/wol/icon16.png", + "48": "assets/icons/wol/icon48.png", + "128": "assets/icons/wol/icon128.png" + }, + "permissions": [ + "https://www.youtube.com/", + "https://yewtu.be/", + "https://vid.puffyan.us/", + "https://invidio.xamh.de/", + "https://invidious.kavin.rocks/", + "https://api.odysee.com/", + "https://lbry.tv/", + "https://odysee.com/", + "https://madiator.com/", + "https://finder.madiator.com/", + "tabs", + "storage" + ], + "web_accessible_resources": [ + "pages/popup/index.html", + "pages/YTtoLBRY/index.html", + "pages/import/index.html", + "assets/icons/lbry/lbry-logo.svg", + "assets/icons/lbry/odysee-logo.svg", + "assets/icons/lbry/madiator-logo.svg" + ], + "browser_action": { + "default_title": "Watch on LBRY", + "default_popup": "pages/popup/index.html" + }, + "content_scripts": [ + { + "matches": [ + "https://www.youtube.com/*", + "https://yewtu.be/*", + "https://vid.puffyan.us/*", + "https://invidio.xamh.de/*", + "https://invidious.kavin.rocks/*" + ], + "js": [ + "scripts/ytContent.js" + ] + } + ], + "background": { + "scripts": [ + "service-worker-entry-point.js" + ], + "persistent": true + } +} \ No newline at end of file diff --git a/src/manifest.json b/manifest.v3.json similarity index 100% rename from src/manifest.json rename to manifest.v3.json diff --git a/package.json b/package.json index 0db5333..e200c3a 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,29 @@ "scripts": { "build:assets": "cpx \"src/**/*.{json,png,svg}\" dist/", "watch:assets": "cpx --watch -v \"src/**/*.{json,png,svg}\" dist/", + "build:parcel": "cross-env NODE_ENV=production parcel build --no-source-maps --no-minify \"src/**/*.{js,jsx,ts,tsx}\" \"src/**/*.html\" \"src/**/*.md\"", "watch:parcel": "parcel watch --no-hmr --no-source-maps \"src/**/*.{js,jsx,ts,tsx}\" \"src/**/*.html\" \"src/**/*.md\"", + "build:webext": "web-ext build --source-dir ./dist --overwrite-dest", - "build": "npm-run-all -l -p build:parcel build:assets", - "watch": "npm-run-all -l -p watch:parcel watch:assets", + + "clear:dist": "rm -r ./dist ; mkdir ./dist", + + "build:base": "npm-run-all -l -p build:parcel build:assets", + + "pick:manifest:v2": "cp -b ./manifest.v2.json ./dist/manifest.json", + "pick:manifest:v3": "cp -b ./manifest.v3.json ./dist/manifest.json", + + "build:v2": "npm run clear:dist ; npm run build:base && npm run pick:manifest:v2", + "build:v3": "npm run clear:dist ; npm run build:base && npm run pick:manifest:v3", + + "build": "npm run build:v3", + + "watch:v2": "npm run clear:dist ; npm run pick:manifest:v2 && npm-run-all -l -p watch:parcel watch:assets", + "watch:v3": "npm run clear:dist ; npm run pick:manifest:v3 && npm-run-all -l -p watch:parcel watch:assets", + + "watch": "npm run watch:v3", + "start:chrome": "web-ext run -t chromium --source-dir ./dist", "start:firefox": "web-ext run --source-dir ./dist", "test": "jest" diff --git a/src/settings/background.ts b/src/settings/background.ts index 19dc28f..910c8ac 100644 --- a/src/settings/background.ts +++ b/src/settings/background.ts @@ -1,4 +1,8 @@ import { DEFAULT_SETTINGS, ExtensionSettings, getExtensionSettingsAsync, setExtensionSetting, targetPlatformSettings, ytUrlResolversSettings } from '../settings' + +// This is for manifest v2 and v3 +const chromeAction = chrome.action ?? chrome.browserAction + /** Reset settings to default value and update the browser badge text */ async function initSettings() { let settings = await getExtensionSettingsAsync() @@ -17,12 +21,12 @@ async function initSettings() { if (!Object.keys(targetPlatformSettings).includes(settings.targetPlatform)) setExtensionSetting('targetPlatform', DEFAULT_SETTINGS.targetPlatform) if (!Object.keys(ytUrlResolversSettings).includes(settings.urlResolver)) setExtensionSetting('urlResolver', DEFAULT_SETTINGS.urlResolver) - chrome.action.setBadgeText({ text: settings.redirect ? 'ON' : 'OFF' }) + chromeAction.setBadgeText({ text: settings.redirect ? 'ON' : 'OFF' }) } chrome.storage.onChanged.addListener((changes, areaName) => { if (areaName !== 'local' || !changes.redirect) return - chrome.action.setBadgeText({ text: changes.redirect.newValue ? 'ON' : 'OFF' }) + chromeAction.setBadgeText({ text: changes.redirect.newValue ? 'ON' : 'OFF' }) }) chrome.runtime.onStartup.addListener(initSettings)