diff --git a/built/web/options/options.mjs b/built/web/options/options.mjs index 1b05d3d6..2487b56b 100644 --- a/built/web/options/options.mjs +++ b/built/web/options/options.mjs @@ -129,7 +129,7 @@ function createKeybindElement(keybind) { containerElement.appendChild(keybindInput); keybindsList.appendChild(containerElement); } -document.getElementById('welcome').href = chrome?.runtime?.getURL('welcome.html') || './../welcome.html'; +document.getElementById('welcome').href = EnvUtils.isExtension() ? chrome?.runtime?.getURL('welcome.html') : './../welcome.html'; playMP4URLs.addEventListener('change', () => { Options.playMP4URLs = playMP4URLs.checked; optionChanged(); diff --git a/built/web/player/main.mjs b/built/web/player/main.mjs index affcee82..96a58d82 100644 --- a/built/web/player/main.mjs +++ b/built/web/player/main.mjs @@ -143,7 +143,7 @@ async function loadSubtitles(subs) { return subs.filter((sub) => sub.data); } async function sortSubtitles(subs) { - if (!chrome?.i18n?.detectLanguage) { + if (!EnvUtils.isExtension() || !chrome?.i18n?.detectLanguage) { return subs; } let defLang = 'en'; @@ -182,16 +182,18 @@ async function setup() { if (OPTIONS && window.fastStream) window.fastStream.setOptions(OPTIONS); const urlParams = new URLSearchParams(window.location.search); const myParam = urlParams.get('frame_id'); - chrome?.runtime?.sendMessage({ - type: 'faststream', - url: window.location.href, - isExt: true, - frameId: parseInt(myParam) || 0, - }).then((data) => { - chrome.runtime.sendMessage({ - type: 'ready', + if (EnvUtils.isExtension()) { + chrome?.runtime?.sendMessage({ + type: 'faststream', + url: window.location.href, + isExt: true, + frameId: parseInt(myParam) || 0, + }).then((data) => { + chrome.runtime.sendMessage({ + type: 'ready', + }); }); - }); + } const version = window.fastStream.version; console.log('\n %c %c %cFast%cStream %c-%c ' + version + ' %c By Andrews54757 \n', 'background: url(https://user-images.githubusercontent.com/13282284/57593160-3a4fb080-7508-11e9-9507-33d45c4f9e41.png) no-repeat; background-size: 16px 16px; padding: 2px 6px; margin-right: 4px', 'background: rgb(50,50,50); padding:5px 0;', 'color: rgb(200,200,200); background: rgb(50,50,50); padding:5px 0;', 'color: rgb(200,200,200); background: rgb(50,50,50); padding:5px 0;', 'color: rgb(200,200,200); background: rgb(50,50,50); padding:5px 0;', 'color: #afbc2a; background: rgb(50,50,50); padding:5px 0;', 'color: black; background: #e9e9e9; padding:5px 0;'); window.addEventListener('beforeunload', () => { diff --git a/built/web/player/modules/FSBlob.mjs b/built/web/player/modules/FSBlob.mjs index e57bb6f6..2cc17e5a 100644 --- a/built/web/player/modules/FSBlob.mjs +++ b/built/web/player/modules/FSBlob.mjs @@ -1,14 +1,15 @@ import {IndexedDBManager} from '../network/IndexedDBManager.mjs'; import {EnvUtils} from '../utils/EnvUtils.mjs'; const BrowserCanAutoOffloadBlobs = EnvUtils.isChrome(); +const UseIndexedDB = !BrowserCanAutoOffloadBlobs && IndexedDBManager.isSupported(); export class FSBlob { constructor() { - if (BrowserCanAutoOffloadBlobs) { - this.blobStore = new Map(); - } else { + if (UseIndexedDB) { this.indexedDBManager = new IndexedDBManager(); this.setupPromise = this.indexedDBManager.setup(); this.blobStorePromises = new Map(); + } else { + this.blobStore = new Map(); } this.blobIndex = 0; } @@ -18,10 +19,10 @@ export class FSBlob { return true; } _saveBlob(identifier, blob) { - if (BrowserCanAutoOffloadBlobs) { - this.blobStore.set(identifier, blob); - } else { + if (UseIndexedDB ) { this.blobStorePromises.set(identifier, this.saveBlobAsync(identifier, blob)); + } else { + this.blobStore.set(identifier, blob); } } saveBlob(blob) { @@ -36,11 +37,11 @@ export class FSBlob { return identifier; } async getBlob(identifier) { - if (BrowserCanAutoOffloadBlobs) { - return this.blobStore.get(identifier); - } else { + if (UseIndexedDB) { await this.blobStorePromises.get(identifier); return await this.indexedDBManager.getFile(identifier); + } else { + return this.blobStore.get(identifier); } } close() { diff --git a/built/web/player/network/DownloadManager.mjs b/built/web/player/network/DownloadManager.mjs index 34d02956..1878f4ce 100644 --- a/built/web/player/network/DownloadManager.mjs +++ b/built/web/player/network/DownloadManager.mjs @@ -244,7 +244,7 @@ export class DownloadManager { } async setup() { // Chrome can move blobs to file storage, so we don't need to use IndexedDB - if (!EnvUtils.isChrome()) { + if (!EnvUtils.isChrome() && IndexedDBManager.isSupported()) { this.indexedDBManager = new IndexedDBManager(); await this.indexedDBManager.setup(); } diff --git a/built/web/player/network/IndexedDBManager.mjs b/built/web/player/network/IndexedDBManager.mjs index 75f98107..89a53d0b 100644 --- a/built/web/player/network/IndexedDBManager.mjs +++ b/built/web/player/network/IndexedDBManager.mjs @@ -2,6 +2,9 @@ const closeQueue = []; export class IndexedDBManager { constructor() { } + static isSupported() { + return window.indexedDB !== undefined; + } async setup() { await this.close(); this.prune(); @@ -91,6 +94,7 @@ export class IndexedDBManager { }); } async clearStorage() { + if (!this.db) return; return this.transact(this.db, 'files', 'readwrite', (transaction)=>{ const metaDataStore = transaction.objectStore('files'); return this.wrapRequest(metaDataStore.clear()); diff --git a/built/web/player/utils/EnvUtils.mjs b/built/web/player/utils/EnvUtils.mjs index abb4bc4a..20dc7e75 100644 --- a/built/web/player/utils/EnvUtils.mjs +++ b/built/web/player/utils/EnvUtils.mjs @@ -14,7 +14,7 @@ export class EnvUtils { return navigator.userAgent.indexOf('Chrome') !== -1; } static isExtension() { - return !!chrome?.extension; + return typeof chrome !== 'undefined' && !!chrome?.extension; } static getVersion() { // eslint-disable-next-line prefer-const