ZeroOmega/omega-target-chromium-extension/overlay/x-background.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

import zeroLocalStorage from "./localstorage-polyfill.js"
import ZeroLogFactory from './log.js'
import ZeroIndexedDBFactory from './indexedDB.js'
2024-02-29 09:14:04 -05:00
import "./js/background_preload.js"
2024-06-28 22:46:25 -04:00
import "./lib/idb-keyval.js"
import "./lib/moment-with-locales.js"
import "./lib/csso.js"
2024-02-29 09:14:04 -05:00
import "./js/log_error.js"
2024-06-28 22:46:25 -04:00
import "./log.js"
2024-02-29 09:14:04 -05:00
//import "./lib/FileSaver/FileSaver.min.js"
2024-06-28 22:46:25 -04:00
//import "./js/omega_debug.js"
2024-02-29 09:14:04 -05:00
import "./js/omega_pac.min.js"
import "./js/omega_target.min.js"
import "./js/omega_target_chromium_extension.min.js"
import "./img/icons/draw_omega.js"
import "./js/background.js" // zeroBackground
/**
* author: suziwen1@gmail.com
**/
const isFirefox = !!globalThis.localStorage
function detectPrivateMode(cb) {
2024-08-13 21:47:41 -04:00
var db, tempMode,
on = cb.bind(null, true),
off = cb.bind(null, false)
if (isFirefox) {
2024-08-13 21:47:41 -04:00
// in private mode, localStorage will be erased when browser restart
tempMode = localStorage.getItem('zeroOmega.isPrivateMode')
if (tempMode) {
tempMode == 'true' ? on() : off()
} else {
db = indexedDB.open("zeroOmega-test"), db.onerror = on, db.onsuccess = off
}
} else {
off()
}
}
detectPrivateMode(function (isPrivateMode) {
2024-08-13 21:47:41 -04:00
if (isFirefox) {
localStorage.setItem('zeroOmega.isPrivateMode', isPrivateMode ? 'true' : 'false')
}
if (isPrivateMode && isFirefox) {
// fake indexedDB
ZeroIndexedDBFactory()
}
ZeroLogFactory()
const zeroStorage = isFirefox ? localStorage : zeroLocalStorage
globalThis.zeroBackground(zeroStorage)
console.log('is private mode: ' + isPrivateMode)
})