diff --git a/chrome/options/options.mjs b/chrome/options/options.mjs index 1e361230..df4b38c6 100644 --- a/chrome/options/options.mjs +++ b/chrome/options/options.mjs @@ -155,7 +155,7 @@ function createKeybindElement(keybind) { 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; diff --git a/chrome/player/main.mjs b/chrome/player/main.mjs index 30590dc2..01dc64f7 100644 --- a/chrome/player/main.mjs +++ b/chrome/player/main.mjs @@ -167,7 +167,7 @@ async function loadSubtitles(subs) { } async function sortSubtitles(subs) { - if (!chrome?.i18n?.detectLanguage) { + if (!EnvUtils.isExtension() || !chrome?.i18n?.detectLanguage) { return subs; } @@ -215,16 +215,18 @@ async function setup() { 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;'); diff --git a/chrome/player/modules/FSBlob.mjs b/chrome/player/modules/FSBlob.mjs index 8538857c..ef77d0f5 100644 --- a/chrome/player/modules/FSBlob.mjs +++ b/chrome/player/modules/FSBlob.mjs @@ -2,15 +2,16 @@ 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; @@ -23,10 +24,10 @@ export class FSBlob { } _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); } } @@ -44,11 +45,11 @@ export class FSBlob { } 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); } } diff --git a/chrome/player/network/DownloadManager.mjs b/chrome/player/network/DownloadManager.mjs index 84c1db25..561ba230 100644 --- a/chrome/player/network/DownloadManager.mjs +++ b/chrome/player/network/DownloadManager.mjs @@ -303,7 +303,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/chrome/player/network/IndexedDBManager.mjs b/chrome/player/network/IndexedDBManager.mjs index 065d0c23..9a442160 100644 --- a/chrome/player/network/IndexedDBManager.mjs +++ b/chrome/player/network/IndexedDBManager.mjs @@ -5,6 +5,10 @@ export class IndexedDBManager { constructor() { } + static isSupported() { + return window.indexedDB !== undefined; + } + async setup() { await this.close(); this.prune(); @@ -107,6 +111,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/chrome/player/utils/EnvUtils.mjs b/chrome/player/utils/EnvUtils.mjs index f3052d9d..31d0ddeb 100644 --- a/chrome/player/utils/EnvUtils.mjs +++ b/chrome/player/utils/EnvUtils.mjs @@ -18,7 +18,7 @@ export class EnvUtils { } static isExtension() { - return !!chrome?.extension; + return typeof chrome !== 'undefined' && !!chrome?.extension; } static getVersion() {