2017-05-23 21:00:38 +02:00
// Autogenerated using buildext. This file should not be modified — modify source files instead.
//BEGIN included from lib/libopts.js
// setopt, getopt, delopt. Shrani oz. dobi oz. briše stvari iz skladišča
// setopt, getopt, delopt. They set/get/delete stuff from the storage
function setopt ( item ) {
browser . storage . local . set ( item ) ;
}
function getopt ( prop , callback ) {
if ( usebrowser == "chrome" )
browser . storage . local . get ( prop , callback ) ;
else
browser . storage . local . get ( prop ) . then ( callback ) ;
}
function delopt ( item ) {
browser . storage . local . remove ( item ) ;
}
//END included from lib/libopts.js
//BEGIN included from lib/uiutils.js
//END included from lib/uiutils.js
//BEGIN included from conf/sitesconf.js
var UW _SITES = {
youtube : {
enabled : true ,
type : "official" ,
urlRules : [ "youtu" ] ,
player : {
name : "movie_player" ,
isClass : false ,
} ,
iframe : {
name : "player" ,
isClass : false
} ,
ui : {
uiMode : "native" ,
uiconf : {
sampleButton : {
class : "ytp-button ytp-settings-button" ,
index : 0 ,
buttonSizeBase : "x" ,
} ,
uiParent : {
name : "ytp-right-controls" ,
isClass : true ,
insertStrat : "prepend" ,
} ,
uiOffset : {
offsetBy : "10vh" ,
offsetType : "css"
}
}
} ,
autoar _imdb : {
enabled : false
}
} ,
netflix : {
enabled : true ,
type : "official" ,
urlRules : [ "netflix" ] ,
player : {
name : "placeholder" ,
isClass : true ,
} ,
ui : {
uiMode : "native" ,
uiconf : {
sampleButton : {
class : "ytp-button ytp-settings-button" ,
index : 0 ,
buttonSizeBase : "x" ,
} ,
uiParent : {
name : "player-controls-wrapper" ,
isClass : true ,
insertStrat : "append"
} ,
uiOffset : {
offsetBy : "0px" ,
offsetType : "css"
}
}
} ,
autoar _imdb : {
enabled : true ,
title : "player-status-main-title" ,
isClass : true
}
} ,
dummy : {
type : "add new site" ,
urlRules : [ "" ] ,
player : {
name : "" ,
isClass : false ,
} ,
sampleButton : {
class : "ytp-button ytp-settings-button" ,
index : 0 ,
buttonSizeBase : "x" ,
} ,
uiParent : {
name : "" ,
isClass : false ,
insertStrat : "prepend" ,
} ,
autoar _imdb : {
enabled : false
}
}
}
//END included from conf/sitesconf.js
2017-01-21 18:31:47 +01:00
var browser _autodetect = true ;
var usebrowser = "chrome" ;
2017-03-13 20:34:59 +01:00
var debugmsg = true ;
2017-01-21 18:31:47 +01:00
if ( browser _autodetect ) {
2017-03-02 20:06:53 +01:00
if ( typeof browser === "undefined" ) {
if ( chrome ) {
browser = chrome ;
usebrowser = "chrome" ;
2017-01-21 18:31:47 +01:00
}
}
else
usebrowser = "firefox" ;
}
else {
if ( usebrowser == "chrome" )
browser = chrome ;
}
2017-03-15 22:25:38 +01:00
var UW _SITES = { } ;
2017-01-21 18:31:47 +01:00
2016-12-07 23:58:43 +01:00
function showAbout ( ) {
2017-01-19 21:29:54 +01:00
clearPage ( ) ;
2016-12-07 23:58:43 +01:00
2017-01-19 21:29:54 +01:00
document . getElementById ( "about" ) . classList . remove ( "hide" ) ;
2016-12-07 23:58:43 +01:00
document . getElementById ( "tab_about" ) . classList . add ( "tab-selected" ) ;
}
function showShortcuts ( ) {
2017-01-19 21:29:54 +01:00
clearPage ( ) ;
2016-12-07 23:58:43 +01:00
document . getElementById ( "uw_shortcuts" ) . classList . remove ( "hide" ) ;
2017-01-19 21:29:54 +01:00
document . getElementById ( "tab_shortcuts" ) . classList . add ( "tab-selected" ) ;
}
function showGeneralSettings ( ) {
clearPage ( ) ;
document . getElementById ( "general_settings" ) . classList . remove ( "hide" ) ;
document . getElementById ( "tab_general_settings" ) . classList . add ( "tab-selected" ) ;
}
2017-03-02 20:06:53 +01:00
function showSites ( ) {
clearPage ( ) ;
document . getElementById ( "uw_sites" ) . classList . remove ( "hide" ) ;
document . getElementById ( "tab_sites" ) . classList . add ( "tab-selected" ) ;
}
2017-01-19 21:29:54 +01:00
function clearPage ( ) {
// Hide you sections
document . getElementById ( "uw_shortcuts" ) . classList . add ( "hide" ) ;
2016-12-07 23:58:43 +01:00
document . getElementById ( "about" ) . classList . add ( "hide" ) ;
2017-01-19 21:29:54 +01:00
document . getElementById ( "general_settings" ) . classList . add ( "hide" ) ;
2017-03-02 20:06:53 +01:00
document . getElementById ( "uw_sites" ) . classList . add ( "hide" ) ;
2016-12-07 23:58:43 +01:00
2017-01-19 21:29:54 +01:00
// Hide you tabs
document . getElementById ( "tab_shortcuts" ) . classList . remove ( "tab-selected" ) ;
2016-12-07 23:58:43 +01:00
document . getElementById ( "tab_about" ) . classList . remove ( "tab-selected" ) ;
2017-01-19 21:29:54 +01:00
document . getElementById ( "tab_general_settings" ) . classList . remove ( "tab-selected" ) ;
2017-03-02 20:06:53 +01:00
document . getElementById ( "tab_sites" ) . classList . remove ( "tab-selected" ) ;
2016-12-07 23:58:43 +01:00
}
function saveopts ( ) {
2017-01-19 21:29:54 +01:00
var actions = [ "fitw" , "fith" , "reset" , "zoom" , "unzoom" , "ar219" , "ar169" , "ar1610" , "ar43" , "autoar" ] ;
2016-12-07 23:58:43 +01:00
var new _keybinds = { } ;
// Preberemo naš obrazec in iz njega naredimo nov objekt z bližnjicami.
// Let's read our form and make a new object with keybinds.
for ( var i = 0 ; i < actions . length ; i ++ ) {
var action = actions [ i ] ;
var targetAR = "" ;
if ( action == "ar219" ) {
action = "char" ;
targetAR = ( 21 / 9 ) ;
}
if ( action == "ar169" ) {
action = "char" ;
targetAR = ( 16 / 9 ) ;
}
if ( action == "ar1610" ) {
action = "char" ;
targetAR = ( 16 / 10 ) ;
}
if ( action == "ar43" ) {
action = "char" ;
targetAR = ( 4 / 3 ) ;
}
if ( targetAR != "" ) {
var keybind = {
action : action ,
targetAR : targetAR ,
key : document . querySelector ( "#" + actions [ i ] + "_letter" ) . value . toLowerCase ( ) . replace ( /[^a-z0-9]/ , "" ) ,
modifiers : [ ]
}
}
else {
var keybind = {
action : action ,
key : document . querySelector ( "#" + actions [ i ] + "_letter" ) . value . toLowerCase ( ) . replace ( /[^a-z0-9]/ , "" ) ,
modifiers : [ ]
}
}
if ( document . querySelector ( "#" + actions [ i ] + "_ctrl" ) . checked )
keybind . modifiers . push ( "ctrl" ) ;
if ( document . querySelector ( "#" + actions [ i ] + "_alt" ) . checked )
keybind . modifiers . push ( "alt" ) ;
if ( document . querySelector ( "#" + actions [ i ] + "_shift" ) . checked )
keybind . modifiers . push ( "shift" ) ;
new _keybinds [ i ] = keybind ;
}
// Preveriti moramo, da nismo dvema možnostima dodali isto bližnjico.
// We need to check if all keybinds are unique.
var fail = false ;
for ( var i = 0 ; i < actions . length ; i ++ )
document . querySelector ( "#" + actions [ i ] + "_letter" ) . classList . remove ( "dup_keybinds" ) ;
for ( var i = 0 ; i < actions . length ; i ++ ) {
if ( new _keybinds [ i ] . key == "" )
continue ;
for ( var j = i + 1 ; j < actions . length ; j ++ ) {
if ( new _keybinds [ i ] . key == new _keybinds [ j ] . key ) {
if ( compareModifiers ( new _keybinds [ i ] . modifiers , new _keybinds [ j ] . modifiers ) ) {
fail = true ;
document . querySelector ( "#" + actions [ i ] + "_letter" ) . classList . add ( "dup_keybinds" ) ;
document . querySelector ( "#" + actions [ j ] + "_letter" ) . classList . add ( "dup_keybinds" ) ;
}
}
}
}
if ( ! fail ) {
browser . storage . local . set ( { ultrawidify _keybinds : new _keybinds } ) ;
}
}
2017-01-19 21:29:54 +01:00
function saveAutoar ( ) {
setopt ( { ultrawidify _autoar : document . querySelector ( "#enable_autoar" ) . checked } ) ;
}
2017-02-22 13:53:40 +01:00
function saveUI ( ) {
var show _ui = document . querySelector ( "#enable_ui" ) ;
var ui _compact = document . querySelector ( "#enable_ui_compact" ) ;
var optionLine = document . getElementById ( "compact_ui_suboption" ) ;
if ( show _ui . checked ) {
ui _compact . disabled = false ;
optionLine . classList . remove ( "hide" ) ;
setopt ( { ultrawidify _ui : ui _compact . checked ? "compact" : "all" } ) ;
}
else {
ui _compact . disabled = true ;
optionLine . classList . add ( "hide" ) ;
setopt ( { ultrawidify _ui : "none" } ) ;
}
}
2017-01-19 21:29:54 +01:00
2016-12-07 23:58:43 +01:00
function compareModifiers ( a , b ) {
//NOTE: to je precej slab in neprenoslijv način primerjanja dveh tabel, ampak za naš primer deluje dovolj
// dobro, saj 'ctrl' vedno pride pred 'alt' in 'alt' vedno pride pred 'shift' (če se sploh pojavijo).
//NOTE: this is bad and totally unfoolproof practice. In our example comparing arrays the way we do works
// because values ALWAYS appear in the same order: 'ctrl' always appears before 'alt' (or it doesn't
// appear at all). 'alt' always appears before 'shift' (or it doesn't appear at all).
if ( a . length != b . length )
return false ;
var match = true ;
for ( var i = 0 ; i < a . length ; i ++ )
match &= a [ i ] == b [ i ]
return match ;
}
function printerr ( err ) {
console . log ( err ) ;
}
function gotopts ( opts ) {
2017-03-02 20:06:53 +01:00
if ( ! opts . ultrawidify _keybinds ) {
console . log ( "ultrawidify keybinds are undefined. the fuck?" , opts ) ;
return ;
}
2016-12-07 23:58:43 +01:00
var KEYBINDS = Object . keys ( opts . ultrawidify _keybinds ) . map ( function ( key ) { return opts . ultrawidify _keybinds [ key ] ; } ) ;
2017-03-02 20:06:53 +01:00
// google chrome is really the untermensch browse // google chrome is really the untermensch browserr
2017-01-19 21:29:54 +01:00
var actions = [ "fitw" , "fith" , "reset" , "zoom" , "unzoom" , "ar219" , "ar169" , "ar1610" , "ar43" , "autoar" ] ;
2016-12-07 23:58:43 +01:00
for ( var i = 0 ; i < actions . length ; i ++ ) {
document . querySelector ( "#" + actions [ i ] + "_letter" ) . classList . remove ( "dup_keybinds" ) ;
document . querySelector ( "#" + actions [ i ] + "_letter" ) . value = KEYBINDS [ i ] . key ;
for ( var j = 0 ; j < KEYBINDS [ i ] . modifiers . length ; j ++ ) {
if ( KEYBINDS [ i ] . modifiers [ j ] == "ctrl" )
document . querySelector ( "#" + actions [ i ] + "_ctrl" ) . checked = true ;
if ( KEYBINDS [ i ] . modifiers [ j ] == "alt" )
document . querySelector ( "#" + actions [ i ] + "_alt" ) . checked = true ;
if ( KEYBINDS [ i ] . modifiers [ j ] == "shift" )
document . querySelector ( "#" + actions [ i ] + "_shift" ) . checked = true ;
}
}
}
2017-02-22 13:53:40 +01:00
function gotar ( opts ) {
}
function gotui ( opts ) {
var show _ui = document . querySelector ( "#enable_ui" ) ;
var ui _compact = document . querySelector ( "#enable_ui_compact" ) ;
var optionLine = document . getElementById ( "compact_ui_suboption" ) ;
if ( opts . ultrawidify _ui == "all" ) {
show _ui . checked = true ;
ui _compact . checked = false ;
optionLine . classList . remove ( "hide" ) ;
}
else if ( opts . ultrawidify _ui == "compact" ) {
show _ui . checked = true ;
ui _compact . checked = true ;
optionLine . classList . remove ( "hide" ) ;
}
else if ( opts . ultrawidify _ui == "none" ) {
show _ui . checked = false ;
ui _compact . checked = false ;
optionLine . classList . add ( "hide" ) ;
}
}
2017-03-02 20:06:53 +01:00
function gotsites ( opts ) {
var list = document . getElementById ( "uw_sites_list" ) ;
if ( list )
list . remove ( ) ;
var anchor = document . getElementById ( "uw_sites_body" ) ;
2017-05-23 21:00:38 +02:00
// at the top of the list, there is this option to reset site config
resetLink = document . createElement ( "a" ) ;
resetLink . onclick = function ( ) { delopt ( "ultrawidify_siterules" ) ; setopt ( { "ultrawidify_siterules" : UW _SITES } ) ; } ;
resetLink . textContent = "Reset site options to default" ;
anchor . appendChild ( resetLink ) ;
2017-03-02 20:06:53 +01:00
list = document . createElement ( "div" ) ;
list . id = "uw_sites_list" ;
list . className = "uw_sites" ;
anchor . appendChild ( list ) ;
uw _sites = opts . ultrawidify _siterules ;
2017-03-15 22:25:38 +01:00
UW _SITES = uw _sites ;
2017-03-21 21:23:03 +01:00
if ( debugmsg )
console . log ( "uw settings::gotopts | site opts:" , opts ) ;
2017-03-02 20:06:53 +01:00
2017-03-13 20:34:59 +01:00
for ( type in { "official" : 1 , "non-official" : 1 , "custom" : 1 , "add new site" : 1 } ) { // unparalleled laziness!
2017-03-21 21:23:03 +01:00
if ( debugmsg ) {
console . log ( "uw settings::gotopts | adding sites of type" , type ) ;
}
2017-03-02 20:06:53 +01:00
var head = document . createElement ( "div" ) ;
head . className = "sites_header" ;
head . textContent = type . charAt ( 0 ) . toUpperCase ( ) + type . slice ( 1 ) ;
var category _desc = document . createElement ( "div" ) ;
if ( type == "official" ) {
2017-03-14 23:51:03 +01:00
category _desc . innerHTML = "These sites are officially supported by the extension developer. These sites should always work. <small>(Pro tip: if you don't want extension to run on some of the following sites, uncheck the checkbox for that site)</small>" ;
2017-03-02 20:06:53 +01:00
}
else if ( type == "non-official" ) {
category _desc . textContent = "Sites in this category have been contribued by third parties. These sites will probably work, but the developer couldn't test whether they work or not." ;
}
else if ( type == "custom" ) {
category _desc . textContent = "In this section, you can define rules for sites that aren't supported either officially or non-officially. See [todo: link] contributing for details. If you define a custom site, please consider sharing configuration on github (see contributing for details)." ;
}
2017-03-13 20:34:59 +01:00
else if ( type == "add new site" ) {
category _desc . textContent = "Add a custom site by filling the form below." ;
}
2017-03-02 20:06:53 +01:00
list . append ( head ) ;
list . append ( category _desc ) ;
2017-03-13 20:34:59 +01:00
var category _counter = 0 ;
2017-05-23 21:00:38 +02:00
for ( site in uw _sites ) {
2017-03-21 21:23:03 +01:00
if ( debugmsg )
console . log ( "we're at site %s of type %s. We're %s this site." , site , uw _sites [ site ] . type , uw _sites [ site ] . type == type ? "processing" : "ignoring" ) ;
2017-03-02 20:06:53 +01:00
if ( uw _sites [ site ] . type == type ) {
var entry = document . createElement ( "div" ) ;
2017-05-23 21:00:38 +02:00
var header = document . createElement ( "div" ) ;
header . id = site + "_display" ;
header . className = "uw_options_line site_details" ;
2017-03-02 20:06:53 +01:00
var siteTitle = document . createElement ( "div" ) ;
siteTitle . className = "site_name" ;
{
2017-03-15 22:25:38 +01:00
var sitecb = mkcb ( site , uw _sites [ site ] . enabled , "siteEnabled" , true ) ;
var editTitle = mkebox ( site , site , "title" ) ;
2017-03-02 20:06:53 +01:00
editTitle . className = "site_title_ebox" ;
siteTitle . append ( sitecb ) ;
siteTitle . append ( editTitle ) ;
var editBtn = document . createElement ( "div" ) ;
editBtn . textContent = "« edit »" ;
editBtn . className = "inline_button" ;
2017-03-13 20:34:59 +01:00
editBtn . id = site + "_edit_button" ;
editBtn . addEventListener ( "click" , function ( ) { var site = this . id ; site = site . replace ( "_edit_button" , "" ) ; enableEditing ( site ) } ) ;
var saveBtn = document . createElement ( "div" ) ;
saveBtn . textContent = "« save »" ;
saveBtn . className = "inline_button hide" ;
saveBtn . id = site + "_save_button" ;
2017-03-15 22:25:38 +01:00
saveBtn . addEventListener ( "click" , function ( ) { var site = this . id ; site = site . replace ( "_save_button" , "" ) ; saveEdited ( site ) } ) ;
2017-03-02 20:06:53 +01:00
2017-03-13 20:34:59 +01:00
var cancelBtn = document . createElement ( "div" ) ;
cancelBtn . textContent = "« cancel »" ;
cancelBtn . className = "inline_button hide" ;
cancelBtn . id = site + "_cancel_button" ;
2017-03-15 22:25:38 +01:00
cancelBtn . addEventListener ( "click" , function ( ) { var site = this . id ; site = site . replace ( "_cancel_button" , "" ) ; cancelEditing ( site ) } ) ;
2017-03-02 20:06:53 +01:00
siteTitle . append ( editBtn ) ;
2017-03-13 20:34:59 +01:00
siteTitle . append ( saveBtn ) ;
siteTitle . append ( cancelBtn ) ;
2017-03-02 20:06:53 +01:00
}
2017-05-23 21:00:38 +02:00
header . appendChild ( siteTitle ) ;
entry . appendChild ( header ) ;
2017-03-14 23:51:03 +01:00
2017-05-23 21:00:38 +02:00
var body = document . createElement ( "div" ) ;
var jsonForm = document . createElement ( "textarea" ) ;
jsonForm . cols = 64 ;
jsonForm . rows = 32 ;
2017-03-14 23:51:03 +01:00
2017-05-23 21:00:38 +02:00
jsonForm . value = JSON . stringify ( uw _sites [ site ] , null , 2 ) ;
2017-03-02 20:06:53 +01:00
2017-05-23 21:00:38 +02:00
body . appendChild ( jsonForm ) ;
// body.classNamež
entry . appendChild ( body ) ;
2017-03-02 20:06:53 +01:00
list . append ( entry ) ;
2017-03-21 21:23:03 +01:00
2017-05-23 21:00:38 +02:00
category _counter ++ ;
2017-03-02 20:06:53 +01:00
}
}
2017-05-23 21:00:38 +02:00
// for (site in uw_sites){
// if(debugmsg)
// console.log("we're at site %s of type %s. We're %s this site.",site, uw_sites[site].type, uw_sites[site].type == type ? "processing" : "ignoring");
//
// if(uw_sites[site].type == type){
//
// var entry = document.createElement("div");
// var displayedInfo = document.createElement("div");
// displayedInfo.id = site + "_display";
// displayedInfo.className = "uw_options_line site_details";
//
// var siteTitle = document.createElement("div");
// siteTitle.className = "site_name";
//
// {
// var sitecb = mkcb(site, uw_sites[site].enabled, "siteEnabled", true);
// var editTitle = mkebox(site, site, "title");
// editTitle.className = "site_title_ebox";
// siteTitle.append(sitecb);
// siteTitle.append(editTitle);
//
// var editBtn = document.createElement("div");
// editBtn.textContent = "« edit »";
// editBtn.className = "inline_button";
// editBtn.id = site + "_edit_button";
// editBtn.addEventListener("click", function(){ var site = this.id; site = site.replace("_edit_button", ""); enableEditing(site)});
//
// var saveBtn = document.createElement("div");
// saveBtn.textContent = "« save »";
// saveBtn.className = "inline_button hide";
// saveBtn.id = site + "_save_button";
// saveBtn.addEventListener("click", function(){ var site = this.id; site = site.replace("_save_button", ""); saveEdited(site)});
//
// var cancelBtn = document.createElement("div");
// cancelBtn.textContent = "« cancel »";
// cancelBtn.className = "inline_button hide";
// cancelBtn.id = site + "_cancel_button";
// cancelBtn.addEventListener("click", function(){ var site = this.id; site = site.replace("_cancel_button", ""); cancelEditing(site)});
//
// siteTitle.append(editBtn);
// siteTitle.append(saveBtn);
// siteTitle.append(cancelBtn);
// }
//
// var siteDetails = document.createElement("div");
// siteDetails.id = site + "_conf_details";
// siteDetails.classList = "hide";
//
// var urlRules = document.createElement("div");
// {
// var urlRulesLabel = document.createElement("span");
// urlRulesLabel.textContent = "URL rule: ";
//
// urlRulesEbox = mkebox(site, uw_sites[site].urlRules[0], "url_rules");
//
// urlRules.append(urlRulesLabel);
// urlRules.append(urlRulesEbox);
// }
//
// var playerElement = document.createElement("div");
//
// {
// var playerName = document.createElement("div");
//
// var playerNameLabel = document.createElement("span");
//
// playerNameLabel.textContent = "id of the player container:";
// var playerNameEbox = mkebox(site, uw_sites[site].player.name, "player_name");
//
// playerName.append(playerNameLabel);
// playerName.append(playerNameEbox);
//
// var playerClass = document.createElement("div");
// var pcb = document.createElement("input");
// pcb.className = site + "_ebox";
// pcb.type = "checkbox";
// pcb.name = site + "_pccb_name";
// pcb.id = site + "_pccb_id";
// pcb.checked = uw_sites[site].player.isClass;
// pcb.disabled = true;
//
// var pcblabel = document.createElement("span");
// pcblabel.textContent = " Name of the player container is a class";
//
// playerClass.append(pcb);
// playerClass.append(pcblabel);
// playerElement.append(playerName);
// playerElement.append(playerClass);
// }
//
// var iframe_playerName = document.createElement("div");
// var ipn_label = document.createElement("span");
// ipn_label.textContent = "id of the player container when in an iframe:";
// ipn_ebox = mkebox(site, uw_sites[site].iframe ? uw_sites[site].iframe.name : "", "iframe_name");
// iframe_playerName.append(ipn_label);
// iframe_playerName.append(ipn_ebox);
//
// var iframe_playerClass = document.createElement("div");
// var ipc_label = document.createElement("span");
// ipc_label.textContent = " Name of the player container is a class";
// var ipc_cb = mkcb(site, uw_sites[site].iframe ? uw_sites[site].iframe.isClass : false, "iframe_class");
// iframe_playerClass.append(ipc_cb);
// iframe_playerClass.append(ipc_label);
//
//
// var sampleButton = document.createElement("div");
// var sbc = document.createElement("div");
// var sbi = document.createElement("div");
// var sbo = document.createElement("div");
// var sbc_label = document.createElement("span");
// var sbi_label = document.createElement("span");
// var sbo_label = document.createElement("span");
// sbc_label.textContent = "Sample button class:";
// sbi_label.textContent = "Sample button index:";
// sbo_label.textContent = "Use height for UI scaling";
// var sampleButtonClass = mkebox(site, uw_sites[site].sampleButton.class, "sample_button_class");
// var sampleButtonIndex = mkebox(site, uw_sites[site].sampleButton.index, "sample_button_index");
// var buttonSizeBase = mkcb(site, uw_sites[site].sampleButton.buttonSizeBase == "y", "sample_button_size_base");
//
// sbc.append(sbc_label);
// sbc.append(sampleButtonClass);
// sampleButton.append(sbc);
//
// sbi.append(sbi_label);
// sbi.append(sampleButtonIndex);
// sampleButton.append(sbi);
//
// sbo.append(buttonSizeBase);
// sbo.append(sbo_label);
// sampleButton.append(sbo);
//
// var imdbar = document.createElement("div");
// var imdbar_cb = mkcb(site, uw_sites[site].autoar_imdb, "imdbar");
// var imdbar_label = document.createElement("span");
// imdbar_label.textContent = " This site supports automatic aspect ratio detection";
// imdbar.append(imdbar_cb);
// imdbar.append(imdbar_label);
//
// var imdbar_title = document.createElement("div");
// var it_label = document.createElement("span");
// it_label.textContent = "id of the element containing video title:";
// it_ebox = mkebox(site, uw_sites[site].iframe ? uw_sites[site].iframe.name : "", "imdbar_title");
// imdbar_title.append(it_label);
// imdbar_title.append(it_ebox);
//
// var imdbar_class = document.createElement("div");
// var ic_label = document.createElement("span");
// ic_label.textContent = " Name of the title container is a class";
// var ic_cb = mkcb(site, uw_sites[site].iframe ? uw_sites[site].iframe.isClass : false, "imdbar_class");
// imdbar_class.append(ic_cb);
// imdbar_class.append(ic_label);
//
//
//
//
//
// var optionspad = document.createElement("div");
// optionspad.textContent = "-------------";
//
//
// siteDetails.append(urlRules);
// siteDetails.append(playerElement);
// siteDetails.append(optionspad);
// siteDetails.append(iframe_playerName);
// siteDetails.append(iframe_playerClass);
// siteDetails.append(optionspad);
//
// siteDetails.append(sampleButton);
//
// siteDetails.append(imdbar);
// siteDetails.append(imdbar_title);
// siteDetails.append(imdbar_class);
// // siteDetails.append(optionspad);
//
//
// displayedInfo.append(siteTitle);
// displayedInfo.append(siteDetails);
//
// entry.append(displayedInfo);
//
// list.append(entry);
//
// category_counter++;
//
// if(site == "dummy" && type == "add new site"){
// if(debugmsg)
// console.log("uw settings::gotsites | we are adding dummy site");
// enableEditing("dummy");
// document.getElementById("dummy_title_ebox").disabled = false;
// }
// }
// }
2017-03-02 20:06:53 +01:00
if ( ! category _counter ) {
var noEntriesMsg = document . createElement ( "div" ) ;
noEntriesMsg . textContent = "There's no entries in this category yet" ;
noEntriesMsg . classList = "red" ;
list . append ( noEntriesMsg ) ;
}
}
}
2017-03-14 23:51:03 +01:00
function mkebox ( site , value , id ) {
2017-03-02 20:06:53 +01:00
var ebox = document . createElement ( "input" ) ;
ebox . className = "site_details details_ebox " + site + "_ebox" ,
2017-03-14 23:51:03 +01:00
ebox . id = site + "_" + id + "_ebox" ;
2017-03-02 20:06:53 +01:00
ebox . type = "text" ;
ebox . value = value ;
ebox . disabled = true ;
return ebox ;
}
2017-03-14 23:51:03 +01:00
function mkcb ( site , checked , id , forceEnable ) {
2017-03-02 20:06:53 +01:00
var cb = document . createElement ( "input" ) ;
cb . type = "checkbox" ;
cb . name = site + "_cb_name" ;
2017-03-14 23:51:03 +01:00
cb . id = site + "_" + id + "_cb" ;
2017-03-02 20:06:53 +01:00
cb . checked = checked ;
2017-03-15 22:25:38 +01:00
if ( ! forceEnable ) {
2017-03-02 20:06:53 +01:00
cb . disabled = true ;
2017-03-15 22:25:38 +01:00
cb . className = site + "_ebox" ;
}
2017-03-02 20:06:53 +01:00
return cb ;
}
2017-03-13 20:34:59 +01:00
function enableEditing ( site ) {
2017-03-14 23:51:03 +01:00
showSiteDetails ( site ) ;
2017-03-13 20:34:59 +01:00
if ( debugmsg )
console . log ( "uw settings :: enableEditing | enabling editing for" , site ) ;
var formElements = document . getElementsByClassName ( site + "_ebox" ) ;
if ( ! formElements )
return ;
if ( debugmsg )
console . log ( "form elements: " , formElements ) ;
for ( var i = 0 ; i < formElements . length ; i ++ ) {
formElements [ i ] . disabled = false ;
}
var editButton = document . getElementById ( site + "_edit_button" ) ;
if ( editButton )
editButton . classList . add ( "hide" ) ;
else
return ;
try {
document . getElementById ( site + "_save_button" ) . classList . remove ( "hide" ) ;
document . getElementById ( site + "_cancel_button" ) . classList . remove ( "hide" ) ;
} catch ( e ) { } ;
}
function disableEditing ( site ) {
var formElements = document . getElementsByClassName ( site + "_ebox" ) ;
if ( ! formElements )
return ;
for ( var i = 0 ; i < formElements . length ; i ++ ) {
formElements [ i ] . disabled = true ;
}
var editButton = document . getElementById ( site + "_edit_button" ) ;
if ( editButton )
editButton . classList . remove ( "hide" ) ;
else
return ;
try {
document . getElementById ( site + "_save_button" ) . classList . add ( "hide" ) ;
document . getElementById ( site + "_cancel_button" ) . classList . add ( "hide" ) ;
} catch ( e ) { } ;
}
2017-03-15 22:25:38 +01:00
function cancelEditing ( site ) {
2017-03-21 21:23:03 +01:00
if ( site != "dummy" ) {
disableEditing ( site ) ;
hideSiteDetails ( site ) ;
}
2017-03-15 22:25:38 +01:00
setSiteOpts ( site , UW _SITES [ site ] ) ;
}
function saveEdited ( site ) {
2017-03-21 21:23:03 +01:00
console . log ( "uw settings::saveEdited | this is our site:" , site , "is this 'dummy'?" , site == "dummy" ) ;
2017-03-15 22:25:38 +01:00
if ( site == "dummy" ) {
var newsite = getSiteOpts ( site ) ;
newsite . type = "custom" ;
newsite . enabled = true ;
UW _SITES [ document . getElementById ( "dummy_title_ebox" ) . value ] = newsite ;
}
else {
UW _SITES [ site ] = getSiteOpts ( site ) ;
2017-03-21 21:23:03 +01:00
// disableEditing(site);
// hideSiteDetails(site);
2017-03-15 22:25:38 +01:00
}
setopt ( { ultrawidify _siterules : UW _SITES } ) ;
if ( site == "dummy" )
gotsites ( { ultrawidify _siterules : UW _SITES } ) ;
}
2017-03-14 23:51:03 +01:00
function showSiteDetails ( site ) {
try {
document . getElementById ( site + "_conf_details" ) . classList . remove ( "hide" ) ;
} catch ( me _outside _how _about _that ) { }
}
function hideSiteDetails ( site ) {
try {
document . getElementById ( site + "_conf_details" ) . classList . add ( "hide" ) ;
} catch ( me _outside _how _about _that ) { }
}
2017-03-15 22:25:38 +01:00
2017-03-14 23:51:03 +01:00
function getSiteOpts ( site ) {
var newOptions = { } ;
newOptions . urlRules = [ document . getElementById ( site + "_url_rules_ebox" ) . value ] ;
newOptions . player = { } ;
newOptions . player . name = document . getElementById ( site + "_player_name_ebox" ) . value ;
newOptions . player . isClass = document . getElementById ( site + "_pccb_id" ) . checked ;
newOptions . iframe = { } ;
newOptions . iframe . name = document . getElementById ( site + "_iframe_name_ebox" ) . value ;
newOptions . iframe . isClass = document . getElementById ( site + "_iframe_class_cb" ) . checked ;
newOptions . autoar _imdb = { } ;
newOptions . autoar _imdb . enabled = document . getElementById ( site + "_imdbar_cb" ) . value ;
newOptions . autoar _imdb . title = document . getElementById ( site + "_imdbar_title_ebox" ) . value ;
newOptions . autoar _imdb . isClass = document . getElementById ( site + "_imdbar_class_cb" ) . checked ;
return newOptions ;
}
function setSiteOpts ( site , opts ) {
document . getElementById ( site + "_url_rules_ebox" ) . value = opts . urlRules [ 0 ] ;
document . getElementById ( site + "_player_name_ebox" ) . value = opts . player . name ;
document . getElementById ( site + "_pccb_id" ) . checked = opts . player . isClass ;
if ( opts . iframe ) {
document . getElementById ( site + "_iframe_name_ebox" ) . value = opts . iframe . name ;
document . getElementById ( site + "_iframe_class_cb" ) . checked = opts . iframe . isClass ;
}
if ( opts . autoar _imdb ) {
document . getElementById ( site + "_imdbar_cb" ) . checked = opts . autoar _imdb . enabled ;
if ( opts . autoar _imdb . enabled ) {
document . getElementById ( site + "_imdbar_title_ebox" ) . value = opts . autoar _imdb . title ;
document . getElementById ( site + "_imdbar_class_cb" ) . value = opts . autoar _imdb . isClass
}
}
}
2016-12-07 23:58:43 +01:00
function loadopts ( ) {
2017-02-22 13:53:40 +01:00
getopt ( "ultrawidify_keybinds" , gotopts ) ;
// getopt("ultrawidify_autoar", gotar)
getopt ( "ultrawidify_ui" , gotui ) ;
2017-03-02 20:06:53 +01:00
getopt ( "ultrawidify_siterules" , gotsites ) ;
// We build ui for 'site options' here
// buildSites();
2017-03-13 20:34:59 +01:00
2016-12-07 23:58:43 +01:00
}
2017-01-19 21:29:54 +01:00
// page init
2016-12-07 23:58:43 +01:00
document . addEventListener ( "DOMContentLoaded" , loadopts ) ;
document . querySelector ( "#tab_shortcuts" ) . addEventListener ( "click" , showShortcuts ) ;
document . querySelector ( "#tab_about" ) . addEventListener ( "click" , showAbout ) ;
2017-01-19 21:29:54 +01:00
document . querySelector ( "#tab_general_settings" ) . addEventListener ( "click" , showGeneralSettings ) ;
2017-03-02 20:06:53 +01:00
document . querySelector ( "#tab_sites" ) . addEventListener ( "click" , showSites ) ;
2016-12-07 23:58:43 +01:00
document . querySelector ( "#kb_save" ) . addEventListener ( "click" , saveopts ) ;
document . querySelector ( "#kb_cancel" ) . addEventListener ( "click" , loadopts ) ;
2017-01-19 21:29:54 +01:00
document . querySelector ( "#enable_autoar" ) . addEventListener ( "click" , saveAutoar ) ;
2017-02-22 13:53:40 +01:00
document . querySelector ( "#enable_ui" ) . addEventListener ( "click" , saveUI ) ;
document . querySelector ( "#enable_ui_compact" ) . addEventListener ( "click" , saveUI ) ;
2017-01-21 18:31:47 +01:00
getopt ( "ultrawidify_autoar" , function ( obj ) { document . querySelector ( "#enable_autoar" ) . checked = obj . ultrawidify _autoar } ) ;