ultrawidify/src/ext/uw.js

146 lines
5.1 KiB
JavaScript
Raw Normal View History

import Debug from './conf/Debug';
import BrowserDetect from './conf/BrowserDetect';
2019-01-20 23:01:45 +01:00
import ExtensionMode from '../common/enums/extension-mode.enum'
import Settings from './lib/Settings';
import ActionHandler from './lib/ActionHandler';
import CommsClient from './lib/comms/CommsClient';
import PageInfo from './lib/video-data/PageInfo';
import Logger from './lib/Logger';
if(Debug.debug){
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀɪɪʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
try {
if(window.self !== window.top){
console.log("%cWe aren't in an iframe.", "color: #afc, background: #174");
}
else{
console.log("%cWe are in an iframe!", "color: #fea, background: #d31", window.self, window.top);
}
} catch (e) {
console.log("%cWe are in an iframe!", "color: #fea, background: #d31");
}
}
2018-09-25 23:37:08 +02:00
if (BrowserDetect.edge) {
HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
}
class UW {
constructor(){
this.pageInfo = undefined;
this.comms = undefined;
this.settings = undefined;
this.actionHandler = undefined;
this.logger = undefined;
}
2018-08-07 23:31:28 +02:00
async init(){
if (Debug.debug) {
console.log("[uw::main] loading configuration ...");
}
2018-08-22 23:16:08 +02:00
// logger init is the first thing that needs to run
try {
if (!this.logger) {
const loggingOptions = {
2020-01-16 01:00:12 +01:00
allowLogging: true,
fileOptions: {
2020-01-20 20:07:18 +01:00
enabled: false,
// really the same stuff as consoleOptions
},
consoleOptions: {
enabled: true, // if logging is enabled at all
2020-01-27 22:32:38 +01:00
'debug': true,
'init': true,
'settings': true,
'keyboard': true,
'mousemove': false,
'actionHandler': true,
'comms': true,
'playerDetect': true,
2020-01-27 22:32:38 +01:00
'resizer': true,
'scaler': true,
'stretcher': true,
// 'videoRescan': true,
// 'playerRescan': true,
2020-01-27 22:32:38 +01:00
'arDetect': true,
'arDetect_verbose': true,
},
allowBlacklistedOrigins: {
// logs that were called from functions named here will be excluded from both console logging
// as well as logging to file. Exclusions happen because these functions — being periodic in
// nature as well as doing a lot of work — usually clog console too fast without providing
// any valuable info.
// 'periodicPlayerCheck': true,
// 'periodicVideoStyleChangeCheck': true,
'handleMouseMove': false,
}
};
2020-01-27 22:32:38 +01:00
this.logger = new Logger();
await this.logger.init(loggingOptions);
2019-09-03 23:01:23 +02:00
// await this.logger.init(); // not needed if logging options are provided at creation
}
} catch (e) {
console.error("logger init failed!", e)
}
// init() is re-run any time settings change
if (this.pageInfo) {
// if this executes, logger must have been initiated at some point before this point
this.logger.log('info', 'debug', "[uw::init] Destroying existing pageInfo", this.pageInfo);
this.pageInfo.destroy();
}
if (this.comms) {
this.comms.destroy();
}
if (!this.settings) {
var ths = this;
2019-09-17 22:18:02 +02:00
this.settings = new Settings({updateCallback: (s) => {console.log("settings callback — ", s); ths.init()}, logger: this.logger});
await this.settings.init();
}
this.comms = new CommsClient('content-client-port', this.settings, this.logger);
// če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar
// If extension is soft-disabled, don't do shit
2018-11-02 02:52:01 +01:00
var extensionMode = this.settings.getExtensionMode();
this.logger.log('info', 'debug', "[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full'));
2018-11-02 02:52:01 +01:00
const isSiteDisabled = extensionMode === ExtensionMode.Disabled
if (isSiteDisabled) {
if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) {
this.logger.log('info', 'debug', "[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
return;
}
}
try {
this.pageInfo = new PageInfo(this.comms, this.settings, this.logger, extensionMode, isSiteDisabled);
this.logger.log('info', 'debug', "[uw.js::setup] pageInfo initialized. Here's the object:", this.pageInfo);
this.comms.setPageInfo(this.pageInfo);
this.logger.log('info', 'debug', "[uw.js::setup] will try to initate ActionHandler. Settings are:", this.settings, this.settings.active)
// start action handler only if extension is enabled for this site
if (!isSiteDisabled) {
2019-09-03 22:55:10 +02:00
this.actionHandler = new ActionHandler(this.pageInfo);
this.actionHandler.init();
this.logger.log('info', 'debug', "[uw.js::setup] ActionHandler initiated:", this.actionHandler);
2018-11-16 23:02:56 +01:00
}
} catch (e) {
this.logger.log('error', 'debug', "[uw::init] FAILED TO START EXTENSION. Error:", e);
}
2017-12-31 18:26:59 +01:00
}
}
var main = new UW();
main.init();