Started including basic mode
This commit is contained in:
parent
8c4759dbe8
commit
90e512559d
@ -2,6 +2,7 @@ if(Debug.debug)
|
||||
console.log("Loading: ExtensionConf.js");
|
||||
|
||||
var ExtensionConf = {
|
||||
basicExtensionMode: "blacklist",
|
||||
extensionMode: "whitelist", // how should this extension work?
|
||||
// 'blacklist' - work everywhere except blacklist
|
||||
// 'whitelist' - only work on whitelisted sites
|
||||
@ -223,7 +224,8 @@ var ExtensionConf = {
|
||||
//
|
||||
// status, arStatus, statusEmbedded:
|
||||
//
|
||||
// * enabled — always allow
|
||||
// * enabled — always allow, full
|
||||
// * basic — allow, but only the basic version without playerData
|
||||
// * default — allow if default is to allow, block if default is to block
|
||||
// * disabled — never allow
|
||||
//
|
||||
|
@ -1,3 +1,13 @@
|
||||
var ExtensionMode = Object.freeze(
|
||||
{
|
||||
AutoDisabled: -2,
|
||||
Disabled: -1,
|
||||
Default: 0,
|
||||
Basic: 1,
|
||||
Full: 2
|
||||
}
|
||||
);
|
||||
|
||||
class Settings {
|
||||
|
||||
constructor(activeSettings, updateCallback) {
|
||||
@ -177,6 +187,7 @@ class Settings {
|
||||
// status, arStatus, statusEmbedded:
|
||||
//
|
||||
// * enabled — always allow
|
||||
// * basic — only allow fullscreen
|
||||
// * default — allow if default is to allow, block if default is to block
|
||||
// * disabled — never allow
|
||||
|
||||
@ -190,6 +201,49 @@ class Settings {
|
||||
return this.active.sites[site];
|
||||
}
|
||||
|
||||
getExtensionMode(site) {
|
||||
if (!site) {
|
||||
site = window.location.hostname;
|
||||
|
||||
if (!site) {
|
||||
console.log("[Settings::canStartExtension] window.location.hostname is null or undefined:", window.location.hostname)
|
||||
console.log("active settings:", this.active)
|
||||
return ExtensionMode.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// if site-specific settings don't exist for the site, we use default mode:
|
||||
if (! this.active.sites[site]) {
|
||||
if (this.active.extensionMode === "blacklist") {
|
||||
return ExtensionMode.Full;
|
||||
} else {
|
||||
return this.active.basicExtensionMode === "blacklist" ? ExtensionMode.Basic : ExtensionMode.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.active.sites[site].status === 'enabled') {
|
||||
return ExtensionMode.Full;
|
||||
} else if (this.active.sites[site].status === 'basic') {
|
||||
return ExtensionMode.Basic;
|
||||
} else if (this.active.sites[site].status === 'default') {
|
||||
if (this.active.extensionMode === "blacklist") {
|
||||
return ExtensionMode.Full;
|
||||
} else {
|
||||
return this.active.basicExtensionMode === "blacklist" ? ExtensionMode.Basic : ExtensionMode.Disabled;
|
||||
}
|
||||
} else {
|
||||
return ExtensionMode.Disabled;
|
||||
}
|
||||
|
||||
} catch(e){
|
||||
if(Debug.debug){
|
||||
console.log("[Settings.js::canStartExtension] Something went wrong — are settings defined/has init() been called?\nSettings object:", this)
|
||||
}
|
||||
return ExtensionMode.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
canStartExtension(site) {
|
||||
// returns 'true' if extension can be started on a given site. Returns false if we shouldn't run.
|
||||
if (!site) {
|
||||
@ -202,14 +256,14 @@ class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
if (Debug.debug) {
|
||||
// let's just temporarily disable debugging while recursively calling
|
||||
// this function to get extension status on current site without duplo
|
||||
// console logs (and without endless recursion)
|
||||
Debug.debug = false;
|
||||
const cse = this.canStartExtension(site);
|
||||
Debug.debug = true;
|
||||
}
|
||||
// if (Debug.debug) {
|
||||
// // let's just temporarily disable debugging while recursively calling
|
||||
// // this function to get extension status on current site without duplo
|
||||
// // console logs (and without endless recursion)
|
||||
// Debug.debug = false;
|
||||
// const cse = this.canStartExtension(site);
|
||||
// Debug.debug = true;
|
||||
// }
|
||||
try{
|
||||
// if site is not defined, we use default mode:
|
||||
if (! this.active.sites[site]) {
|
||||
|
@ -5,15 +5,21 @@ class VideoData {
|
||||
this.video = video;
|
||||
this.destroyed = false;
|
||||
this.settings = settings;
|
||||
this.pageInfo = pageInfo;
|
||||
this.extensionMode = pageInfo.extensionMode;
|
||||
|
||||
|
||||
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
|
||||
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last)
|
||||
this.player = new PlayerData(this);
|
||||
if (pageInfo.extensionMode === ExtensionMode.Full) {
|
||||
this.player = new PlayerData(this);
|
||||
}
|
||||
this.resizer = new Resizer(this);
|
||||
|
||||
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
|
||||
// player dimensions need to be in:
|
||||
// this.player.dimensions
|
||||
this.pageInfo = pageInfo;
|
||||
|
||||
this.vdid = (Math.random()*100).toFixed();
|
||||
if (Debug.init) {
|
||||
console.log("[VideoData::ctor] Created videoData with vdid", this.vdid);
|
||||
@ -101,7 +107,9 @@ class VideoData {
|
||||
this.paused = false;
|
||||
try {
|
||||
this.resizer.start();
|
||||
this.player.start();
|
||||
if (this.player) {
|
||||
this.player.start();
|
||||
}
|
||||
} catch (e) {
|
||||
if(Debug.debug){
|
||||
console.log("[VideoData.js::resume] cannot resume for reasons. Will destroy videoData. Error here:", e);
|
||||
|
@ -2,13 +2,14 @@ if(Debug.debug)
|
||||
console.log("Loading: PageInfo.js");
|
||||
|
||||
class PageInfo {
|
||||
constructor(comms, settings){
|
||||
constructor(comms, settings, extensionMode){
|
||||
this.hasVideos = false;
|
||||
this.siteDisabled = false;
|
||||
this.videos = [];
|
||||
this.settings = settings;
|
||||
|
||||
this.lastUrl = window.location.href;
|
||||
this.extensionMode = extensionMode;
|
||||
|
||||
this.rescan(RescanReason.PERIODIC);
|
||||
this.scheduleUrlCheck();
|
||||
|
5
js/uw.js
5
js/uw.js
@ -50,7 +50,10 @@ class UW {
|
||||
|
||||
// če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar
|
||||
// If extension is soft-disabled, don't do shit
|
||||
if(! this.settings.canStartExtension()){
|
||||
|
||||
extensionMode = this.settings.getExtensionMode();
|
||||
|
||||
if(extensionMode === ExtensionMode.Disabled){
|
||||
if(Debug.debug) {
|
||||
console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
|
||||
}
|
||||
|
@ -45,7 +45,16 @@
|
||||
<div id="_menu_settings_ext" class="suboption hidden">
|
||||
<p>These settings can be overriden on per-site basis.</p>
|
||||
<div class="row">
|
||||
<span class="label">Enable this extension:</span>
|
||||
<span class="label">Enable this extension:<br/>
|
||||
<small>By default, extension will only work on fullscreen videos.</small></span>
|
||||
<div class="button-row">
|
||||
<a id="_ext_global_options_blacklist" class="button _ext _ext_global_options_basic _blacklist">Always</a>
|
||||
<a id="_ext_global_options_whitelist" class="button _ext _ext_global_options_basic _whitelist">On whitelisted sites</a>
|
||||
<a id="_ext_global_options_disabled" class="button _ext _ext_global_options_basic _disabled" >Never</a>
|
||||
</div>
|
||||
|
||||
<span class="label">Enable advanced mode:<br/>
|
||||
<small>In advanced mode, extension will also try to correct video aspect ratio when not in full screen. Useful for e.g. theater mode on youtube.</small></span>
|
||||
<div class="button-row">
|
||||
<a id="_ext_global_options_blacklist" class="button _ext _ext_global_options _blacklist">Always</a>
|
||||
<a id="_ext_global_options_whitelist" class="button _ext _ext_global_options _whitelist">On whitelisted sites</a>
|
||||
|
Loading…
Reference in New Issue
Block a user