Files
I2P_in_Private_Browsing_Mod…/privacy.js

243 lines
6.5 KiB
JavaScript
Raw Normal View History

2019-05-02 17:31:11 -04:00
2019-06-29 01:43:16 -04:00
function getChrome() {
if (chrome.runtime.getBrowserInfo == undefined) {
return true
}
return false
}
2019-05-02 17:31:11 -04:00
function onSet(result) {
if (result) {
console.log("->: Value was updated");
} else {
console.log("-X: Value was not updated");
}
}
// This disables queries to centralized databases of bad URLs to screen for
// risky sites in your browser
function disableHyperlinkAuditing() {
2019-06-29 01:43:16 -04:00
if (!getChrome()){
var setting = browser.privacy.websites.hyperlinkAuditingEnabled.set({
value: false
});
console.log("Disabling hyperlink auditing/val=", {
value: false
})
setting.then(onSet);
}
2019-05-02 17:31:11 -04:00
}
// This enables first-party isolation
function enableFirstPartyIsolation() {
2019-06-29 00:32:03 -04:00
if (!getChrome()) {
var setting = browser.privacy.websites.firstPartyIsolate.set({
value: true
});
console.log("Enabling first party isolation/val=", {
value: true
})
setting.then(onSet);
}
2019-05-02 17:31:11 -04:00
}
// This rejects tracking cookies and third-party cookies but it
// LEAVES "Persistent" Cookies unmodified in favor of an option in the content
// interface for now
function disableEvilCookies() {
2019-06-29 00:32:03 -04:00
if (!getChrome()) {
var getting = browser.privacy.websites.cookieConfig.get({});
getting.then((got) => {
var setting = browser.privacy.websites.cookieConfig.set(
{value: {behavior: "reject_third_party",
nonPersistentCookies: got.value.nonPersistentCookies}}
);
console.log("Setting cookie behavior/val=", {value: {behavior: "reject_third_party",
nonPersistentCookies: got.value.nonPersistentCookies}})
setting.then(onSet);
});
}
2019-05-02 17:31:11 -04:00
}
// Make sure that they're gone
/*function disableBadCookies(){
var setting = browser.privacy.websites.thirdPartyCookiesAllowed.set({
value: false
});
console.log("Disabling third party cookies/val=", {
value: false
})
setting.then(onSet);
}*/
// this disables the use of referrer headers
function disableReferrers() {
2019-06-29 01:43:16 -04:00
if (!getChrome()){
2019-06-24 19:20:54 -04:00
var setting = browser.privacy.websites.referrersEnabled.set({
2019-05-02 17:31:11 -04:00
value: false
});
console.log("Disabling referrer headers/val=", {
value: false
})
setting.then(onSet);
2019-06-29 01:43:16 -04:00
}
2019-05-02 17:31:11 -04:00
}
// enable fingerprinting resistent features(letterboxing and stuff)
function enableResistFingerprinting() {
2019-06-29 01:43:16 -04:00
if (!getChrome()){
2019-06-24 19:20:54 -04:00
var setting = browser.privacy.websites.referrersEnabled.set({
2019-05-02 17:31:11 -04:00
value: true
});
console.log("Enabling resist fingerprinting/val=", {
value: true
})
setting.then(onSet);
2019-06-29 01:43:16 -04:00
}
2019-05-02 17:31:11 -04:00
}
// This is essentially a blocklist of clearnet web-sites known to do bad tracking
function enableTrackingProtection() {
2019-06-29 00:32:03 -04:00
if (!getChrome()) {
var setting = browser.privacy.websites.trackingProtectionMode.set({
value: "always"
});
console.log("Enabling tracking protection/val=", {
value: "always"
})
setting.then(onSet);
}
2019-05-02 17:31:11 -04:00
}
// This disables protected content, which is a form of digital restrictions
// management dependent on identifying information
function disableDigitalRestrictionsManagement() {
2019-06-29 01:43:16 -04:00
if (!getChrome()){
2019-05-02 17:31:11 -04:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then((got) => {
if (got.os == "win") {
var setting = browser.privacy.websites.protectedContentEnabled.set({
value: false
});
console.log("Setting Protected Content(Digital Restrictions Management) false/val=", {
value: false
})
setting.then(onSet);
}
});
2019-06-29 01:43:16 -04:00
}
2019-05-02 17:31:11 -04:00
}
function setAllPrivacy() {
disableHyperlinkAuditing()
enableFirstPartyIsolation()
disableEvilCookies()
disableReferrers()
enableTrackingProtection()
enableResistFingerprinting()
disableDigitalRestrictionsManagement()
}
setAllPrivacy()
function ResetPeerConnection(){
2019-06-29 00:32:03 -04:00
if (!getChrome()) {
browser.privacy.network.peerConnectionEnabled.set({value: false});
2019-06-29 01:43:16 -04:00
browser.privacy.network.networkPredictionEnabled.set({value: false});
2019-06-29 00:32:03 -04:00
}
2019-06-29 01:43:16 -04:00
chrome.privacy.network.webRTCIPHandlingPolicy.set({value: "disable_non_proxied_udp"});
2019-05-02 17:31:11 -04:00
console.log("Re-disabled WebRTC")
}
function EnablePeerConnection(){
2019-06-29 00:32:03 -04:00
if (!getChrome()) {
browser.privacy.network.peerConnectionEnabled.set({value: true});
2019-06-29 01:43:16 -04:00
browser.privacy.network.networkPredictionEnabled.set({value: false});
2019-06-29 00:32:03 -04:00
}
2019-06-29 01:43:16 -04:00
chrome.privacy.network.webRTCIPHandlingPolicy.set({value: "disable_non_proxied_udp"});
2019-05-02 17:31:11 -04:00
console.log("Enabled WebRTC")
}
ResetPeerConnection()
function ResetDisableSavePasswords(){
browser.privacy.services.passwordSavingEnabled.set({value: false});
console.log("Re-disabled saved passwords")
}
function EnableSavePasswords(){
browser.privacy.services.passwordSavingEnabled.set({value: true});
console.log("Enabled saved passwords")
}
//ResetDisableSavePasswords()
var defaultSettings = {
since: "forever",
dataTypes: ["history", "downloads", "cache", "cookies", "passwords", "pluginData", "formData", "serviceWorkers"]
};
var appSettings = {
since: "forever",
dataTypes: [""]
};
function onError(e) {
console.error(e);
}
function checkStoredSettings(storedSettings) {
2019-06-19 10:44:03 -04:00
chrome.storage.local.set(appSettings);
2019-05-02 17:31:11 -04:00
}
2019-06-29 01:43:16 -04:00
if (!getChrome()){
const gettingStoredSettings = browser.storage.local.get();
gettingStoredSettings.then(checkStoredSettings, onError);
}
2019-05-02 17:31:11 -04:00
function forgetBrowsingData(storedSettings) {
function getSince(selectedSince) {
if (selectedSince === "forever") {
return 0;
}
const times = {
hour: () => { return 1000 * 60 * 60 },
day: () => { return 1000 * 60 * 60 * 24 },
week: () => { return 1000 * 60 * 60 * 24 * 7}
}
const sinceMilliseconds = times[selectedSince].call();
return Date.now() - sinceMilliseconds;
}
function getTypes(selectedTypes) {
let dataTypes = {};
for (let item of selectedTypes) {
dataTypes[item] = true;
}
return dataTypes;
}
const since = getSince(defaultSettings.since);
const dataTypes = getTypes(defaultSettings.dataTypes);
function notify() {
let dataTypesString = Object.keys(dataTypes).join(", ");
let sinceString = new Date(since).toLocaleString();
browser.notifications.create({
"type": "basic",
"title": "Removed browsing data",
"message": `Removed ${dataTypesString}\nsince ${sinceString}`
});
}
browser.browsingData.remove({since}, dataTypes).then(notify);
setAllPrivacy()
ResetPeerConnection()
2019-06-29 00:32:03 -04:00
2019-05-02 17:31:11 -04:00
}