1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
mask-detector/background.js

43 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-09-20 15:33:18 +02:00
function handleMessage(request, sender, sendResponse) {
var tabId = sender.tab.id;
if (request.typo3) {
chrome.storage.local.get(request.url, function (result) {
var data = result[request.url];
2017-09-20 15:52:40 +02:00
if (!data || Date.now() - data.updated > 1000 * 60 * 60 * 24) {
2017-09-20 15:33:18 +02:00
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
var found;
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
found = true;
chrome.browserAction.enable(tabId);
} else {
found = false;
chrome.browserAction.disable(tabId);
}
var data = {};
2017-09-20 15:52:40 +02:00
data[request.url] = {
found: found,
modified: xmlHttp.getResponseHeader('Last-Modified'),
updated: Date.now()
};
2017-09-20 15:33:18 +02:00
chrome.storage.local.set(data);
};
xmlHttp.open("GET", request.url + "/typo3conf/ext/mask/ext_icon.gif", true);
xmlHttp.send();
} else {
if (data.found) {
chrome.browserAction.enable(tabId);
console.info("found");
} else {
chrome.browserAction.disable(tabId);
}
}
});
}
else {
chrome.browserAction.disable(tabId);
}
}
chrome.runtime.onMessage.addListener(handleMessage);