diff --git a/background.js b/background.js index f26e650..2ff21cc 100644 --- a/background.js +++ b/background.js @@ -1,71 +1,92 @@ -function enabled(tabId) { - chrome.pageAction.show(tabId); +function displayData(data, tabId, typo3) { + var icon; + if (typo3) { + chrome.pageAction.show(tabId); + if (data.mask.found) { + icon = "icon"; + } else if (data.tv.found) { + icon = "icon-tv"; + } else if (typo3) { + icon = "icon-typo3"; + } else { + icon = "icon-disabled"; + } + } else { + chrome.pageAction.hide(tabId); + icon = "icon-disabled"; + } chrome.pageAction.setIcon({ tabId: tabId, path: { - "128": "logo.128.png" + "128": "img/" + icon + ".128.png" } }) } -function disabled(tabId) { - chrome.pageAction.hide(tabId); - chrome.pageAction.setIcon({ - tabId: tabId, - path: { - "128": "logo-disabled.128.png" - } - }) -} -function typo3(tabId) { - chrome.pageAction.show(tabId); - chrome.pageAction.setIcon({ - tabId: tabId, - path: { - "128": "logo-typo3.128.png" - } - }) -} - -function handleMessage(request, sender, sendResponse) { +function handleMessage(request, sender) { + console.log("recieved message"); var tabId = sender.tab.id; if (request.typo3) { chrome.storage.local.get(request.url, function (result) { var data = result[request.url]; if (!data || Date.now() - data.updated > 1000 * 60 * 60 * 24) { + data = {}; + var xmlHttp = new XMLHttpRequest(); + data.mask = {}; xmlHttp.onreadystatechange = function () { - var found; if (xmlHttp.readyState === 4) { - if (xmlHttp.status === 200) { - found = true; - enabled(tabId); - } else { - found = false; - typo3(tabId); - } + data.mask.found = xmlHttp.status === 200; + data.mask.modified = xmlHttp.getResponseHeader('Last-Modified'); + var tvHttp = new XMLHttpRequest(); + data.tv = {}; + tvHttp.onreadystatechange = function () { + if (tvHttp.readyState === 4) { + data.tv.found = tvHttp.status === 200; + data.tv.modified = tvHttp.getResponseHeader('Last-Modified'); + + var cl = new XMLHttpRequest(); + cl.onreadystatechange = function () { + if (cl.readyState === 4) { + if (cl.status === 200) { + var changelog = cl.responseText.split('\n', 1)[0]; + const regex = /(\d\.)+(\d+)/; + var match = regex.exec(changelog); + data.t3version = match[0]; + } + console.log("saving data"); + data.updated = Date.now(); + + displayData(data, tabId, true); + + var storage = {}; + storage[request.url] = data; + chrome.storage.local.set(storage); + } + }; + + cl.open("GET", request.url + "/typo3_src/ChangeLog", true); + console.log("request changelog"); + cl.send(); + } + }; + tvHttp.open("GET", request.url + "/typo3conf/ext/templavoila/ext_icon.gif", true); + console.log("request tv icon"); + tvHttp.send(); } - var data = {}; - data[request.url] = { - found: found, - modified: xmlHttp.getResponseHeader('Last-Modified'), - updated: Date.now() - }; - chrome.storage.local.set(data); - }; - xmlHttp.open("GET", request.url + "/typo3conf/ext/mask/ext_icon.gif", true); - xmlHttp.send(); - } else { - if (data.found) { - enabled(tabId); - } else { - typo3(tabId); } + ; + xmlHttp.open("GET", request.url + "/typo3conf/ext/mask/ext_icon.gif", true); + console.log("request mask icon"); + xmlHttp.send(); + } + else { + displayData(data, tabId, true) } }); } else { - disabled(tabId); + displayData(false, tabId, false) } } diff --git a/logo-disabled.128.png b/img/icon-disabled.128.png similarity index 100% rename from logo-disabled.128.png rename to img/icon-disabled.128.png diff --git a/logo-disabled.svg b/img/icon-disabled.svg similarity index 100% rename from logo-disabled.svg rename to img/icon-disabled.svg diff --git a/img/icon-tv.128.png b/img/icon-tv.128.png new file mode 100644 index 0000000..313e614 Binary files /dev/null and b/img/icon-tv.128.png differ diff --git a/img/icon-tv.svg b/img/icon-tv.svg new file mode 100644 index 0000000..eb86bad --- /dev/null +++ b/img/icon-tv.svg @@ -0,0 +1,75 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/img/icon-typo3.128.png b/img/icon-typo3.128.png new file mode 100644 index 0000000..c6aca7e Binary files /dev/null and b/img/icon-typo3.128.png differ diff --git a/logo-typo3.svg b/img/icon-typo3.svg similarity index 65% rename from logo-typo3.svg rename to img/icon-typo3.svg index 9ef48b7..876e02f 100644 --- a/logo-typo3.svg +++ b/img/icon-typo3.svg @@ -22,7 +22,7 @@ viewBox="0 0 156 156" enable-background="new 0 0 156 156" xml:space="preserve" - sodipodi:docname="logo-typo3.svg" + sodipodi:docname="icon-typo3.svg" inkscape:version="0.92.1 r15371">image/svg+xml - - - - - - - - - - - - diff --git a/manifest.json b/manifest.json index 7312fde..ed264f3 100644 --- a/manifest.json +++ b/manifest.json @@ -6,11 +6,11 @@ "author": "Lukas Winkler", "description": "find websites using the mask Typo3 extension", "icons": { - "128": "logo.128.png" + "128": "img/icon.128.png" }, "page_action": { "default_icon": { - "128": "logo-disabled.128.png" + "128": "img/icon-disabled.128.png" }, "default_popup": "popup.html" }, diff --git a/popup.html b/popup.html index b49efe7..4478cd4 100644 --- a/popup.html +++ b/popup.html @@ -5,6 +5,7 @@ Mask Detector +
diff --git a/popup.js b/popup.js index 8ade417..86dcae9 100644 --- a/popup.js +++ b/popup.js @@ -2,8 +2,19 @@ chrome.tabs.query({active: true}, function (tabs) { var url = new URL(tabs[0].url); var key = url.protocol + "//" + url.host; chrome.storage.local.get(key, function (result) { - if(result[key]) { - document.getElementById("lastModified").innerText = result[key].modified; + var text; + if (result[key]) { + if (result[key].mask.modified) { + text = result[key].mask.modified; + } else if (result[key].tv.modified) { + text = result[key].tv.modified + } + } + if (text) { + document.getElementById("lastModified").innerText = text; + } + if (result[key].t3version) { + document.getElementById("typo3Version").innerText = result[key].t3version; } }); });