Files
I2P_in_Private_Browsing_Mod…/cert.js

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-06-20 13:19:49 -04:00
function clearContent(titleId) {
const titleElement = document.getElementById(titleId);
if (!titleElement) {
2020-03-05 23:25:08 -05:00
return;
}
2023-06-20 13:19:49 -04:00
titleElement.textContent = "";
2020-03-05 23:25:08 -05:00
}
2023-06-20 13:19:49 -04:00
function updateContentById(id, message) {
const element = document.getElementById(id);
if (!element) return;
const content = chrome.i18n.getMessage(message);
if (!content) return;
element.textContent = content;
2020-03-05 23:25:08 -05:00
}
2023-06-20 13:19:49 -04:00
updateContentById("TypeLabel", "siteLabel");
2020-03-05 23:25:08 -05:00
2023-06-20 13:19:49 -04:00
updateContentById("CertLabel", "CertLabel");
2020-03-05 23:25:08 -05:00
2023-06-20 13:19:49 -04:00
function checkTab(tabInfo) {
const url = tabInfo[0].url;
const host = url.split(".i2p")[0] + ".i2p";
2020-03-05 23:25:08 -05:00
if (host.length < 51) {
2023-06-20 13:19:49 -04:00
updateContentById("AddressInfo", "isHostName");
} else if (host.endsWith("b32.i2p")) {
updateContentById("AddressInfo", "isBase32");
2020-03-05 23:25:08 -05:00
}
2023-06-20 13:19:49 -04:00
if (url.startsWith("https")) {
updateContentById("AddressCertInfo", "certPresent");
2020-11-10 21:48:08 -05:00
fetch(host).then((response) => {
2022-10-24 19:57:51 -04:00
console.log("Updating cert information", response);
2020-03-05 23:25:08 -05:00
});
} else {
2023-06-20 13:19:49 -04:00
updateContentById("AddressCertInfo", "certAbsent");
clearContent("SignedLabel");
2020-03-05 23:25:08 -05:00
}
}
function tabError(error) {
2023-06-20 13:19:49 -04:00
console.error(`Error: ${error}`);
2020-03-05 23:25:08 -05:00
}
const gettingCurrent = browser.tabs.query({ active: true });
2023-06-20 13:19:49 -04:00
gettingCurrent.then(checkTab, tabError);