2018-03-11 00:49:29 +01:00
if ( Debug . debug ) {
console . log ( "Loading: SitesConf.js" ) ;
}
// Nastavitve za posamezno stran
// Config for a given page:
//
// <hostname> : {
// status: <option> // should extension work on this site?
// arStatus: <option> // should we do autodetection on this site?
// statusEmbedded: <option> // should we do autodetection on this site?
// }
//
// Veljavne vrednosti za možnosti
// Valid values for options:
//
// status, arStatus, statusEmbedded:
//
// * whitelisted — always allow
// * follow-global — allow if default is to allow, block if default is to block
// * blacklisted — never allow
//
var _sc _sites = {
"www.youtube.com" : {
status : "whitelisted" , // should extension work on this site?
arStatus : "follow-global" , // should we enable autodetection
statusEmbedded : "whitelisted" , // should extension work for this site when embedded on other sites?
override : false // ignore value localStorage in favour of this
} ,
"netflix.com" : {
status : "whitelisted" ,
arStatus : "blacklisted" ,
statusEmbedded : "whitelisted" ,
override : false
} ,
}
2018-03-10 23:25:30 +01:00
// var _sc_SITES = {
// "vimeo.com" : {
// extraCss: [],
// bannedCss: [],
// nonfsPlayerMod: function(){
// // hack player to take all the width
// $("head").append('<style type="text/css">.uw_forceFullWidth {width: 100% !important} .uw_forceCenter{text-align: center;}</style>');
//
// var e = document.getElementsByClassName("player_outro_area")[0];
// e.classList.add("uw_forceFullWidth");
// e.classList.add("uw_forceCenter");
// e = document.getElementsByClassName("player_container")[0];
// e.classList.add("uw_forceFullWidth");
// e.classList.add("uw_forceCenter");
//
// $("video")[0].style.display = "inline-block";
// },
// fsPlayerMod: function(){
// // hack player to take all the width
// $("head").append('<style type="text/css">.uw_forceFullWidth {width: 100% !important} .uw_forceCenter{text-align: center;}</style>');
//
// var e = document.getElementsByClassName("player_outro_area")[0];
// e.classList.add("uw_forceFullWidth");
// e.classList.add("uw_forceCenter");
// e = document.getElementsByClassName("player_container")[0];
// e.classList.add("uw_forceFullWidth");
// e.classList.add("uw_forceCenter");
//
// $("video")[0].style.display = "inline-block";
// }
// }
// }
2018-03-11 00:49:29 +01:00
var _sc _init = async function ( ) {
var newSettings = await StorageManager . getopt _async ( "uw-siteopts" ) ;
if ( Debug . debug )
console . log ( "[SitesConf::_sc_init()] settings saved in localstorage are:" , newSettings , " - if that's empty, it's gonna be replaced by this:" , JSON . stringify ( _sc _sites ) , ")" ) ;
if ( ( Object . keys ( newSettings ) . length === 0 && newSettings . constructor === Object ) ) {
console . log ( "[SitesConf::_sc_init()] replacing settings" ) ;
StorageManager . setopt ( { "uw-siteopts" : JSON . stringify ( _sc _sites ) } ) ;
}
else {
var actualSettings = JSON . parse ( newSettings [ "uw-siteopts" ] ) ;
if ( Debug . debug )
console . log ( "[SitesConf::_sc_init()] parsed settings:" , actualSettings ) ;
var overrides = 0 ;
for ( var k in actualSettings ) {
// let sites with override=true override saved sites
if ( _sc _sites [ k ] != undefined && _sc _sites [ k ] . override ) {
++ overrides ;
continue ;
}
_sc _sites [ k ] = actualSettings [ k ] ;
}
if ( overrides > 0 )
_sc _save ( ) ;
}
if ( Debug . debug )
console . log ( "[SitesConf::_sc_init()] settings have been loaded/reloaded. Current state: " , this ) ;
2017-10-02 00:27:01 +02:00
}
2018-03-11 00:49:29 +01:00
var _sc _reset = function ( ) {
StoreManager . delopt ( "uw-siteopts" ) ;
2018-03-10 23:25:30 +01:00
_sc _init ( ) ;
}
2018-03-11 00:49:29 +01:00
var _sc _reload = function ( ) {
_sc _init ( ) ;
}
var _sc _save = function ( ) {
2018-03-10 23:25:30 +01:00
StorageManager . delopt ( "uw-siteopts" ) ;
StorageManager . setopt ( { "uw-siteopts" : JSON . stringify ( _sc _sites ) } ) ;
}
2018-03-11 00:49:29 +01:00
var _sc _createEmptySite = function ( ) {
2018-03-10 23:25:30 +01:00
return {
status : "follow-global" ,
arStatus : "follow-global" ,
statusEmbedded : "follow-global" ,
} ;
}
2018-03-11 00:49:29 +01:00
function inIframe ( ) {
try {
return window . self !== window . top ;
} catch ( e ) {
return true ;
}
}
var _sc _isEnabled = function ( site ) {
2018-03-13 23:55:38 +01:00
// console.log(".... — _sc_sites[", site, "].status:", (_sc_sites[site] == undefined ? "<default>" : _sc_sites[site].status), "; ExtensionConf.extensionMode:", ExtensionConf.extensionMode)
2018-03-11 00:49:29 +01:00
if ( inIframe ) {
return _sc _siteEnableEmbedded ( site ) ;
}
return _sc _siteEnabled ( site ) ;
}
var _sc _siteEnabled = function ( site ) {
2018-03-10 23:25:30 +01:00
// če za stran nismo določili načina delovanja, potem storimo privzeto stvar
// if we haven't defined options for a site, we do the default thing
if ( _sc _sites [ site ] == undefined || _sc _sites [ site ] . status == "follow-global" ) {
2018-03-11 18:00:47 +01:00
console . log ( ".... this site is undefined!" ) ;
2018-03-13 23:55:38 +01:00
if ( ExtensionConf . extensionMode == "blacklist" ) {
2018-03-10 23:25:30 +01:00
return true ;
}
return false ;
}
2017-10-02 00:27:01 +02:00
2018-03-10 23:25:30 +01:00
if ( _sc _sites [ site ] . status == "whitelisted" )
return true ;
2017-10-02 00:27:01 +02:00
2018-03-10 23:25:30 +01:00
if ( _sc _sites [ site ] . status == "blacklisted" )
return false ;
// sem ne bi smeli priti, vendar pa za varnost naredimo en return
// we shouldn't come here but let's do a safety return
return false ;
}
2018-03-11 18:00:47 +01:00
var _sc _siteStatus = function ( site ) {
if ( _sc _sites [ site ] == undefined )
return "follow-global" ;
return _sc _sites [ site ] . status ;
}
2018-03-11 00:49:29 +01:00
var _sc _arEnabled = function ( site ) {
2018-03-10 23:25:30 +01:00
if ( _sc _sites [ site ] == undefined || _sc _sites [ site ] . arStatus == "follow-global" ) {
2018-03-13 23:55:38 +01:00
if ( ExtensionConf . extensionMode == "blacklist" ) {
2018-03-10 23:25:30 +01:00
return true ;
}
return false ;
}
2017-10-02 00:27:01 +02:00
2018-03-10 23:25:30 +01:00
if ( _sc _sites [ site ] . arStatus == "whitelisted" )
return true ;
2017-10-02 00:27:01 +02:00
2018-03-10 23:25:30 +01:00
if ( _sc _sites [ site ] . arStatus == "blacklisted" )
return false ;
2017-10-02 00:27:01 +02:00
}
2018-03-11 18:00:47 +01:00
var _sc _arStatus = function ( site ) {
if ( _sc _sites [ site ] == undefined )
return "follow-global" ;
return _sc _sites [ site ] . arStatus ;
}
2018-03-11 00:49:29 +01:00
var _sc _siteEnableEmbedded = function ( site ) {
if ( _sc _sites [ site ] == undefined || _sc _sites [ site ] . statusEmbedded == "follow-global" ) {
2018-03-14 21:19:15 +01:00
if ( Debug . debug )
console . log ( "[SitesConf::_sc_siteEnableEmbedded] site" , site , "is not defined in settings." ) ;
2018-03-11 18:00:47 +01:00
2018-03-13 23:55:38 +01:00
if ( ExtensionConf . extensionMode == "blacklist" ) {
2018-03-11 00:49:29 +01:00
return true ;
}
return false ;
}
if ( _sc _sites [ site ] . statusEmbedded == "whitelisted" )
return true ;
if ( _sc _sites [ site ] . statusEmbedded == "blacklisted" )
return false ;
}
var _sc _updateSiteStatus = function ( site , status ) {
2018-03-10 23:25:30 +01:00
// status: {}
// status.status - optional
// status.arStatus - optional
// status.statusEmbedded - optional
//
// <==[ Valid values for options: ]==>
//
// status, arStatus, statusEmbedded:
//
// * whitelisted — always allow
// * follow-global — allow if default is to allow, block if default is to block
// * blacklisted — never allow
2017-10-02 00:27:01 +02:00
2018-03-10 23:25:30 +01:00
if ( _sc _sites [ site ] == undefined ) {
_sc _sites [ site ] = _sc _createEmptySite ( ) ;
}
2017-10-02 00:27:01 +02:00
2018-03-10 23:25:30 +01:00
if ( status . status != undefined ) {
_sc _sites [ site ] . status = status . status ;
}
if ( status . arStatus != undefined ) {
_sc _sites [ site ] . arStatus = status . arStatus ;
}
if ( status . statusEmbedded != undefined ) {
_sc _sites [ site ] . statusEmbedded = status . statusEmbedded ;
}
2017-10-02 00:27:01 +02:00
2018-03-10 23:25:30 +01:00
_sc _save ( ) ;
2017-12-02 21:09:08 +01:00
}
2017-10-02 00:27:01 +02:00
var SitesConf = {
2018-03-10 23:25:30 +01:00
siteopts : _sc _sites ,
2017-12-17 22:56:07 +01:00
init : _sc _init ,
2018-03-11 00:49:29 +01:00
reset : _sc _reset ,
reload : _sc _reload ,
save : _sc _save ,
updateSiteStatus : _sc _updateSiteStatus ,
2018-03-11 18:00:47 +01:00
updateSite : _sc _updateSiteStatus ,
getSiteStatus : _sc _siteStatus ,
getArStatus : _sc _arStatus ,
2018-03-11 00:49:29 +01:00
siteEnabled : _sc _siteEnabled ,
isEnabled : _sc _isEnabled ,
siteEnableEmbedded : _sc _siteEnableEmbedded ,
arEnabled : _sc _arEnabled ,
isArEnabled : _sc _arEnabled
2017-10-02 00:27:01 +02:00
}