Permalink
Browse files

Signed-off-by: patlockley <patrick.lockley@googlemail.com>

  • Loading branch information...
1 parent 929c723 commit 9f7b14308685d3d1decb9649b9c66e2195f01b53 @pgogy committed Jan 20, 2011
Showing with 341 additions and 0 deletions.
  1. +38 −0 _locales/en_US/messages.json
  2. +228 −0 content_script.js
  3. BIN icon.png
  4. +22 −0 manifest.json
  5. +53 −0 popup.html
@@ -0,0 +1,38 @@
+{
+ "extDesc": {
+ "description": "Extension description",
+ "message": "This extension lists all RDF triples on a Website that are embedded in RDFa format."
+ },
+ "extName": {
+ "description": "Extension name",
+ "message": "RDFa Triples Lister"
+ },
+ "iframe": {
+ "description": "iframe option",
+ "message": "Inline in an iframe"
+ },
+ "lookFeel": {
+ "description": "Look and Feel header",
+ "message": "Look and Feel"
+ },
+ "options": {
+ "description": "Options header",
+ "message": "Options"
+ },
+ "popup": {
+ "description": "pop-up option",
+ "message": "In the pop-up window"
+ },
+ "save": {
+ "description": "Save button",
+ "message": "Save"
+ },
+ "tripleFound": {
+ "description": "Number of triples, singular",
+ "message": "Triple found"
+ },
+ "triplesFound": {
+ "description": "Number of triples, plural",
+ "message": "Triples found"
+ }
+}
View
@@ -0,0 +1,228 @@
+triplesHtml = "";
+
+var n = document;
+var rootNode = n;
+var triple_store = new Array();
+var license_found = false;
+
+chrome.extension.sendRequest({data: "title", title: document.title});
+chrome.extension.sendRequest({data: "url", url: document.location.href});
+
+function add_triple(data_triple){
+
+ if (triple_store.length == 0) {
+
+ triple_store.push(data_triple);
+ if(data_triple[1]=="license"){
+
+ license_found = true;
+ chrome.extension.sendRequest({license: "namespace", url: data_triple[2]});
+
+ }
+
+
+ }
+ else {
+
+ var triple_not_found = false;
+
+ for (var x = 0; x < triple_store.length; x++) {
+
+ if (triple_store[x][0] != data_triple[0]) {
+
+ triple_store.push(data_triple);
+ triple_not_found = false;
+ break;
+
+ }
+
+ if(triple_store[x][1]!=data_triple[1]){
+
+ triple_not_found = true;
+
+ }else{
+
+ triple_not_found = false;
+ break;
+
+ }
+
+ }
+
+ if(triple_not_found){
+
+ triple_store.push(data_triple);
+ if(data_triple[1]=="license"){
+
+ license_found = true;
+ chrome.extension.sendRequest({license: "namespace", url: data_triple[2]});
+
+ }
+
+ }
+
+ }
+
+}
+
+namespace_data = "";
+
+while (n) {
+
+ if (n.nodeName != "LINK") {
+
+ if (n.hasAttributes()) {
+
+ temp_attr = {};
+
+ if (n.attributes.length != 1) {
+
+ var attr_names = ['about', 'src', 'resource', 'href', 'instanceof', 'typeof', 'rel', 'rev', 'property', 'content', 'datatype'];
+ rdfa_found = 0;
+ for (var i = 0; i < attr_names.length; i++) {
+
+ if (n.getAttribute(attr_names[i]) != null) {
+
+ temp_attr[attr_names[i]] = n.getAttribute(attr_names[i]);
+
+ if (n.getAttribute(attr_names[i]) != "nofollow") {
+
+ asset = "";
+ attribute = "";
+ value = "";
+
+ if (n.getAttribute(attr_names[i]).indexOf(":") == 2) {
+
+ attribute = n.getAttribute(attr_names[i]).substring(3);
+
+ }
+
+ if (attr_names[i] == "property") {
+
+ value = n.innerHTML;
+
+ }
+
+ if (n.getAttribute(attr_names[i]).indexOf("license") != -1 || n.getAttribute(attr_names[i]) == "copyright") {
+
+ value = n.getAttribute("href");
+ attribute = "license";
+
+ }
+
+ if (attr_names[i] == "href" && n.getAttribute(attr_names[i]).indexOf("http://") != -1) {
+
+ value = n.getAttribute("href");
+
+ }
+
+ if (asset == "") {
+
+ asset = document.location.href;
+
+ if (attribute == "") {
+
+ attribute = n.getAttribute(attr_names[i]);
+
+ }
+
+ }
+
+ if (attribute == "type") {
+
+ value = n.getAttribute("href")
+
+ }
+
+ if (attribute == "attributionName") {
+
+ value = n.getAttribute("href")
+
+ }
+
+ if (attribute == "attributionURL") {
+
+ value = n.innerHTML;
+
+ }
+
+ if (value != attribute) {
+
+ if (asset != null && attribute != null && value != null) {
+
+ if (asset.length != 0 && attribute.length != 0 && value.length != 0) {
+
+ base = document.location.href.split("/")[2];
+ if (value.indexOf("http://") == 0) {
+
+ if (base != value.split("/")[2]) {
+
+ triple_array = Array(asset, attribute, value);
+ add_triple(triple_array)
+ triple_array = Array();
+
+ }
+
+ }
+ else {
+
+ triple_array = Array(asset, attribute, value);
+ add_triple(triple_array)
+ triple_array = Array();
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ if (n.v) {
+ n.v = false;
+ if (n == rootNode) {
+ break;
+ }
+ if (n.nextSibling) {
+ n = n.nextSibling;
+ }
+ else {
+ n = n.parentNode;
+ }
+ }
+ else {
+ if (n.firstChild) {
+ n.v = true;
+ n = n.firstChild;
+ }
+ else
+ if (n.nextSibling) {
+ n = n.nextSibling;
+ }
+ else {
+ n = n.parentNode;
+ }
+ }
+
+
+}
+
+if(license_found){
+
+ chrome.extension.sendRequest({show: "icon", html: triple_store});
+
+}
+
+
View
BIN icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,22 @@
+{
+ "background_page": "background.html",
+ "content_scripts": [ {
+ "js": [ "content_script.js" ],
+ "matches": ["<all_urls>"],
+ "run_at": "document_idle"
+ } ],
+ "default_locale": "en_US",
+ "icons": {
+ "128": "icon.png"
+ },
+ "name": "OpenAttribute Chrome",
+ "page_action": {
+ "default_icon": "icon.png",
+ "default_title": "Get Attribution Info",
+ "popup": "popup.html"
+ },
+ "permissions": [ "tabs",
+ "<all_urls>"
+ ],
+ "version" : "0.1"
+}
View
@@ -0,0 +1,53 @@
+<html>
+ <head>
+ <script type="text/javascript">
+ function init() {
+
+ var bkg = chrome.extension.getBackgroundPage();
+
+ title = bkg.attribute_info.title;
+ url = bkg.attribute_info.url;
+ license = bkg.attribute_info.license;
+ license_link = bkg.attribute_info.license_link;
+ license_shorthand = bkg.attribute_info.license_shorthand ;
+ author = bkg.attribute_info.author;
+ attribution_url = bkg.attribute_info.attribution_url;
+
+ document.getElementById("container").innerHTML = "<p style=\"font-weight:bold\">" + title + "</p>";
+ attrib_string = '<span property="dct:title">' + title + '</span>';
+
+ document.getElementById("container").innerHTML += "<p style=\"font-size:80%\"> Source : " + url + "</p>";
+ attrib_string += '<span property="dct:title">' + title + '</span>';
+
+ if(author!=""){
+
+ if(attribution_url!=""){
+
+ document.getElementById("container").innerHTML += "<p style=\"font-size:80%\"> Author: <a href=\"" + attribution_url + "\">" + author + "</a></p>";
+ attrib_string += '<a rel="cc:attributionURL" ' + 'href="' + attribution_url + '">' + attribution_url + '</a>';
+ attrib_string += '<span property="cc:attributionName">' + author + '</span>';
+
+ }else{
+
+ document.getElementById("container").innerHTML += "<p style=\"font-size:80%\"> Author: " + author + "</p>";
+ attrib_string += '<span property="cc:attributionName">' + attribution_url + '</span>';
+
+ }
+
+ }
+
+ document.getElementById("container").innerHTML += "<p style=\"font-size:80%\"> License: <a target=\"_blank\" href=\"" + license_link + "\">" + license + "</a></p>";
+
+ attrib_string +='<a rel="license" href="' + license_link + '">' + license + " / " + license_shorthand + '</a>';
+ attrib_string = "<div xmlns:dc=\"http://dublincore.org/2010/10/11/dcterms.rdf#\" xmlns:cc\"http://creativecommons.org/#ns\" about=\"" + url + "\">" + attrib_string + "</a>";
+
+ document.getElementById("container").innerHTML += "<textarea rows=\"7\" cols=\"20\">" + attrib_string + "</textarea>";
+
+
+ }
+ </script>
+ </head>
+ <body onload="init();" style="font-family:arial; width:600px; height:auto">
+ <div id="container"></div>
+ </body>
+</html>

0 comments on commit 9f7b143

Please sign in to comment.