-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (47 loc) · 1.93 KB
/
script.js
File metadata and controls
60 lines (47 loc) · 1.93 KB
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
53
54
55
56
57
58
59
60
// Get all summary blocks
const _sums = document.getElementsByClassName('summary');
// Set question name to inline to play nice with FP blocks
for (let i = 0; i < _sums.length; i++) {
_sums[i].querySelector('h3').style.display = "inline-block";
}
// Create .fp-blocks and insert in front of summary blocks
for (let i = 0; i < _sums.length; i++) {
let fpBlock = document.createElement('div');
fpBlock.id = "fpb-" + i;
fpBlock.className = "fp-block"; // Todo: move style to .css
fpBlock.style.cssText = "background-color: green; color: white; width: fit-content; display: none; padding: 2px"; // Display setting defaults to none, then loaded from storage
fpBlock.textContent = (Math.random() * 10).toFixed(2) + " CBC"; // Random filler bounty
_sums[i].insertBefore(fpBlock, _sums[i].firstChild);
}
// Saved display setting is loaded
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.savedDispSet) {
var fpBlocks = document.getElementsByClassName('fp-block');
for (let i = 0; i < fpBlocks.length; i++) {
fpBlocks[i].style.display = request.savedDispSet;
}
}
});
/* ---------- End of Code ----------- */
/* ---------- Next steps: -----------
- Inject blocks into homepage
- Inject blocks into full question pages
- Learn SE APIs and make blocks display first num of question ID
*/
/* --------- Unused code below ------
chrome.pageAction.onClicked.addListener(setBountBlocks());
function update() {
const fpBlocks = document.getElementsByClassName('fp-block');
for (let i = 0; i < fpBlocks.length; i++) {
fpBlocks[i].textContent = (Math.random() * 10).toFixed(2) + " CBC";
}
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
*/