Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
SemWeb
libview
Commits
1036ffc49005
Commit
3f4c9d89
authored
Jul 06, 2018
by
Laurent Wouters
Browse files
Transform into a web extension
parent
ecde72bff2b6
Changes
3
Hide whitespace changes
Inline
Side-by-side
manifest.json
View file @
1036ffc4
...
...
@@ -8,8 +8,9 @@
},
"permissions"
:
[
"tabs"
,
"activeTab"
,
"webRequest"
"webRequest"
,
"webNavigation"
,
"*://*/*"
],
"browser_action"
:
{
"default_icon"
:
"icons/browser_action_disabled.png"
,
...
...
src/background/main.js
View file @
1036ffc4
var
NO_DATA
=
{
badge
:
""
,
syntax
:
""
,
fetch
:
function
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
reject
(
"
No data!
"
);
});
}
syntax
:
null
,
target
:
null
};
var
allTabs
=
{};
var
MIME
=
{
"
text/n3
"
:
"
N3
"
,
"
application/n-triples
"
:
"
N3
"
,
"
application/n-quads
"
:
"
N4
"
,
"
text/turtle
"
:
"
TTL
"
,
"
application/rdf+xml
"
:
"
RDF
"
,
"
application/ld+json
"
:
"
JSON
"
,
"
application/trig
"
:
"
TRIG
"
}
function
getTabData
(
id
)
{
if
(
!
allTabs
.
hasOwnProperty
(
id
))
{
allTabs
[
id
]
=
{
...
...
@@ -113,13 +120,11 @@ function detectDataOnLinks(headers) {
return
NO_DATA
;
var
links
=
parseLinks
(
linksContent
);
for
(
var
j
=
0
;
j
!=
links
.
length
;
j
++
)
{
if
(
links
[
j
].
rel
==
"
alternate
"
&&
links
[
j
].
type
==
"
text/n3
"
)
{
if
(
links
[
j
].
rel
==
"
alternate
"
&&
MIME
.
hasOwnProperty
(
links
[
j
].
type
)
)
{
return
{
badge
:
"
N3
"
,
badge
:
MIME
[
links
[
j
].
type
]
,
syntax
:
links
[
j
].
type
,
fetch
:
function
(
url
=
links
[
j
].
url
)
{
return
fetchAt
(
url
);
}
target
:
links
[
j
]
};
}
}
...
...
@@ -131,30 +136,34 @@ function detectDataOnContent(tabId, headers) {
if
(
contentType
==
null
)
return
NO_DATA
;
contentType
=
contentType
.
split
(
"
;
"
)[
0
];
if
(
contentType
==
"
text/n3
"
)
{
if
(
MIME
.
hasOwnProperty
(
contentType
)
)
{
return
{
badge
:
"
N3
"
,
syntax
:
"
text/n3
"
,
fetch
:
function
(
tabId
=
tabId
)
{
return
fetchContent
(
tabId
);
}
badge
:
MIME
[
contentType
],
syntax
:
contentType
,
target
:
"
content
"
};
}
return
NO_DATA
;
}
function
detectData
(
tabId
,
headers
)
{
var
linkedData
=
detectDataOnContent
(
tabId
,
headers
);
if
(
linkedData
==
NO_DATA
)
linkedData
=
detectDataOnLinks
(
headers
);
data
=
getTabData
(
tabId
);
data
.
linkedData
=
linkedData
;
updateIcon
(
tabId
);
function
onHeadersReceived
(
details
)
{
data
=
getTabData
(
details
.
tabId
);
if
(
data
.
linkedData
!=
NO_DATA
)
// already detected something
return
;
data
.
linkedData
=
detectDataOnContent
(
details
.
tabId
,
details
.
responseHeaders
);
if
(
data
.
linkedData
==
NO_DATA
)
data
.
linkedData
=
detectDataOnLinks
(
details
.
responseHeaders
);
updateIcon
(
details
.
tabId
);
}
function
onHeaders
(
details
)
{
detectData
(
details
.
tabId
,
details
.
responseHeaders
);
function
onBeforeNavigate
(
details
)
{
data
=
getTabData
(
details
.
tabId
);
data
.
linkedData
=
NO_DATA
;
updateIcon
(
details
.
tabId
);
}
// listen to received headers
chrome
.
webRequest
.
onHeadersReceived
.
addListener
(
onHeaders
,
{
urls
:
[
"
<all_urls>
"
]
},
[
"
responseHeaders
"
]);
chrome
.
webRequest
.
onHeadersReceived
.
addListener
(
onHeadersReceived
,
{
urls
:
[
"
<all_urls>
"
]
},
[
"
responseHeaders
"
]);
// listen to received headers
chrome
.
webNavigation
.
onBeforeNavigate
.
addListener
(
onBeforeNavigate
,
{
urls
:
[
"
<all_urls>
"
]
});
\ No newline at end of file
src/content/main.js
View file @
1036ffc4
chrome
.
runtime
.
onMessage
.
addListener
(
function
(
request
,
sender
,
sendResponse
)
{
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment