2017-09-24 01:54:46 +02:00
// Extension settings are in this file. Site configuration is in Sites.js
// todo: move keybinds here
if ( Debug . debug )
console . log ( "Loading: Settings.js" ) ;
2017-12-29 23:34:40 +01:00
var _se _init = async function ( neverFlushStored ) {
2018-02-01 00:26:16 +01:00
// if(Debug.flushStoredSettings && neverFlushStored === false)
2018-03-10 23:25:30 +01:00
// StorageManager.delopt("uw-settings");
2017-12-29 23:34:40 +01:00
if ( Debug . debug )
console . log ( "[Settings::_se_init()] -------- starting init! ---------" ) ;
var newSettings = await StorageManager . getopt _async ( "uw-settings" ) ;
2018-02-22 22:10:13 +01:00
var uwVersion = browser . runtime . getManifest ( ) . version ;
2017-12-29 23:34:40 +01:00
if ( Debug . debug )
2018-02-01 00:26:16 +01:00
console . log ( "[Settings::_se_init()] settings saved in localstorage are:" , newSettings , " - if that's empty, it's gonna be replaced by this:" , JSON . stringify ( this ) , ")" ) ;
2017-12-29 23:34:40 +01:00
2018-02-01 00:26:16 +01:00
if ( ( Object . keys ( newSettings ) . length === 0 && newSettings . constructor === Object ) ) {
2018-02-02 00:21:29 +01:00
console . log ( "[Settings::_se_init()] replacing settings" ) ;
2018-02-01 00:26:16 +01:00
StorageManager . setopt ( { "uw-settings" : JSON . stringify ( this ) } ) ;
2017-12-29 23:34:40 +01:00
}
else {
2018-02-02 00:21:29 +01:00
var actualSettings = JSON . parse ( newSettings [ "uw-settings" ] ) ;
2018-02-22 22:10:13 +01:00
if ( actualSettings . version === undefined || actualSettings . version != uwVersion ) {
2018-02-26 22:38:17 +01:00
this . version = uwVersion ;
2018-02-22 22:10:13 +01:00
console . log ( "[Settings::_se_init()] extension was updated, replacing settings" ) ;
StorageManager . setopt ( { "uw-settings" : JSON . stringify ( this ) } ) ;
}
2018-02-02 00:21:29 +01:00
if ( Debug . debug )
console . log ( "[Settings::_se_init()] parsed settings:" , actualSettings ) ;
for ( var k in actualSettings )
this [ k ] = actualSettings [ k ] ;
2017-12-29 23:34:40 +01:00
}
if ( Debug . debug )
console . log ( "[Settings::_se_init] settings have been loaded/reloaded. Current state: " , this ) ;
2017-12-17 22:56:07 +01:00
}
2018-02-01 00:26:16 +01:00
var _se _save = function ( settings ) {
2017-12-29 23:34:40 +01:00
StorageManager . delopt ( "uw-settings" ) ;
2018-02-01 00:26:16 +01:00
if ( settings !== undefined ) {
StorageManager . setopt ( { "uw-settings" : JSON . stringify ( settings ) } ) ;
}
else {
StorageManager . setopt ( { "uw-settings" : JSON . stringify ( this ) } ) ;
}
if ( Debug . debug )
console . log ( "[Settings::_se_save()] saving settings:" , JSON . stringify ( settings ) ) ;
2017-12-29 23:34:40 +01:00
}
var _se _reload = function ( ) {
this . init ( true ) ;
}
2018-02-04 17:39:26 +01:00
var _se _isBlacklisted = function ( site ) {
return this . blacklist . indexOf ( site ) > - 1 ;
}
var _se _isWhitelisted = function ( site ) {
return this . whitelist . indexOf ( site ) > - 1 ;
}
2017-12-29 23:34:40 +01:00
var Settings = {
2018-03-10 23:25:30 +01:00
extensionMode : "whitelist" , // how should this extension work?
// 'blacklist' - work everywhere except blacklist
// 'whitelist' - only work on whitelisted sites
// 'disabled' - work nowhere
2017-09-24 01:54:46 +02:00
arDetect : {
2018-03-10 23:25:30 +01:00
mode : "blacklist" , // how should autodetection work?
// 'blacklist' - work by default, problem sites need to be blocked
// 'whitelist' - only work if site has been specifically approved
// 'disabled' - don't work at all
2018-02-15 00:17:58 +01:00
allowedMisaligned : 0.05 , // top and bottom letterbox thickness can differ by this much.
// Any more and we don't adjust ar.
2018-01-02 03:36:29 +01:00
allowedArVariance : 0.075 , // amount by which old ar can differ from the new (1 = 100%)
2018-03-07 23:49:43 +01:00
timer _playing : 30 , // we trigger ar this often (in ms) under this conditions
2017-12-29 23:34:40 +01:00
timer _paused : 3000 ,
2017-12-31 18:26:59 +01:00
timer _error : 3000 ,
2018-02-15 22:59:31 +01:00
timer _minimumTimeout : 5 , // but regardless of above, we wait this many msec before retriggering
2018-03-05 23:55:14 +01:00
hSamples : 640 ,
vSamples : 360 ,
samplingInterval : 10 , // we sample at columns at (width/this) * [ 1 .. this - 1]
2018-02-15 22:59:31 +01:00
blackLevel _default : 10 , // everything darker than 10/255 across all RGB components is considered black by
// default. GlobalVars.blackLevel can decrease if we detect darker black.
2018-03-04 23:07:11 +01:00
blackbarTreshold : 8 , // if pixel is darker than blackLevel + blackbarTreshold, we count it as black
// on 0-255. Needs to be fairly high (8 might not cut it) due to compression
// artifacts in the video itself
2017-12-31 18:26:59 +01:00
staticSampleCols : 9 , // we take a column at [0-n]/n-th parts along the width and sample it
randomSampleCols : 0 , // we add this many randomly selected columns to the static columns
staticSampleRows : 9 , // forms grid with staticSampleCols. Determined in the same way. For black frame checks
2018-02-15 00:17:58 +01:00
guardLine : { // all pixels on the guardline need to be black, or else we trigger AR recalculation
// (if AR fails to be recalculated, we reset AR)
enabled : true ,
ignoreEdgeMargin : 0.20 , // we ignore anything that pokes over the black line this close to the edge
// (relative to width of the sample)
2018-02-22 21:06:57 +01:00
imageTestTreshold : 0.1 , // when testing for image, this much pixels must be over blackbarTreshold
edgeTolerancePx : 3 , // black edge violation is performed this far from reported 'last black pixel'
edgeTolerancePercent : null // unused. same as above, except use % of canvas height instead of pixels
2018-02-15 00:17:58 +01:00
} ,
arSwitchLimiter : { // to be implemented
switches : 2 , // we can switch this many times
period : 2.0 // per this period
2018-02-15 22:59:31 +01:00
} ,
edgeDetection : {
2018-03-08 22:22:42 +01:00
sampleWidth : 8 , // we take a sample this wide for edge detection
detectionTreshold : 4 , // sample needs to have this many non-black pixels to be a valid edge
2018-02-15 22:59:31 +01:00
singleSideConfirmationTreshold : 0.3 , // we need this much edges (out of all samples, not just edges) in order
// to confirm an edge in case there's no edges on top or bottom (other
// than logo, of course)
2018-02-22 21:06:57 +01:00
logoTreshold : 0.15 , // if edge candidate sits with count greater than this*all_samples, it can't be logo
2018-03-03 23:58:29 +01:00
// or watermark.
edgeTolerancePx : 2 , // we check for black edge violation this far from detection point
edgeTolerancePercent : null , // we check for black edge detection this % of height from detection point. unused
middleIgnoredArea : 0.2 , // we ignore this % of canvas height towards edges while detecting aspect ratios
minColsForSearch : 0.5 , // if we hit the edge of blackbars for all but this many columns (%-wise), we don't
// continue with search. It's pointless, because black edge is higher/lower than we
// are now. (NOTE: keep this less than 1 in case we implement logo detection)
edgeTolerancePx : 1 , // tests for edge detection are performed this far away from detected row
2018-02-15 00:17:58 +01:00
}
2017-09-24 01:54:46 +02:00
} ,
arChange : {
samenessTreshold : 0.025 , // if aspect ratios are within 2.5% within each other, don't resize
} ,
miscFullscreenSettings : {
2017-12-29 23:34:40 +01:00
videoFloat : "center"
2017-12-17 22:56:07 +01:00
} ,
2017-12-31 18:26:59 +01:00
colors : {
// criticalFail: "background: #fa2; color: #000"
} ,
2017-12-29 23:34:40 +01:00
init : _se _init ,
save : _se _save ,
reload : _se _reload ,
2017-09-24 01:54:46 +02:00
}