Started including basic mode

This commit is contained in:
Tamius Han 2018-11-02 02:52:01 +01:00
parent 8c4759dbe8
commit 90e512559d
6 changed files with 92 additions and 15 deletions

View File

@ -2,6 +2,7 @@ if(Debug.debug)
console.log("Loading: ExtensionConf.js"); console.log("Loading: ExtensionConf.js");
var ExtensionConf = { var ExtensionConf = {
basicExtensionMode: "blacklist",
extensionMode: "whitelist", // how should this extension work? extensionMode: "whitelist", // how should this extension work?
// 'blacklist' - work everywhere except blacklist // 'blacklist' - work everywhere except blacklist
// 'whitelist' - only work on whitelisted sites // 'whitelist' - only work on whitelisted sites
@ -223,7 +224,8 @@ var ExtensionConf = {
// //
// status, arStatus, statusEmbedded: // 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 // * default — allow if default is to allow, block if default is to block
// * disabled — never allow // * disabled — never allow
// //

View File

@ -1,3 +1,13 @@
var ExtensionMode = Object.freeze(
{
AutoDisabled: -2,
Disabled: -1,
Default: 0,
Basic: 1,
Full: 2
}
);
class Settings { class Settings {
constructor(activeSettings, updateCallback) { constructor(activeSettings, updateCallback) {
@ -177,6 +187,7 @@ class Settings {
// status, arStatus, statusEmbedded: // status, arStatus, statusEmbedded:
// //
// * enabled — always allow // * enabled — always allow
// * basic — only allow fullscreen
// * default — allow if default is to allow, block if default is to block // * default — allow if default is to allow, block if default is to block
// * disabled — never allow // * disabled — never allow
@ -190,6 +201,49 @@ class Settings {
return this.active.sites[site]; 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) { canStartExtension(site) {
// returns 'true' if extension can be started on a given site. Returns false if we shouldn't run. // returns 'true' if extension can be started on a given site. Returns false if we shouldn't run.
if (!site) { if (!site) {
@ -202,14 +256,14 @@ class Settings {
} }
} }
if (Debug.debug) { // if (Debug.debug) {
// let's just temporarily disable debugging while recursively calling // // let's just temporarily disable debugging while recursively calling
// this function to get extension status on current site without duplo // // this function to get extension status on current site without duplo
// console logs (and without endless recursion) // // console logs (and without endless recursion)
Debug.debug = false; // Debug.debug = false;
const cse = this.canStartExtension(site); // const cse = this.canStartExtension(site);
Debug.debug = true; // Debug.debug = true;
} // }
try{ try{
// if site is not defined, we use default mode: // if site is not defined, we use default mode:
if (! this.active.sites[site]) { if (! this.active.sites[site]) {

View File

@ -5,15 +5,21 @@ class VideoData {
this.video = video; this.video = video;
this.destroyed = false; this.destroyed = false;
this.settings = settings; this.settings = settings;
this.pageInfo = pageInfo;
this.extensionMode = pageInfo.extensionMode;
// POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji) // POZOR: VRSTNI RED JE POMEMBEN (arDetect mora bit zadnji)
// NOTE: ORDERING OF OBJ INITIALIZATIONS IS IMPORTANT (arDetect needs to go last) // 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.resizer = new Resizer(this);
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting
// player dimensions need to be in: // player dimensions need to be in:
// this.player.dimensions // this.player.dimensions
this.pageInfo = pageInfo;
this.vdid = (Math.random()*100).toFixed(); this.vdid = (Math.random()*100).toFixed();
if (Debug.init) { if (Debug.init) {
console.log("[VideoData::ctor] Created videoData with vdid", this.vdid); console.log("[VideoData::ctor] Created videoData with vdid", this.vdid);
@ -101,7 +107,9 @@ class VideoData {
this.paused = false; this.paused = false;
try { try {
this.resizer.start(); this.resizer.start();
this.player.start(); if (this.player) {
this.player.start();
}
} catch (e) { } catch (e) {
if(Debug.debug){ if(Debug.debug){
console.log("[VideoData.js::resume] cannot resume for reasons. Will destroy videoData. Error here:", e); console.log("[VideoData.js::resume] cannot resume for reasons. Will destroy videoData. Error here:", e);

View File

@ -2,13 +2,14 @@ if(Debug.debug)
console.log("Loading: PageInfo.js"); console.log("Loading: PageInfo.js");
class PageInfo { class PageInfo {
constructor(comms, settings){ constructor(comms, settings, extensionMode){
this.hasVideos = false; this.hasVideos = false;
this.siteDisabled = false; this.siteDisabled = false;
this.videos = []; this.videos = [];
this.settings = settings; this.settings = settings;
this.lastUrl = window.location.href; this.lastUrl = window.location.href;
this.extensionMode = extensionMode;
this.rescan(RescanReason.PERIODIC); this.rescan(RescanReason.PERIODIC);
this.scheduleUrlCheck(); this.scheduleUrlCheck();

View File

@ -50,7 +50,10 @@ class UW {
// če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar // če smo razširitev onemogočili v nastavitvah, ne naredimo ničesar
// If extension is soft-disabled, don't do shit // If extension is soft-disabled, don't do shit
if(! this.settings.canStartExtension()){
extensionMode = this.settings.getExtensionMode();
if(extensionMode === ExtensionMode.Disabled){
if(Debug.debug) { if(Debug.debug) {
console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED") console.log("[uw::init] EXTENSION DISABLED, THEREFORE WONT BE STARTED")
} }

View File

@ -45,7 +45,16 @@
<div id="_menu_settings_ext" class="suboption hidden"> <div id="_menu_settings_ext" class="suboption hidden">
<p>These settings can be overriden on per-site basis.</p> <p>These settings can be overriden on per-site basis.</p>
<div class="row"> <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"> <div class="button-row">
<a id="_ext_global_options_blacklist" class="button _ext _ext_global_options _blacklist">Always</a> <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> <a id="_ext_global_options_whitelist" class="button _ext _ext_global_options _whitelist">On whitelisted sites</a>