ultrawidify/js/uw.js

95 lines
2.7 KiB
JavaScript
Raw Normal View History

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;
}
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
// init() is re-run any time settings change
if (this.pageInfo) {
if(Debug.debug){
console.log("[uw::init] Destroying existing pageInfo", this.pageInfo);
}
this.pageInfo.destroy();
}
if (this.comms) {
this.comms.destroy();
}
if (!this.settings) {
var ths = this;
this.settings = new Settings(undefined, () => ths.init());
await this.settings.init();
}
this.comms = new CommsClient('content-client-port', this.settings);
// č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();
if(Debug.debug) {
console.log("[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full'));
}
2018-11-02 02:52:01 +01:00
if(extensionMode === ExtensionMode.Disabled){
if(Debug.debug) {
console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
}
return;
}
try {
this.pageInfo = new PageInfo(this.comms, this.settings, extensionMode);
if(Debug.debug){
console.log("[uw.js::setup] pageInfo initialized. Here's the object:", this.pageInfo);
}
this.comms.setPageInfo(this.pageInfo);
if(Debug.debug) {
console.log("[uw.js::setup] will try to initate ActionHandler. Settings are:", this.settings, this.settings.active)
}
this.actionHandler = new ActionHandler(this.pageInfo);
this.actionHandler.init();
2018-11-16 23:02:56 +01:00
if(Debug.debug) {
console.log("[uw.js::setup] ActionHandler initiated:", this.actionHandler);
}
} catch (e) {
console.log("[uw::init] FAILED TO START EXTENSION. Error:", e);
}
2017-12-31 18:26:59 +01:00
}
}
var uw = new UW();
uw.init();