2018-12-31 01:03:07 +01:00
|
|
|
|
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'
|
2018-12-31 01:03:07 +01:00
|
|
|
|
import Settings from './lib/Settings';
|
|
|
|
|
import ActionHandler from './lib/ActionHandler';
|
|
|
|
|
import CommsClient from './lib/comms/CommsClient';
|
|
|
|
|
import PageInfo from './lib/video-data/PageInfo';
|
2019-07-18 21:25:58 +02:00
|
|
|
|
import Logger from './lib/Logger';
|
2018-12-31 01:03:07 +01:00
|
|
|
|
|
2020-02-02 00:57:54 +01:00
|
|
|
|
// vue dependency imports
|
2020-01-31 01:03:06 +01:00
|
|
|
|
import Vue from 'vue';
|
2020-02-02 00:57:54 +01:00
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
|
import VuexWebExtensions from 'vuex-webextensions';
|
|
|
|
|
|
|
|
|
|
global.browser = require('webextension-polyfill');
|
2020-01-31 01:03:06 +01:00
|
|
|
|
import LoggerUi from '../csui/LoggerUi';
|
|
|
|
|
|
2018-01-24 23:15:54 +01:00
|
|
|
|
if(Debug.debug){
|
2017-09-24 01:54:46 +02:00
|
|
|
|
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
2018-01-24 23:15:54 +01:00
|
|
|
|
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];
|
|
|
|
|
}
|
2018-05-13 13:49:25 +02:00
|
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
|
class UW {
|
|
|
|
|
constructor(){
|
|
|
|
|
this.pageInfo = undefined;
|
|
|
|
|
this.comms = undefined;
|
|
|
|
|
this.settings = undefined;
|
2018-11-15 00:18:41 +01:00
|
|
|
|
this.actionHandler = undefined;
|
2019-07-18 21:25:58 +02:00
|
|
|
|
this.logger = undefined;
|
2020-02-04 00:56:48 +01:00
|
|
|
|
this.vuexStore = {};
|
2018-08-30 00:56:15 +02:00
|
|
|
|
}
|
2018-08-07 23:31:28 +02:00
|
|
|
|
|
2020-02-09 01:16:46 +01:00
|
|
|
|
reloadSettings() {
|
|
|
|
|
this.logger.log('info', 'debug', 'Things happened in the popup. Will reload extension settings.');
|
|
|
|
|
this.init();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
|
async init(){
|
|
|
|
|
if (Debug.debug) {
|
|
|
|
|
console.log("[uw::main] loading configuration ...");
|
|
|
|
|
}
|
2018-08-22 23:16:08 +02:00
|
|
|
|
|
2019-09-03 00:48:18 +02:00
|
|
|
|
// logger init is the first thing that needs to run
|
|
|
|
|
try {
|
|
|
|
|
if (!this.logger) {
|
|
|
|
|
const loggingOptions = {
|
2020-01-30 23:17:43 +01:00
|
|
|
|
isContentScript: true,
|
2020-01-16 01:00:12 +01:00
|
|
|
|
allowLogging: true,
|
2020-01-29 01:36:23 +01:00
|
|
|
|
useConfFromStorage: true,
|
2019-09-03 00:48:18 +02:00
|
|
|
|
fileOptions: {
|
2020-01-29 01:36:23 +01:00
|
|
|
|
enabled: false
|
2019-09-03 00:48:18 +02:00
|
|
|
|
},
|
|
|
|
|
consoleOptions: {
|
2020-02-09 01:13:29 +01:00
|
|
|
|
"enabled": true,
|
|
|
|
|
"debug": true,
|
|
|
|
|
"init": true,
|
|
|
|
|
"settings": true,
|
|
|
|
|
"keyboard": true,
|
|
|
|
|
"mousemove": false,
|
|
|
|
|
"actionHandler": true,
|
|
|
|
|
"comms": true,
|
|
|
|
|
"playerDetect": true,
|
|
|
|
|
"resizer": true,
|
|
|
|
|
"scaler": true,
|
|
|
|
|
"stretcher": true,
|
2020-02-11 19:36:49 +01:00
|
|
|
|
// "videoRescan": true,
|
|
|
|
|
// "playerRescan": true,
|
2020-02-09 01:13:29 +01:00
|
|
|
|
"arDetect": true,
|
|
|
|
|
"arDetect_verbose": true
|
2020-01-28 01:27:30 +01:00
|
|
|
|
},
|
|
|
|
|
allowBlacklistedOrigins: {
|
2020-01-29 01:36:23 +01:00
|
|
|
|
'periodicPlayerCheck': false,
|
|
|
|
|
'periodicVideoStyleChangeCheck': false,
|
|
|
|
|
'handleMouseMove': false
|
2019-09-03 00:48:18 +02:00
|
|
|
|
}
|
2020-01-28 01:27:30 +01:00
|
|
|
|
};
|
2020-02-04 00:56:48 +01:00
|
|
|
|
this.logger = new Logger({vuexStore: this.vuexStore});
|
2020-01-27 22:32:38 +01:00
|
|
|
|
await this.logger.init(loggingOptions);
|
2020-02-04 00:56:48 +01:00
|
|
|
|
|
|
|
|
|
// show popup if logging to file is enabled
|
|
|
|
|
if (this.logger.isLoggingToFile()) {
|
|
|
|
|
console.info('[uw::init] Logging to file is enabled. Will show popup!');
|
|
|
|
|
try {
|
|
|
|
|
this.vuexStore.dispatch('uw-show-logger');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('[uw::init] Failed to open popup!', e)
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-03 00:48:18 +02:00
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error("logger init failed!", e)
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
|
// init() is re-run any time settings change
|
|
|
|
|
if (this.pageInfo) {
|
2019-07-18 21:25:58 +02:00
|
|
|
|
// 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);
|
2018-08-30 00:56:15 +02:00
|
|
|
|
this.pageInfo.destroy();
|
|
|
|
|
}
|
|
|
|
|
if (this.comms) {
|
|
|
|
|
this.comms.destroy();
|
|
|
|
|
}
|
2019-09-03 00:48:18 +02:00
|
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
|
if (!this.settings) {
|
|
|
|
|
var ths = this;
|
2020-02-09 01:16:46 +01:00
|
|
|
|
this.settings = new Settings({
|
|
|
|
|
onSettingsChanged: () => this.reloadSettings(),
|
|
|
|
|
logger: this.logger
|
|
|
|
|
});
|
2018-08-30 00:56:15 +02:00
|
|
|
|
await this.settings.init();
|
2018-06-27 23:55:37 +02:00
|
|
|
|
}
|
2018-08-30 00:56:15 +02:00
|
|
|
|
|
2019-07-18 21:25:58 +02:00
|
|
|
|
this.comms = new CommsClient('content-client-port', this.settings, this.logger);
|
2020-02-04 00:56:48 +01:00
|
|
|
|
|
|
|
|
|
// add showPopup, hidePopup listener to comms
|
|
|
|
|
this.comms.subscribe('show-logger', () => this.showLogger());
|
|
|
|
|
this.comms.subscribe('hide-logger', () => this.hideLogger());
|
2018-08-30 00:56:15 +02:00
|
|
|
|
|
|
|
|
|
// č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
|
|
|
|
|
2018-11-02 21:19:34 +01:00
|
|
|
|
var extensionMode = this.settings.getExtensionMode();
|
|
|
|
|
|
2019-07-18 21:25:58 +02:00
|
|
|
|
this.logger.log('info', 'debug', "[uw::init] Extension mode:" + (extensionMode < 0 ? "disabled" : extensionMode == '1' ? 'basic' : 'full'));
|
2018-11-02 02:52:01 +01:00
|
|
|
|
|
2019-07-03 21:55:08 +02:00
|
|
|
|
const isSiteDisabled = extensionMode === ExtensionMode.Disabled
|
|
|
|
|
|
|
|
|
|
if (isSiteDisabled) {
|
|
|
|
|
if (this.settings.getExtensionMode('@global') === ExtensionMode.Disabled) {
|
2019-07-18 21:25:58 +02:00
|
|
|
|
this.logger.log('info', 'debug', "[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
|
2019-07-03 21:55:08 +02:00
|
|
|
|
return;
|
2018-08-30 00:56:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2019-07-18 21:25:58 +02:00
|
|
|
|
this.pageInfo = new PageInfo(this.comms, this.settings, this.logger, extensionMode, isSiteDisabled);
|
2020-02-03 22:13:03 +01:00
|
|
|
|
this.logger.log('info', 'debug', "[uw.js::setup] pageInfo initialized.");
|
2018-08-30 00:56:15 +02:00
|
|
|
|
this.comms.setPageInfo(this.pageInfo);
|
|
|
|
|
|
2020-02-03 22:13:03 +01:00
|
|
|
|
this.logger.log('info', 'debug', "[uw.js::setup] will try to initate ActionHandler.");
|
2018-11-15 00:18:41 +01:00
|
|
|
|
|
2019-07-03 21:55:08 +02:00
|
|
|
|
// 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);
|
2019-07-03 21:55:08 +02:00
|
|
|
|
this.actionHandler.init();
|
|
|
|
|
|
2020-02-03 22:13:03 +01:00
|
|
|
|
this.logger.log('info', 'debug', "[uw.js::setup] ActionHandler initiated.");
|
2018-11-16 23:02:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-30 00:56:15 +02:00
|
|
|
|
} catch (e) {
|
2019-07-18 21:25:58 +02:00
|
|
|
|
this.logger.log('error', 'debug', "[uw::init] FAILED TO START EXTENSION. Error:", e);
|
2018-08-30 00:56:15 +02:00
|
|
|
|
}
|
2017-12-31 18:26:59 +01:00
|
|
|
|
}
|
2020-01-31 01:03:06 +01:00
|
|
|
|
|
2020-02-02 00:57:54 +01:00
|
|
|
|
initVue() {
|
|
|
|
|
Vue.prototype.$browser = global.browser;
|
|
|
|
|
Vue.use(Vuex);
|
2020-02-04 00:56:48 +01:00
|
|
|
|
this.vuexStore = new Vuex.Store({
|
2020-02-02 00:57:54 +01:00
|
|
|
|
plugins: [VuexWebExtensions({
|
|
|
|
|
persistentStates: [
|
2020-02-04 00:56:48 +01:00
|
|
|
|
'uwLog',
|
|
|
|
|
'showLogger',
|
2020-02-02 00:57:54 +01:00
|
|
|
|
],
|
|
|
|
|
})],
|
|
|
|
|
state: {
|
|
|
|
|
uwLog: '',
|
2020-02-04 00:56:48 +01:00
|
|
|
|
showLogger: false,
|
2020-02-02 00:57:54 +01:00
|
|
|
|
},
|
|
|
|
|
mutations: {
|
|
|
|
|
'uw-set-log'(state, payload) {
|
|
|
|
|
state['uwLog'] = payload;
|
2020-02-04 00:56:48 +01:00
|
|
|
|
},
|
|
|
|
|
'uw-show-logger'(state) {
|
|
|
|
|
state['showLogger'] = true;
|
|
|
|
|
},
|
|
|
|
|
'uw-hide-logger'(state) {
|
|
|
|
|
state['showLogger'] = false;
|
2020-02-02 00:57:54 +01:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
'uw-set-log' ({commit}, payload) {
|
|
|
|
|
commit('uw-set-log', payload);
|
2020-02-04 00:56:48 +01:00
|
|
|
|
},
|
|
|
|
|
'uw-show-logger'({commit}) {
|
|
|
|
|
commit('uw-show-logger');
|
|
|
|
|
},
|
|
|
|
|
'uw-hide-logger'({commit}) {
|
|
|
|
|
commit('uw-hide-logger');
|
2020-02-02 00:57:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-04 00:56:48 +01:00
|
|
|
|
initUi() {
|
2020-01-31 01:03:06 +01:00
|
|
|
|
console.log("CREATING UI");
|
|
|
|
|
const random = Math.round(Math.random() * 69420);
|
|
|
|
|
const uwid = `uw-ui-root-${random}`;
|
|
|
|
|
|
|
|
|
|
const rootDiv = document.createElement('div');
|
|
|
|
|
rootDiv.setAttribute("style", "position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 999999; background-color: #ff0000;");
|
|
|
|
|
rootDiv.setAttribute("id", uwid);
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(rootDiv);
|
2020-02-02 00:57:54 +01:00
|
|
|
|
|
2020-01-31 01:03:06 +01:00
|
|
|
|
new Vue({
|
|
|
|
|
el: `#${uwid}`,
|
|
|
|
|
components: {
|
|
|
|
|
LoggerUi
|
|
|
|
|
},
|
2020-02-04 00:56:48 +01:00
|
|
|
|
store: this.vuexStore,
|
2020-01-31 01:03:06 +01:00
|
|
|
|
render(h) {
|
|
|
|
|
return h('logger-ui');
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-02-04 00:56:48 +01:00
|
|
|
|
|
|
|
|
|
showLogger() {
|
|
|
|
|
this.vuexStore.dispatch('uw-show-logger');
|
|
|
|
|
}
|
|
|
|
|
hideLogger() {
|
|
|
|
|
this.vuexStore.dispatch('uw-hide-logger');
|
|
|
|
|
}
|
2018-05-24 20:50:37 +02:00
|
|
|
|
}
|
2018-08-30 00:56:15 +02:00
|
|
|
|
|
2018-12-30 23:16:09 +01:00
|
|
|
|
var main = new UW();
|
2020-02-02 00:57:54 +01:00
|
|
|
|
main.initVue();
|
2020-02-04 00:56:48 +01:00
|
|
|
|
main.initUi();
|
2018-12-30 23:16:09 +01:00
|
|
|
|
main.init();
|