Browse Source

fixed missing setting crashes js on update interface

master
edoardoo 10 years ago
parent
commit
444515b9cc
2 changed files with 57 additions and 29 deletions
  1. +15
    -2
      main.js
  2. +42
    -27
      preferences/preferences.js

+ 15
- 2
main.js View File

@ -7,6 +7,14 @@ function setupVideoObject(){
};
}
// not actually working:
// function getSetting( setting ){
// var value = "";
// var value = chrome.storage.sync.get( setting, function(obj){
// value = obj[setting];
// });
// return value;
// }
function setLilikLogo(){
jQuery(" header#top-nav a.logo").css({
@ -129,16 +137,21 @@ function nightMode(){
if( hasComments())
setInvertCommentImages();
if( isNightTime() ){
if( isNightTime()){
toggleNight("on");
}
}
function isNightTime(){
var nightHour = 19;
var morningHour = 7;
// if( getSetting("night_mode_starting_hour") ){
// nightHour = getSetting("night_mode_starting_hour");
// console.log(nightHour);
// }
var date = new Date();
var hours = date.getHours();
if( hours >= nightHour || hours <= morningHour)


+ 42
- 27
preferences/preferences.js View File

@ -1,26 +1,35 @@
var settings = [
{
id: "1",
id: "long_post_visualization",
name: "Long Post Visualization",
description: "Select which way you prefer to display long posts",
type: "radio",
options: [ "Sidebar", "In place"]
},{
id: "2",
id: "night_mode_enabler",
name: "Night Mode",
description: "Enable or disable night mode",
type: "checkbox"
},{
id: "3",
id: "night_mode_starting_hour",
name: "Night Mode Starting Hour",
description: "in hours. Ex: 19",
type: "text"
type: "range",
options: {
min: "0",
max: "24"
}
},{
id: "4",
id: "night_mode_ending_hour",
name: "Night Mode Ending Hour",
description: "in hours. Ex: 7",
type: "text"
},
type: "range",
options: {
min: "0",
max: "24"
}
}
];
// var settings = [
@ -136,7 +145,7 @@ function addListeners(){
for (var i = rangeElements.length - 1; i >= 0; i--) {
rangeElements[i].addEventListener('change', function( element ){
var labelIdNumber = this.id.split("_")[1];
var labelIdNumber = this.id.split(/_(.+)?/)[1];
updateRangeValueLabel( labelIdNumber, this.value);
});
};
@ -145,7 +154,7 @@ function addListeners(){
//saves the data into storage
function saveSettings(){
var setting = this.id;
setting = setting.split("_")[1];
setting = setting.split(/_(.+)?/)[1];
var type = this.getAttribute('data-type');
switch (type){
case "checkbox":
@ -184,27 +193,33 @@ function loadSettings( ){
}
function updateSettings( storedSettings ){
for( var settingId in storedSettings ){
settingId = String( settingId );
settingObject = document.getElementById( "setting_"+settingId );
type = settingObject.getAttribute('data-type');
switch( type ){
case ( "checkbox" ):
settingObject.childNodes[1].childNodes[0].checked = storedSettings[settingId];
break;
case ( "radio" ):
document.getElementById( "radio_"+ settingId +"_"+ storedSettings[settingId] ).checked = true;
break;
case "range":
settingObject.childNodes[1].childNodes[0].value = storedSettings[settingId];
updateRangeValueLabel( settingId , storedSettings[settingId] );
break;
case "text":
case "dropdown":
settingObject.childNodes[1].childNodes[0].value = storedSettings[settingId];
break;
settingObject = document.getElementById( "setting_"+settingId );
if( typeof settingObject != "undefined" && settingObject != null){
type = settingObject.getAttribute('data-type');
switch( type ){
case ( "checkbox" ):
settingObject.childNodes[1].childNodes[0].checked = storedSettings[settingId];
break;
case ( "radio" ):
document.getElementById( "radio_"+ settingId +"_"+ storedSettings[settingId] ).checked = true;
break;
case "range":
settingObject.childNodes[1].childNodes[0].value = storedSettings[settingId];
updateRangeValueLabel( settingId , storedSettings[settingId] );
break;
case "text":
case "dropdown":
settingObject.childNodes[1].childNodes[0].value = storedSettings[settingId];
break;
}
}
}


Loading…
Cancel
Save