This repository has been archived by the owner on Oct 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
52 lines (39 loc) · 1.94 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const SEARCH_TYPE_GOOGLE_BANG = "google_bang";
const SEARCH_TYPE_DDG = "ddg";
var storedStats = browser.storage.local.get();
storedStats.then(results => {
let ddgSearchDiv = document.getElementById("ddgSearchCountDiv");
let googleBangSearchDiv = document.getElementById("googleBangSearchDiv");
let percentageStatsDiv = document.getElementById("percentageStatsDiv");
if (results == null || results.searchType == null || results.searchType.length === 0) {
const ddgSearchCountItem = document.createTextNode("h6");
ddgSearchCountItem.textContent = "Nothing to show at the moment.";
ddgSearchDiv.appendChild(ddgSearchCountItem);
return;
}
var ddgSearchCount = results.searchType[SEARCH_TYPE_DDG];
var googleBangSearchCount = results.searchType[SEARCH_TYPE_GOOGLE_BANG];
if (results.searchType[SEARCH_TYPE_DDG] > 0) {
ddgSearchCount = results.searchType[SEARCH_TYPE_DDG];
} else {
ddgSearchCount = 0;
}
if (results.searchType[SEARCH_TYPE_GOOGLE_BANG] > 0) {
googleBangSearchCount = results.searchType[SEARCH_TYPE_GOOGLE_BANG];
} else {
googleBangSearchCount = 0;
}
// Set DDG search count text
const ddgSearchCountItem = document.createTextNode("h6");
ddgSearchCountItem.textContent = "DDG Searches: " + ddgSearchCount;
ddgSearchDiv.appendChild(ddgSearchCountItem);
// Set Google bang search count text
const googleBangSearchCountItem = document.createTextNode("h6");
googleBangSearchCountItem.textContent = "!g Searches: " + googleBangSearchCount;
googleBangSearchDiv.appendChild(googleBangSearchCountItem);
// Set use percentage text
var percentageStat = (ddgSearchCount/(ddgSearchCount + googleBangSearchCount)) * 100;
const percentageStatItem = document.createTextNode("h6");
percentageStatItem.textContent = "Your DDG usage is " + percentageStat + "%";
percentageStatsDiv.appendChild(percentageStatItem);
});