Check for Turtle as well as XML/RDF. Parse XML/RDF and look for licensing info. Click on revealed RDF to make it full height/width. Show traffic light icon depending on results of parsing.
1 parent c1237e7 commit 217e4126ddacfba7e70f3bc62ba9407244580e57
@Alex Tucker Alex Tucker authored on 18 Jun 2014
Showing 13 changed files
View
18
background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("Message from content: " + request);
var messages = {
'error': 'Error parsing RDF',
'unlicensed': 'No machine readable licensing',
'licensed': 'License declared'
};
chrome.pageAction.setTitle({
tabId: sender.tab.id,
title: messages[request.check]
});
var icon = {
'error': 'red',
'unlicensed': 'amber',
'licensed': 'green'
};
chrome.pageAction.show(sender.tab.id);
chrome.pageAction.setIcon({
tabId: sender.tab.id,
path: 'pageIcon-' + icon[request.check] + '.png'
});
sendResponse({text: "ok"});
}
);
View
109
contentscript.js
function peelBackRdf(data) {
function peelBackRdf(data, format) {
$('body').prepend('<div id="target"><textarea id="code"></textarea></div>');
$('#code').text(data);
var cm = CodeMirror.fromTextArea($('#code')[0], {
mode: "xml",
readOnly: "nocursor"
mode: format,
readOnly: "nocursor",
viewportMargin: Infinity
});
$('#target').fold({
directory: "chrome-extension://" + chrome.runtime.id
directory: "chrome-extension://" + chrome.runtime.id,
autoCurl: true
});
$('#turn_wrapper').click(
function() {
$('#turn_fold').hide();
$('#turn_wrapper').width('100%').height('100%').off();
$('#turn_object').width('100%').height('100%').off();
$('#turn_hideme').width('100%').height('100%').off();
}
);
}
 
function checkRdf(data, format) {
var parser = new DOMParser();
doc = parser.parseFromString(data, 'text/xml');
try {
var rdf = $.rdf().load(doc);
var licenses = rdf
.prefix('cc', 'http://creativecommons.org/ns#')
.where('?doc cc:license ?license');
licenses = licenses.add(
rdf
.prefix('dct', 'http://purl.org/dc/terms/')
.where('?doc dct:license ?license')
);
if (licenses.select().length > 0) {
return 'licensed';
} else {
return 'unlicensed';
}
} catch (e) {
console.log(e);
return 'error';
}
}
 
var res = document.evaluate("//link[(@rel = 'alternate') or (@rel = 'meta')]", document.head, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
 
var rdfUrl = null;
var rdfFormat = null;
var acceptFormats = ['application/rdf+xml', 'text/turtle'];
 
for (var i=0; i < res.snapshotLength; i++) {
if (res.snapshotItem(i).type == "application/rdf+xml") {
console.log("Found link rel=(alternate|meta) type=application/rdf+xml");
if (acceptFormats.indexOf(res.snapshotItem(i).type) > -1) {
rdfFormat = res.snapshotItem(i).type;
rdfUrl = res.snapshotItem(i).href; // relative
chrome.runtime.sendMessage({type: 'rdf+xml'}, function(response) {
console.log(response.text);
});
break;
}
}
 
if (rdfUrl == null) { // Try fetching current page as RDF
$.ajax(document.URL, {
accepts: { text: 'application/rdf+xml' },
headers: {
Accept: acceptFormats.join(', ')
},
dataType: 'text',
success: function(data, textStatus, res) {
var ct = res.getResponseHeader('Content-Type');
if ((ct != null) && (ct.slice(0, 'application/rdf+xml'.length) == 'application/rdf+xml')) {
chrome.runtime.sendMessage({type: 'rdf+xml'}, function(response) {
console.log(response.text);
});
peelBackRdf(data);
if (ct != null) {
var format = null;
for (var i = 0; i < acceptFormats.length; i++) {
if (ct.slice(0, acceptFormats[i].length) == acceptFormats[i]) {
format = acceptFormats[i];
break;
}
}
if (format != null) {
peelBackRdf(data, format);
chrome.runtime.sendMessage({
type: format,
check: checkRdf(data, format)
}, function(response) {
console.log(response.text);
});
}
}
}
});
} else {
$.ajax(rdfUrl, {
accepts: { text: 'application/rdf+xml' },
accepts: { text: rdfFormat },
dataType: 'text',
success: function(data, textStatus, res) {
peelBackRdf(data);
peelBackRdf(data, rdfFormat);
chrome.runtime.sendMessage({
type: format,
check: checkRdf(data, rdfFormat)
}, function(response) {
console.log(response.text);
});
}
});
}
View
9
custom.css
box-shadow: none;
}
 
.CodeMirror {
height: 800px;
width: 800px;
border: 1px solid #eee;
height: auto;
}
 
.CodeMirror-scroll {
overflow-y: hidden;
overflow-x: auto;
}
View
153
fold.svg 0 → 100644
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
 
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="600"
height="600"
id="svg4355"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="fold.svg"
inkscape:export-filename="/home/alex/Development/res-check/fold.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<defs
id="defs4357">
<linearGradient
id="linearGradient5017">
<stop
id="stop5019"
offset="0"
style="stop-color:#000000;stop-opacity:0.33333334;" />
<stop
id="stop5021"
offset="1"
style="stop-color:#000000;stop-opacity:0;" />
</linearGradient>
<linearGradient
id="linearGradient5005">
<stop
style="stop-color:#000000;stop-opacity:0.33333334;"
offset="0"
id="stop5007" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop5009" />
</linearGradient>
<linearGradient
id="linearGradient4901">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop4903" />
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="1"
id="stop4905" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4901"
id="linearGradient4907"
x1="342.57367"
y1="356.22702"
x2="71.756355"
y2="84.327812"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5017"
id="linearGradient5015"
x1="470.87097"
y1="917.11597"
x2="208.01205"
y2="636.01599"
gradientUnits="userSpaceOnUse" />
<filter
inkscape:collect="always"
id="filter5039"
x="-0.015632253"
width="1.0312645"
y="-0.15854214"
height="1.3170843">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="3.2513557"
id="feGaussianBlur5041" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.75417998"
inkscape:cx="106.20105"
inkscape:cy="349.43014"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:snap-global="false"
inkscape:window-width="1440"
inkscape:window-height="853"
inkscape:window-x="-2"
inkscape:window-y="-3"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid4365"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata4360">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-452.36218)">
<path
style="fill:url(#linearGradient4907);fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 550.36157,549.37048 50.629514,550.30807 C -0.93758381,551.24565 1.8751672,599.06242 1.8751672,599.06242 0,579.37316 15.001338,562.49666 15.001338,562.49666 L 561.61258,20.573334 c 0,0 13.12617,-18.7516722 38.44093,-19.68925556 0,0 -48.75436,0.93758326 -48.75436,59.06776656 z"
id="path4899"
inkscape:connector-curvature="0"
transform="translate(0,452.36218)"
sodipodi:nodetypes="cccccccc" />
<path
inkscape:connector-curvature="0"
style="fill:#000000;fill-opacity:0.12264151000000000;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;filter:url(#filter5039)"
d="m 500.61063,1051.9693 -0.6875,-49.2188 -449.906249,0.8438 c -23.63492,0.4297 -35.830562,10.7108 -42.125001,21.7187 -6.0775144,10.1975 -6.8856214,16.6465 -6.2982314,26.5188 z"
id="path4928-6"
sodipodi:nodetypes="cccccc" />
<path
style="fill:url(#linearGradient5015);fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 0.66103367,451.04707 c 0,199.33334 0,398.66667 0,598.00003 C 5.4174437,1028.8795 7.5601037,1022.486 20.484304,1009.4214 204.14855,827.36133 387.81975,645.17831 571.47849,463.19432 c 5.36721,-4.32421 13.11275,-9.60925 29.83879,-10.8035 -200.21875,-0.44792 -400.4375,-0.89583 -600.65624633,-1.34375 z"
id="path4983"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc" />
</g>
</svg>
View
jquery.rdfquery.core-1.0.js 0 → 100644
Too large (Show diff)
View
manifest.json
View
package-icon-128.png 0 → 100644
View
package-icon-16.png 0 → 100644
View
package-icon-48.png 0 → 100644
View
package-icon.svg 0 → 100644
View
pageIcon-amber.png 0 → 100644
View
pageIcon-green.png 0 → 100644
View
pageIcon-red.png 0 → 100644