mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Added container specific navigator settings
This commit is contained in:
parent
01b63b356c
commit
cc8ca147b0
8 changed files with 265 additions and 51 deletions
102
lib/navigator.js
102
lib/navigator.js
|
@ -36,38 +36,63 @@
|
|||
changedValues = newValue;
|
||||
});
|
||||
|
||||
|
||||
function getValue(name, stack = []){
|
||||
if (stack.indexOf(name) !== -1){
|
||||
return "[ERROR: loop in property definition]";
|
||||
}
|
||||
stack.push(name);
|
||||
|
||||
switch (name){
|
||||
case "original value":
|
||||
return original[stack[stack.length - 2]];
|
||||
case "random":
|
||||
return String.fromCharCode(Math.floor(65 + 85 * Math.random()));
|
||||
default:
|
||||
if (changedValues.hasOwnProperty(name)){
|
||||
return parseString(changedValues[name], stack.slice());
|
||||
const getValue = function(){
|
||||
function getChangedValues(getCookieStoreId){
|
||||
if (changedValues.contextualIdentities){
|
||||
const cookieStoreId = getCookieStoreId();
|
||||
if (
|
||||
cookieStoreId !== "" &&
|
||||
cookieStoreId !== "firefox-default" &&
|
||||
changedValues.contextualIdentities[cookieStoreId]
|
||||
){
|
||||
return changedValues.contextualIdentities[cookieStoreId];
|
||||
}
|
||||
else {
|
||||
return original[name];
|
||||
return changedValues;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return changedValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
function parseString(string, stack){
|
||||
if (string === "{undefined}"){
|
||||
return undefined;
|
||||
}
|
||||
return string.replace(/{([a-z[\]_. -]*)}/ig, function(m, name){
|
||||
return getValue(name, stack.slice());
|
||||
});
|
||||
}
|
||||
|
||||
return function getValue(name, getCookieStoreId){
|
||||
const changedValues = getChangedValues(getCookieStoreId);
|
||||
|
||||
function getValueInternal(name, stack = []){
|
||||
if (stack.indexOf(name) !== -1){
|
||||
return "[ERROR: loop in property definition]";
|
||||
}
|
||||
stack.push(name);
|
||||
|
||||
switch (name){
|
||||
case "original value":
|
||||
return original[stack[stack.length - 2]];
|
||||
case "random":
|
||||
return String.fromCharCode(Math.floor(65 + 85 * Math.random()));
|
||||
default:
|
||||
if (changedValues.hasOwnProperty(name)){
|
||||
return parseString(changedValues[name], stack.slice());
|
||||
}
|
||||
else {
|
||||
return original[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
function parseString(string, stack){
|
||||
if (string === "{undefined}"){
|
||||
return undefined;
|
||||
}
|
||||
return string.replace(/{([a-z[\]_. -]*)}/ig, function(m, name){
|
||||
return getValueInternal(name, stack.slice());
|
||||
});
|
||||
}
|
||||
return getValueInternal(name);
|
||||
};
|
||||
}();
|
||||
|
||||
scope.getNavigatorValue = function getNavigatorValue(name){
|
||||
return getValue(name);
|
||||
scope.getNavigatorValue = function getNavigatorValue(name, getCookieStoreId){
|
||||
return getValue(name, getCookieStoreId);
|
||||
};
|
||||
|
||||
function changeHTTPHeader(details){
|
||||
|
@ -82,7 +107,9 @@
|
|||
){
|
||||
for (let header of details.requestHeaders){
|
||||
if (header.name.toLowerCase() === "user-agent"){
|
||||
header.value = getValue("userAgent");
|
||||
header.value = getValue("userAgent", function(){
|
||||
return details.cookieStoreId;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -118,5 +145,24 @@
|
|||
scope.unregisterHeaderChange();
|
||||
}
|
||||
});
|
||||
|
||||
if (browser.contextualIdentities && browser.contextualIdentities.onRemoved){
|
||||
logging.message("register contextual navigator identities removal");
|
||||
browser.contextualIdentities.onRemoved.addListener(function(details){
|
||||
logging.message("Contextual navigator identity", details.contextualIdentity.cookieStoreId, "removed.");
|
||||
if (changedValues.contextualIdentities){
|
||||
delete changedValues.contextualIdentities[details.contextualIdentity.cookieStoreId];
|
||||
if (Object.keys(changedValues.contextualIdentities).length === 0){
|
||||
delete changedValues.contextualIdentities;
|
||||
}
|
||||
settings.navigatorDetails = changedValues;
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
logging.error(
|
||||
"Old Firefox does not support browser.contextualIdentities.onRemoved"
|
||||
);
|
||||
}
|
||||
};
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue