Added incognito mode

This commit is contained in:
Pierre HUBERT 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,23 @@
/**
* Incognito mode stylesheet
*
* @author Pierre HUBERT
*/
#incognito-block {
position: fixed;
left: 10px;
bottom: 54px;
text-align: center;
background-color: #001F3F;
padding: 10px;
color: white;
}
#incognito-block i {
font-size: 200%;
}
#incognito-block span {
display: block;
}

View File

@ -33,6 +33,10 @@ ComunicWeb.common.api = {
}
//Enable incognito mode if required
if(ComunicWeb.components.incognito.management.isEnabled())
params.incognito = true;
//Prepare data to send in request
var count = 0;
var datas = "";
@ -92,6 +96,10 @@ ComunicWeb.common.api = {
}
//Enable incognito mode if required
if(ComunicWeb.components.incognito.management.isEnabled())
data.append("incognito", true);
//Create request
var apiXHR = new XMLHttpRequest();
apiXHR.open("POST", requestURL);

View File

@ -1107,7 +1107,35 @@ var ComunicWeb = {
*/
darkTheme: {
//TODO : implement
}
},
/**
* Incognito mode component
*/
incognito: {
/**
* Keyboard catcher
*/
keyboard: {
//TODO : implement
},
/**
* Incognito management
*/
management: {
//TODO : implement
},
/**
* UI management
*/
ui: {
//TODO : implement
},
},
},
/**

View File

@ -278,6 +278,11 @@ ComunicWeb.common.page = {
//Call the method related to the page
eval(pageInfos.methodHandler + ("(additionnalData, pageTarget);"));
//Propagate information
SendEvent("openPage", {
page: pageURI
});
//Success
return true;
},

View File

@ -48,6 +48,16 @@ ComunicWeb.common.system = {
*/
ComunicWeb.common.langs.initLanguages();
/**
* Initialize incognito mode detection
*/
ComunicWeb.components.incognito.management.init();
/**
* Refresh dark theme mode
*/
ComunicWeb.components.darkTheme.refresh();
/**
* What to do after login refresh
*/
@ -81,11 +91,6 @@ ComunicWeb.common.system = {
}), 25000);
ComunicWeb.common.cacheManager.registerInterval(autoRefresh);
/**
* Refresh dark theme mode
*/
ComunicWeb.components.darkTheme.refresh();
//Success
return true;
},

View File

@ -683,3 +683,21 @@ function ApplySceditorStyle(textarea){
//Apply new styles to body
iframeDOM.body.className += " sceditor-iframe-body";
}
/**
* Send a new javascript event
*
* @param {String} name The name of the event to create
* @param {Object} details Information about the event to create
*/
function SendEvent(name, details){
var event = new CustomEvent(name, {
detail: details,
bubbles: true,
cancelable: false
});
document.dispatchEvent(event);
}

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);
})
}
}

View File

@ -215,6 +215,9 @@ class Dev {
"css/components/notifications/dropdown.css",
"css/components/notifications/ui.css",
//Incognito mode component
"css/components/incognito/ui.css",
//Pages stylesheets
//User Page
"css/pages/userPage/main.css",
@ -425,6 +428,11 @@ class Dev {
//Dark theme component
"js/components/darkTheme.js",
//Incognito mode component
"js/components/incognito/ui.js",
"js/components/incognito/management.js",
"js/components/incognito/keyboard.js",
//User scripts
"js/user/loginTokens.js",
"js/user/userLogin.js",