Initial commit
This commit is contained in:
commit
ef2f7aeaaa
22 changed files with 566 additions and 0 deletions
54
popup.js
Normal file
54
popup.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
const statusText = {
|
||||
0: "No requests have been processed yet.",
|
||||
1: "No requests were served by Cloudflare.",
|
||||
2: "Requests for these domains were served by Cloudflare:",
|
||||
3: "Requests for these domains were served by Cloudflare:",
|
||||
99: "Detection result unavailable."
|
||||
};
|
||||
|
||||
var getTab = chrome.tabs.query( { active:true, currentWindow:true }, function(tabs){
|
||||
try {
|
||||
var tab = tabs[0];
|
||||
var port = chrome.runtime.connect();
|
||||
port.postMessage(tab.id);
|
||||
port.onMessage.addListener( function(msg) {
|
||||
port.disconnect();
|
||||
if (msg) {
|
||||
writeStatus(msg.result);
|
||||
populatePopup(msg.counts);
|
||||
} else {
|
||||
writeStatus(0);
|
||||
}
|
||||
});
|
||||
}catch (error){
|
||||
writeStatus(99);
|
||||
console.log(`CF-Detect-Popup: ${error}`);
|
||||
}
|
||||
});
|
||||
|
||||
function writeStatus( st ) {
|
||||
var p = document.getElementById("status");
|
||||
p.textContent = statusText[st];
|
||||
}
|
||||
|
||||
function populatePopup( domainCounts ) {
|
||||
var ndomain = 0;
|
||||
var div = document.getElementById("top");
|
||||
var ul = document.createElement("ul");
|
||||
for (var domain in domainCounts) {
|
||||
if (!domainCounts.hasOwnProperty(domain)) continue;
|
||||
++ndomain;
|
||||
var count = domainCounts[domain];
|
||||
var li = document.createElement("li");
|
||||
var text = document.createTextNode(`${domain}: `);
|
||||
var span = document.createElement("span");
|
||||
span.setAttribute("class", "count");
|
||||
span.textContent = `${count}`;
|
||||
li.appendChild(text);
|
||||
li.appendChild(span);
|
||||
ul.appendChild(li);
|
||||
}
|
||||
if (ndomain>0) div.appendChild(ul);
|
||||
}
|
||||
|
||||
// vim: set expandtab ts=4 sw=4 :
|
Loading…
Add table
Add a link
Reference in a new issue