Files
I2P_in_Private_Browsing_Mod…/privacy.js

512 lines
13 KiB
JavaScript
Raw Normal View History

2022-10-24 19:57:51 -04:00
var titlepref = chrome.i18n.getMessage("titlePreface");
2019-05-02 17:31:11 -04:00
function onSet(result) {
2022-10-07 19:32:52 -04:00
if (result) {
2022-10-24 19:57:51 -04:00
console.log("->: Value was updated");
2022-10-07 19:32:52 -04:00
} else {
2022-10-24 19:57:51 -04:00
console.log("-X: Value was not updated");
2022-10-07 19:32:52 -04:00
}
2019-05-02 17:31:11 -04:00
}
/* This disables queries to centralized databases of bad URLs to screen for
risky sites in your browser */
2019-05-02 17:31:11 -04:00
function disableHyperlinkAuditing() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.hyperlinkAuditingEnabled.set({
2022-10-24 19:57:51 -04:00
value: false,
2022-10-07 19:32:52 -04:00
});
2022-10-24 19:57:51 -04:00
console.log("Disabling hyperlink auditing/val=", {
value: false,
2022-10-07 19:32:52 -04:00
});
setting.then(onSet);
2019-05-02 17:31:11 -04:00
}
// UNINSTALL ONLY
function enableHyperlinkAuditing() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.hyperlinkAuditingEnabled.clear();
2022-10-24 19:57:51 -04:00
console.log("Disabling hyperlink auditing/val=", {
value: false,
2022-10-07 19:32:52 -04:00
});
setting.then(onSet);
}
2019-05-02 17:31:11 -04:00
// This enables first-party isolation
function enableFirstPartyIsolation() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.firstPartyIsolate.set({
2022-10-24 19:57:51 -04:00
value: true,
2022-10-07 19:32:52 -04:00
});
2022-10-24 19:57:51 -04:00
console.log("Enabling first party isolation/val=", {
value: true,
2022-10-07 19:32:52 -04:00
});
setting.then(onSet);
2019-05-02 17:31:11 -04:00
}
// UNINSTALL ONLY
function disableFirstPartyIsolation() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.firstPartyIsolate.clear();
2022-10-24 19:57:51 -04:00
console.log("Enabling first party isolation/val=", {
value: true,
2022-10-07 19:32:52 -04:00
});
setting.then(onSet);
}
/* 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 */
2019-05-02 17:31:11 -04:00
function disableEvilCookies() {
2022-10-07 19:32:52 -04:00
var getting = browser.privacy.websites.cookieConfig.get({});
getting.then((got) => {
var setting = browser.privacy.websites.cookieConfig.set({
value: {
2022-10-24 19:57:51 -04:00
behavior: "reject_third_party",
nonPersistentCookies: got.value.nonPersistentCookies,
},
2022-10-07 19:32:52 -04:00
});
2022-10-24 19:57:51 -04:00
console.log("Setting cookie behavior/val=", {
2022-10-07 19:32:52 -04:00
value: {
2022-10-24 19:57:51 -04:00
behavior: "reject_third_party",
nonPersistentCookies: got.value.nonPersistentCookies,
},
2019-10-28 01:11:16 -04:00
});
2022-10-07 19:32:52 -04:00
setting.then(onSet);
});
2019-05-02 17:31:11 -04:00
}
2020-12-09 20:53:15 -05:00
function enableEvilCookies() {
2022-10-07 19:32:52 -04:00
var getting = browser.privacy.websites.cookieConfig.clear();
2020-12-09 20:53:15 -05:00
}
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() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.referrersEnabled.set({
value: false,
});
console.log("Disabling referrer headers/val=", {
value: false,
});
setting.then(onSet);
2019-05-02 17:31:11 -04:00
}
// UNINSATALL ONLY
function enableReferrers() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.referrersEnabled.clear();
console.log("Disabling referrer headers/val=", {
value: false,
});
setting.then(onSet);
}
2019-05-02 17:31:11 -04:00
// enable fingerprinting resistent features(letterboxing and stuff)
function enableResistFingerprinting() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.resistFingerprinting.set({
value: true,
});
console.log("Enabling resist fingerprinting/val=", {
value: true,
});
setting.then(onSet);
2019-05-02 17:31:11 -04:00
}
// UNINSTALL ONLY
function disableResistFingerprinting() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.resistFingerprinting.clear();
console.log("Enabling resist fingerprinting/val=", {
value: false,
});
setting.then(onSet);
}
2019-05-02 17:31:11 -04:00
// This is essentially a blocklist of clearnet web-sites known to do bad tracking
function enableTrackingProtection() {
2022-10-07 19:32:52 -04:00
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
}
// UNINSTALL ONLY
function disableTrackingProtection() {
2022-10-07 19:32:52 -04:00
var setting = browser.privacy.websites.trackingProtectionMode.clear();
console.log("Enabling tracking protection/val=", {
value: "always",
});
setting.then(onSet);
}
/* This disables protected content, which is a form of digital restrictions
management dependent on identifying information */
2019-05-02 17:31:11 -04:00
function disableDigitalRestrictionsManagement() {
2022-10-07 19:32:52 -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,
2019-10-28 01:11:16 -04:00
}
2022-10-07 19:32:52 -04:00
);
setting.then(onSet);
}
});
2019-05-02 17:31:11 -04:00
}
// UNINSTALL ONLY
function disableDigitalRestrictionsManagement() {
2022-10-07 19:32:52 -04:00
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then((got) => {
if (got.os == "win") {
var setting = browser.privacy.websites.protectedContentEnabled.clear();
console.log(
"Setting Protected Content(Digital Restrictions Management) false/val=",
{
value: true,
}
2022-10-07 19:32:52 -04:00
);
setting.then(onSet);
}
});
}
function unsetAllPrivacy() {
2022-10-07 19:32:52 -04:00
enableHyperlinkAuditing();
disableFirstPartyIsolation();
enableEvilCookies();
enableReferrers();
disableTrackingProtection();
disableResistFingerprinting();
enableDigitalRestrictionsManagement();
UnsetPeerConnection();
EnableSavePasswords();
}
browser.management.onUninstalled.addListener((info) => {
2022-10-07 19:32:52 -04:00
function gotSelf(selfinfo) {
if (info.name == selfinfo.name) {
unsetAllPrivacy();
}
2022-10-07 19:32:52 -04:00
}
var gettingSelf = browser.management.getSelf();
gettingSelf.then(gotSelf);
});
2019-05-02 17:31:11 -04:00
function setAllPrivacy() {
2022-10-07 19:32:52 -04:00
disableHyperlinkAuditing();
enableFirstPartyIsolation();
disableEvilCookies();
disableReferrers();
enableTrackingProtection();
enableResistFingerprinting();
disableDigitalRestrictionsManagement();
2019-05-02 17:31:11 -04:00
}
2019-10-06 15:18:10 -04:00
setAllPrivacy();
2019-05-02 17:31:11 -04:00
function ResetPeerConnection() {
2022-10-07 19:32:52 -04:00
function reset(snowflake) {
var webrtc = true;
console.log("No snowflake plugin found, pre-disabled WebRTC");
var rtc = browser.privacy.network.peerConnectionEnabled.set({
value: webrtc,
});
rtc.then(AssurePeerConnection);
}
function snowflake(snowflake) {
console.log("snowflake plugin found, leaving WebRTC alone", snowflake);
AssurePeerConnection();
}
var snowflakeInfo = browser.management.get(
"{b11bea1f-a888-4332-8d8a-cec2be7d24b9}" // string
);
snowflakeInfo.then(snowflake, reset);
2019-05-02 17:31:11 -04:00
}
function AssurePeerConnection() {
2022-10-07 19:32:52 -04:00
function assure(webrtc) {
browser.privacy.network.peerConnectionEnabled.set({
value: true,
});
chrome.privacy.network.webRTCIPHandlingPolicy.set({
value: "disable_non_proxied_udp",
});
}
let rtc = browser.privacy.network.peerConnectionEnabled.get({});
rtc.then(assure);
}
// UNINSTALL ONLY
function UnsetPeerConnection() {
2022-10-07 19:32:52 -04:00
function assure(webrtc) {
browser.privacy.network.peerConnectionEnabled.set({
value: true,
});
chrome.privacy.network.webRTCIPHandlingPolicy.set({
value: "default",
});
}
let rtc = browser.privacy.network.peerConnectionEnabled.get({});
rtc.then(assure);
}
var gettingInfo = browser.runtime.getPlatformInfo();
2020-11-10 21:48:08 -05:00
gettingInfo.then((got) => {
2022-10-07 19:32:52 -04:00
if (got.os == "android") {
browser.tabs.onCreated.addListener(ResetPeerConnection);
} else {
browser.windows.onCreated.addListener(ResetPeerConnection);
}
});
//AssurePeerConnection();
2019-05-02 17:31:11 -04:00
function ResetDisableSavePasswords() {
2022-10-07 19:32:52 -04:00
browser.privacy.services.passwordSavingEnabled.set({
value: false,
});
console.log("Re-disabled saved passwords");
2019-05-02 17:31:11 -04:00
}
function EnableSavePasswords() {
2022-10-07 19:32:52 -04:00
browser.privacy.services.passwordSavingEnabled.clear();
console.log("Enabled saved passwords");
2019-05-02 17:31:11 -04:00
}
//ResetDisableSavePasswords()
var defaultSettings = {
2022-10-07 19:32:52 -04:00
since: "forever",
dataTypes: ["downloads", "passwords", "formData", "localStorage", "history"],
2019-05-02 17:31:11 -04:00
};
function onError(therror) {
2022-10-07 19:32:52 -04:00
console.error(therror);
2019-05-02 17:31:11 -04:00
}
function forgetBrowsingData(storedSettings) {
2022-10-07 19:32:52 -04:00
function getSince(selectedSince) {
if (selectedSince === "forever") {
return 0;
2019-05-02 17:31:11 -04:00
}
2022-10-07 19:32:52 -04:00
const times = {
hour: () => 1000 * 60 * 60,
day: () => 1000 * 60 * 60 * 24,
week: () => 1000 * 60 * 60 * 24 * 7,
};
2022-10-07 19:32:52 -04:00
const sinceMilliseconds = times[selectedSince].call();
return Date.now() - sinceMilliseconds;
}
2022-10-07 19:32:52 -04:00
function getTypes(selectedTypes) {
let dataTypes = {};
for (let item of selectedTypes) {
dataTypes[item] = true;
}
2022-10-07 19:32:52 -04:00
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}\n for I2P Browsing`,
});
}
function deepCleanHistory(historyItems) {
console.log("Deep cleaning history");
for (let item of historyItems) {
if (i2pCheck(item.url)) {
browser.history.deleteUrl({
url: item.url,
});
browser.browsingData.removeCache({});
console.log("cleared Cache");
browser.browsingData
.removePasswords({
hostnames: [i2pHostName(item.url)],
since,
})
.then(onContextGotLog);
console.log("cleared Passwords");
browser.browsingData
.removeDownloads({
hostnames: [i2pHostName(item.url)],
since,
})
.then(onContextGotLog);
console.log("cleared Downloads");
browser.browsingData
.removeFormData({
hostnames: [i2pHostName(item.url)],
since,
})
.then(onContextGotLog);
console.log("cleared Form Data");
browser.browsingData
.removeLocalStorage({
hostnames: [i2pHostName(item.url)],
since,
})
.then(onContextGotLog);
console.log("cleared Local Storage");
let contexts = browser.contextualIdentities.query({
name: titlepref,
});
2022-10-07 19:32:52 -04:00
function deepCleanCookies(cookies) {
for (let cookie of cookies) {
var removing = browser.cookies.remove({
firstPartyDomain: cookie.firstPartyDomain,
name: cookie.name,
url: item.url,
});
removing.then(onContextGotLog, onError);
}
console.log("Cleared cookies");
2022-10-07 13:26:09 -04:00
}
2022-10-07 19:32:52 -04:00
function deepCleanContext(cookieStoreIds) {
for (let cookieStoreId of cookieStoreIds) {
var removing = browser.cookies.getAll({
firstPartyDomain: null,
storeId: cookieStoreId.cookieStoreId,
});
removing.then(deepCleanCookies, onError);
}
}
contexts.then(deepCleanContext, onError);
}
2022-10-07 13:26:09 -04:00
}
2022-10-07 19:32:52 -04:00
notify();
}
2022-10-07 13:26:09 -04:00
2022-10-07 19:32:52 -04:00
var searching = browser.history.search({
text: "i2p",
startTime: 0,
});
2022-10-07 19:32:52 -04:00
searching.then(deepCleanHistory);
2019-06-29 00:32:03 -04:00
2022-10-07 19:32:52 -04:00
setAllPrivacy();
ResetPeerConnection();
2019-05-02 17:31:11 -04:00
}
2019-07-10 02:29:38 -04:00
function i2pHostName(url) {
2022-10-07 19:32:52 -04:00
let hostname = "";
console.log("(hosts)", url);
let u = new URL(url);
if (u.host.endsWith(".i2p")) {
hostname = u.host;
} else if (url.includes("=")) {
if (url.includes(".i2p")) {
lsit = url.split("=");
for (let item in lsit) {
var items = lsit[item].split(`\ % `); //"\%")
for (let p in items) {
if (items[p].includes(".i2p")) {
hostname = items[p].replace("3D", 1);
}
break;
}
if (hostname != "") {
break;
2020-12-05 23:43:37 -05:00
}
2022-10-07 19:32:52 -04:00
}
2020-12-05 23:43:37 -05:00
}
2022-10-07 19:32:52 -04:00
} else if (url.indexOf("://") > -1) {
hostname = url.split("/")[2];
} else {
hostname = url.split("/")[0];
}
return hostname;
}
2022-10-07 13:26:09 -04:00
function i2pCheck(url) {
2022-10-07 19:32:52 -04:00
let hostname = i2pHostName(url);
let postname = hostname.split(":")[0];
if (postname.endsWith(".i2p")) {
console.log("(hostname) i2p", postname);
}
return postname.endsWith(".i2p");
}
2019-11-24 17:14:43 -05:00
function onContextGotLog(contexts) {
2022-10-07 19:32:52 -04:00
if (contexts != null) {
console.log(contexts);
}
2019-07-10 02:29:38 -04:00
}
2019-10-28 01:11:16 -04:00
browser.runtime.onMessage.addListener(message);
2019-07-10 02:29:38 -04:00
function enableHistory() {
2022-10-07 19:32:52 -04:00
function checkStoredSettings(storedSettings) {
storedSettings["disable_history"] = false;
console.log(storedSettings);
2022-10-07 13:26:09 -04:00
2022-10-07 19:32:52 -04:00
function enablehistory(settings) {
console.log("Store History:", settings);
}
2022-10-07 19:32:52 -04:00
let setting = browser.storage.local.set(storedSettings);
setting.then(enablehistory);
}
const gettingStoredSettings = browser.storage.local.get();
gettingStoredSettings.then(checkStoredSettings, onError);
}
function disableHistory() {
2022-10-07 19:32:52 -04:00
function checkStoredSettings(storedSettings) {
storedSettings["disable_history"] = true;
console.log(storedSettings);
2022-10-07 13:26:09 -04:00
2022-10-07 19:32:52 -04:00
function enablehistory(settings) {
console.log("Store History:", settings);
}
2022-10-07 19:32:52 -04:00
var setting = browser.storage.local.set(storedSettings);
setting.then(enablehistory);
}
const gettingStoredSettings = browser.storage.local.get();
gettingStoredSettings.then(checkStoredSettings, onError);
}
function message(recieved) {
2022-10-07 19:32:52 -04:00
console.log(recieved);
if (recieved.rtc === "enableWebRTC") {
console.log("enableWebRTC");
AssurePeerConnection();
} else if (recieved.rtc === "disableWebRTC") {
console.log("disableWebRTC");
ResetPeerConnection();
}
if (recieved.history === "enableHistory") {
console.log("enableHistory");
enableHistory();
} else if (recieved.history === "disableHistory") {
console.log("disableHistory");
disableHistory();
}
}