diff --git a/README b/README index b005339..821eed1 100644 --- a/README +++ b/README @@ -20,12 +20,17 @@ Rationale --------- -The extension runs once on each page you visit, looking for -tags in the page with relationship 'meta' or 'alternate' pointing to a -URI with media-type application/rdf+xml or text/turtle. Failing that, -the extension will attempt to do content negotiation on the current -URI, asking for application/rdf+xml or text/turtle representation of -the current resource. +The extension runs once on each page you visit looking for any RDF +data it can find in the following order: + +1) Any tags in the page with relationship 'meta' or 'alternate' +pointing to a URI with media-type application/rdf+xml or text/turtle. + +2) Any RDFa in the body of the HTML document. + +3) Using content negotiation on the current URI, asking for +application/rdf+xml or text/turtle representation of the current +resource. If an RDF representation is available, it will be rendered behind the current page and a peel-back animation will reveal the background RDF @@ -34,6 +39,8 @@ Examples -------- +http://sws.geonames.org/3020251/ + http://data.nytimes.com/48675831753778135041 http://collection.britishmuseum.org/id/object/EOC3130 @@ -49,3 +56,14 @@ http://live.dbpedia.org/page/William_Shakespeare http://data.europeana.eu/item/92056/BD9D5C6C6B02248F187238E9D7CC09EAF17BEA59 + +http://didactalia.net/comunidad/materialeducativo/recurso/La-teoria-de-la-relatividad-en-ingles/eb95e40e-937f-4447-a68d-5f1a3fbc97ff + +Todo +---- + +Parsing Turtle to look for licensing statements. + +Checking that the license applies to the document URI of the RDF document. + +Checking what license is being applied and that it is usable. \ No newline at end of file diff --git a/contentscript.js b/contentscript.js index f587824..12baaa1 100644 --- a/contentscript.js +++ b/contentscript.js @@ -125,19 +125,37 @@ } if (rdfUrl == null) { - // check to see whether we've been redirected here - chrome.runtime.sendMessage({ - method: 'isRedirect', - url: document.URL - }, function(response) { - if (response.redirect) { - fetchRdf(response.fromUrl, function() { - fetchRdf(document.URL, function() {}); // if failed to fetch prior page as RDF - }); - } else { // if no redirect, try fetching current page as RDF - fetchRdf(document.URL, function() {}); - } - }); + // No link URL, so first check to see whether there's any RDFa in the current document + var localdata = $(document.body).rdf(); + if (localdata.databank.size() > 0) { + // Serialize it out as RDF/XML + var format = "application/rdf+xml"; + var dom = localdata.databank.dump({format: format}); + var serializer = new XMLSerializer(); + var data = vkbeautify.xml(serializer.serializeToString(dom)); + peelBackRdf(data, format); + chrome.runtime.sendMessage({ + method: 'setLicense', + type: format, + check: checkRdfXmlLicense(data, format) + }, function(response) { + console.log(response.text); + }); + } else { + // check to see whether we've been redirected here + chrome.runtime.sendMessage({ + method: 'isRedirect', + url: document.URL + }, function(response) { + if (response.redirect) { + fetchRdf(response.fromUrl, function() { + fetchRdf(document.URL, function() {}); // if failed to fetch prior page as RDF + }); + } else { // if no redirect, try fetching current page as RDF + fetchRdf(document.URL, function() {}); + } + }); + } } else { fetchRdf(rdfUrl, function() {}); } diff --git a/manifest.json b/manifest.json index 41d2dee..ce251b8 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "LOD-check", "description": "Checks pages as you browse for the presence of Linked Open Data behind them and reveals the underlying data.", - "version": "1.1.2", + "version": "1.1.3", "permissions": [ "webRequest", "" @@ -28,7 +28,7 @@ "http://*/*", "https://*/*" ], - "js": [ "jquery.min.js", "jquery-ui.min.js", "turn.js", "codemirror-compressed.js", "jquery.rdfquery.core-1.0.js", "contentscript.js" ], + "js": [ "jquery.min.js", "jquery-ui.min.js", "turn.js", "codemirror-compressed.js", "jquery.rdfquery.core-1.0.js", "jquery.rdfquery.rdfa-1.0.js", "vkbeautify.0.99.00.beta.js", "contentscript.js" ], "css": [ "turn.css", "codemirror.css", "custom.css" ], "run_at" : "document_idle", "all_frames" : false diff --git a/vkbeautify.0.99.00.beta.js b/vkbeautify.0.99.00.beta.js new file mode 100644 index 0000000..57effae --- /dev/null +++ b/vkbeautify.0.99.00.beta.js @@ -0,0 +1,358 @@ +/** +* vkBeautify - javascript plugin to pretty-print or minify text in XML, JSON, CSS and SQL formats. +* +* Version - 0.99.00.beta +* Copyright (c) 2012 Vadim Kiryukhin +* vkiryukhin @ gmail.com +* http://www.eslinstructor.net/vkbeautify/ +* +* Dual licensed under the MIT and GPL licenses: +* http://www.opensource.org/licenses/mit-license.php +* http://www.gnu.org/licenses/gpl.html +* +* Pretty print +* +* vkbeautify.xml(text [,indent_pattern]); +* vkbeautify.json(text [,indent_pattern]); +* vkbeautify.css(text [,indent_pattern]); +* vkbeautify.sql(text [,indent_pattern]); +* +* @text - String; text to beatufy; +* @indent_pattern - Integer | String; +* Integer: number of white spaces; +* String: character string to visualize indentation ( can also be a set of white spaces ) +* Minify +* +* vkbeautify.xmlmin(text [,preserve_comments]); +* vkbeautify.jsonmin(text); +* vkbeautify.cssmin(text [,preserve_comments]); +* vkbeautify.sqlmin(text); +* +* @text - String; text to minify; +* @preserve_comments - Bool; [optional]; +* Set this flag to true to prevent removing comments from @text ( minxml and mincss functions only. ) +* +* Examples: +* vkbeautify.xml(text); // pretty print XML +* vkbeautify.json(text, 4 ); // pretty print JSON +* vkbeautify.css(text, '. . . .'); // pretty print CSS +* vkbeautify.sql(text, '----'); // pretty print SQL +* +* vkbeautify.xmlmin(text, true);// minify XML, preserve comments +* vkbeautify.jsonmin(text);// minify JSON +* vkbeautify.cssmin(text);// minify CSS, remove comments ( default ) +* vkbeautify.sqlmin(text);// minify SQL +* +*/ + +(function() { + +function createShiftArr(step) { + + var space = ' '; + + if ( isNaN(parseInt(step)) ) { // argument is string + space = step; + } else { // argument is integer + switch(step) { + case 1: space = ' '; break; + case 2: space = ' '; break; + case 3: space = ' '; break; + case 4: space = ' '; break; + case 5: space = ' '; break; + case 6: space = ' '; break; + case 7: space = ' '; break; + case 8: space = ' '; break; + case 9: space = ' '; break; + case 10: space = ' '; break; + case 11: space = ' '; break; + case 12: space = ' '; break; + } + } + + var shift = ['\n']; // array of shifts + for(ix=0;ix<100;ix++){ + shift.push(shift[ix]+space); + } + return shift; +} + +function vkbeautify(){ + this.step = ' '; // 4 spaces + this.shift = createShiftArr(this.step); +}; + +vkbeautify.prototype.xml = function(text,step) { + + var ar = text.replace(/>\s{0,}<") + .replace(/ or -1) { + str += shift[deep]+ar[ix]; + inComment = true; + // end comment or // + if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1 ) { + inComment = false; + } + } else + // end comment or // + if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) { + str += ar[ix]; + inComment = false; + } else + // // + if( /^<\w/.exec(ar[ix-1]) && /^<\/\w/.exec(ar[ix]) && + /^<[\w:\-\.\,]+/.exec(ar[ix-1]) == /^<\/[\w:\-\.\,]+/.exec(ar[ix])[0].replace('/','')) { + str += ar[ix]; + if(!inComment) deep--; + } else + // // + if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) == -1 && ar[ix].search(/\/>/) == -1 ) { + str = !inComment ? str += shift[deep++]+ar[ix] : str += ar[ix]; + } else + // ... // + if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) { + str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/<\//) > -1) { + str = !inComment ? str += shift[--deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/\/>/) > -1 ) { + str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/<\?/) > -1) { + str += shift[deep]+ar[ix]; + } else + // xmlns // + if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) { + str += shift[deep]+ar[ix]; + } + + else { + str += ar[ix]; + } + } + + return (str[0] == '\n') ? str.slice(1) : str; +} + +vkbeautify.prototype.json = function(text,step) { + + var step = step ? step : this.step; + + if (typeof JSON === 'undefined' ) return text; + + if ( typeof text === "string" ) return JSON.stringify(JSON.parse(text), null, step); + if ( typeof text === "object" ) return JSON.stringify(text, null, step); + + return text; // text is not string nor object +} + +vkbeautify.prototype.css = function(text, step) { + + var ar = text.replace(/\s{1,}/g,' ') + .replace(/\{/g,"{~::~") + .replace(/\}/g,"~::~}~::~") + .replace(/\;/g,";~::~") + .replace(/\/\*/g,"~::~/*") + .replace(/\*\//g,"*/~::~") + .replace(/~::~\s{0,}~::~/g,"~::~") + .split('~::~'), + len = ar.length, + deep = 0, + str = '', + ix = 0, + shift = step ? createShiftArr(step) : this.shift; + + for(ix=0;ix/g,"") + .replace(/[ \r\n\t]{1,}xmlns/g, ' xmlns'); + return str.replace(/>\s{0,}<"); +} + +vkbeautify.prototype.jsonmin = function(text) { + + if (typeof JSON === 'undefined' ) return text; + + return JSON.stringify(JSON.parse(text), null, 0); + +} + +vkbeautify.prototype.cssmin = function(text, preserveComments) { + + var str = preserveComments ? text + : text.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"") ; + + return str.replace(/\s{1,}/g,' ') + .replace(/\{\s{1,}/g,"{") + .replace(/\}\s{1,}/g,"}") + .replace(/\;\s{1,}/g,";") + .replace(/\/\*\s{1,}/g,"/*") + .replace(/\*\/\s{1,}/g,"*/"); +} + +vkbeautify.prototype.sqlmin = function(text) { + return text.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")"); +} + +window.vkbeautify = new vkbeautify(); + +})(); +