-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbackground.js
More file actions
27 lines (23 loc) · 853 Bytes
/
background.js
File metadata and controls
27 lines (23 loc) · 853 Bytes
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
//logo color is #1271ED
chrome.runtime.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
const parsed = String(msg.url.match(/(\/\/www\.\w+\.)|(\/\/\w+\.)/gi)).replace('www\.', '').slice(2, -1);
const xhr = new XMLHttpRequest();
xhr.open('GET', `https://stackshare.io/${parsed}/${parsed}`);
xhr.onreadystatechange = handleReady;
xhr.send();
function handleReady() {
if (xhr.readyState === 4 && xhr.status === 200) {
chrome.tabs.query({ currentWindow: true, active: true }, tabs => {
chrome.browserAction.setIcon({
path: "./images/iconblue32.png",
tabId: tabs[0].id
});
});
chrome.browserAction.onClicked.addListener(tab => {
port.postMessage({message: xhr.responseText});
});
}
}
});
});