Commit 0629eaa9 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Transform into a web extension

parent 90f727ba690a
......@@ -23,6 +23,9 @@
],
"js": [
"src/content/main.js"
],
"css": [
"src/content/main.css"
]
}
],
......
......@@ -61,7 +61,7 @@ function toggleActive(tab) {
chrome.browserAction.onClicked.addListener(toggleActive);
function onTabActivated(tabId) {
updateTab(tabId);
updateIcon(tabId);
}
// listen to tab URL changes
......@@ -165,7 +165,7 @@ function onHeadersReceived(details) {
data.linkedData = detectDataOnContent(details.tabId, details.responseHeaders);
if (data.linkedData == NO_DATA)
data.linkedData = detectDataOnLinks(details.responseHeaders);
updateTab(details.tabId);
updateIcon(details.tabId);
}
function onBeforeNavigate(details) {
......@@ -173,6 +173,12 @@ function onBeforeNavigate(details) {
return;
data = getTabData(details.tabId);
data.linkedData = NO_DATA;
updateIcon(details.tabId);
}
function onCompleted(details) {
if (details.tabId == -1 || details.frameId != 0)
return;
updateTab(details.tabId);
}
......@@ -180,6 +186,7 @@ function onBeforeNavigate(details) {
chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, { urls: ["<all_urls>"] }, ["responseHeaders"]);
// listen to navigation
chrome.webNavigation.onBeforeNavigate.addListener(onBeforeNavigate, { urls: ["<all_urls>"] });
chrome.webNavigation.onCompleted.addListener(onCompleted, { urls: ["<all_urls>"] });
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
......@@ -188,6 +195,6 @@ chrome.runtime.onMessage.addListener(
if (data.linkedData != NO_DATA)
return;
data.linkedData = doDetectDataOnLinks(request.links);
updateTab(sender.tab.id);
updateIcon(sender.tab.id);
}
});
\ No newline at end of file
#linked-data-injectable-app {
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background-color: white;
color: black;
}
\ No newline at end of file
var ID = "linked-data-injectable-app";
function maxZIndex() {
return values = Array.from(document.querySelectorAll('body *'))
.map(a => parseFloat(window.getComputedStyle(a).zIndex))
.filter(a => !isNaN(a))
.reduce(function (acc, value) { return (acc > value ? acc : value); }, 0);
}
function injectApplication() {
var zIndex = maxZIndex();
var appContent = document.createElement("div");
appContent.id = ID;
appContent.style.zIndex = zIndex + 10;
appContent.appendChild(document.createTextNode("Here!"));
document.body.insertBefore(appContent, document.body.firstChild);
}
function onUpdateDeactivate() {
var root = document.getElementById(ID);
if (root == null)
return;
root.parentNode.removeChild(root);
}
function onActivated(data) {
function onUpdateActivate(data) {
onUpdateDeactivate();
injectApplication();
}
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (!request.isActive || request.syntax == "")
return;
onActivated(request);
var activate = request.isActive && request.syntax != "";
if (activate)
onUpdateActivate(request);
else
onUpdateDeactivate();
});
function sendHead() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment