Added incognito mode

This commit is contained in:
2019-01-11 14:50:06 +01:00
parent f76d9ba9cd
commit a0d644469d
10 changed files with 289 additions and 7 deletions

View File

@ -0,0 +1,31 @@
/**
* Incognito mode keyboard catcher
*
* @author Pierre HUBERT
*/
ComunicWeb.components.incognito.keyboard = {
/**
* Initialize incognito mode requests detection
*/
init: function(){
//We need to catch keyboard press to check if F6 key is pressed
window.addEventListener("keydown", function(e){
//Filter key
if(e.keyCode != 117)
return;
//If incognito mode is enabled, disable it
if(ComunicWeb.components.incognito.management.isEnabled())
ComunicWeb.components.incognito.management.setEnabled(false);
//Else we ask user confirmation
else
ComunicWeb.components.incognito.ui.confirmEnable();
});
}
}

View File

@ -0,0 +1,59 @@
/**
* Incognito mode management
*
* @author Pierre HUBERT
*/
ComunicWeb.components.incognito.management = {
/**
* This variable is use to check if incognito mode
* has already be initialized or not
*/
_is_init: false,
/**
* Specify whether incognito mode should be enabled or not
*/
_local_storage_name: "incognito_mode",
/**
* Initialize incognito component
*/
init: function(){
//This code should be run only once
if(this._is_init)
return;
this._is_init = true;
log("Initialize incognito mode");
//Initialize components
ComunicWeb.components.incognito.keyboard.init();
ComunicWeb.components.incognito.ui.init();
},
/**
* Check out whether incognito mode is enabled or not
*
* @return {Boolean} TRUE if incognito mode is enabled / FALSE else
*/
isEnabled: function(){
return localStorage.getItem(this._local_storage_name) === "true";
},
/**
* Update status of incognito mode
*
* @param {Boolean} enable TRUE to enable incognito mode / FALSE else
*/
setEnabled: function(enable){
localStorage.setItem(this._local_storage_name, enable ? "true" : "false");
//Propagate information
SendEvent("incognitoStatusChanged", {
enabled: enable
});
}
}

View File

@ -0,0 +1,97 @@
/**
* Incognito mode management
*
* @author Pierre HUBERT
*/
ComunicWeb.components.incognito.ui = {
/**
* Initialize UI component
*/
init: function(){
//Initialize incognito mode updates detection
document.addEventListener("incognitoStatusChanged", function(e){
ComunicWeb.components.incognito.ui.statusChanged();
})
document.addEventListener("openPage", function(){
ComunicWeb.components.incognito.ui.statusChanged();
});
},
/**
* Show confirmation dialog to enable incognito mode
*/
confirmEnable: function(){
//Ask user confirmation
ComunicWeb.common.messages.confirm(
"Are you sure do you want to enable incognito mode? When this mode is enabled, you can use Comunic while appearing as disconnected for your friends...",
function(confirm){
if(!confirm)
return;
//Enable incognito mode
ComunicWeb.components.incognito.management.setEnabled(true);
});
},
/**
* Function called each time incognito status is updated
*/
statusChanged: function(){
var enabled = ComunicWeb.components.incognito.management.isEnabled();
var incognitoBlock = byId("incognito-block");
//Check if incognito mode is disabled
if(!enabled){
if(incognitoBlock != null)
//Remove incognito block
incognitoBlock.remove();
return;
}
//Nothing has to done if incognito block is already visible
if(incognitoBlock)
return;
//Create incognito block
incognitoBlock = createElem2({
type: "div",
appendTo: document.body,
id: "incognito-block",
});
createElem2({
type: "i",
appendTo: incognitoBlock,
class: "fa fa-user-secret",
});
createElem2({
type: "span",
appendTo: incognitoBlock,
innerHTML: "Incognito mode"
});
var disableLink = createElem2({
type: "span",
appendTo: incognitoBlock,
class: "a",
innerHTML: "Disable"
});
disableLink.addEventListener("click", function(){
ComunicWeb.components.incognito.management.setEnabled(false);
})
}
}