diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000..c76ccae --- /dev/null +++ b/.bowerrc @@ -0,0 +1,6 @@ +{ + "directory":"js/lib/", + "scripts": { + "postinstall": "grunt bowerRequirejs" + } +} diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..f6fa46c --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,31 @@ +/*global module:false*/ +module.exports = function(grunt) { + + // Project configuration. + grunt.initConfig({ + // Metadata. + pkg: grunt.file.readJSON('package.json'), + banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + + '<%= grunt.template.today("yyyy-mm-dd") %>\n' + + '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + + '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', + // Task configuration. + bowerRequirejs: { + target: { + rjsConfig: 'js/common.js', + options: { + baseUrl: './js/lib', + transitive: true + } + } + } + }); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-bower-requirejs'); + + // Default task. + grunt.registerTask('default', ['bowerRequirejs']); + +}; diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..26f37f8 --- /dev/null +++ b/bower.json @@ -0,0 +1,31 @@ +{ + "name": "eexcess", + "version": "0.0.1", + "authors": [ + "eexcess consortium " + ], + "description": "Enhancing Euroupe's eXchange in Cultural, Educational and Scientific reSources", + "moduleType": [ + "amd", + "globals" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "lib/", + "test", + "tests" + ], + "dependencies": { + "requirejs": "~2.1.17", + "jquery": "~2.1.4", + "c4": "https://github.com/EEXCESS/c4.git" + }, + "devDependencies": { + "requirejs": "~2.1.17", + "jquery": "~2.1.4", + "c4": "https://github.com/EEXCESS/c4.git" + } +} diff --git a/html/background.html b/html/background.html new file mode 100644 index 0000000..2d888e3 --- /dev/null +++ b/html/background.html @@ -0,0 +1,15 @@ + + + + + + + + +
TODO write content
+ + + diff --git a/js/background.js b/js/background.js new file mode 100644 index 0000000..8bf7124 --- /dev/null +++ b/js/background.js @@ -0,0 +1,40 @@ +require(['./common'], function(common) { + require(['c4/APIconnector'], function(APIconnector) { + var msgAllTabs = function(msg) { + chrome.tabs.query({}, function(tabs) { + for (var i = 0, len = tabs.length; i < len; i++) { + chrome.tabs.sendMessage(tabs[i].id, msg); + } + }); + }; + + + chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { + if (typeof msg.method !== 'undefined') { + switch (msg.method) { + case 'triggerQuery': + console.log(msg.data); + APIconnector.query(msg.data, function(response) { + if (response.status === 'success') { + msgAllTabs({ + method: 'newResults', + data: {profile: msg.data, results: {results: response.data.result}} + }); + } else { + msgAllTabs({method: 'error', data: response.data}); + } + console.log(response.status); + console.log(response.data); + }); + break; + default: + console.log('unknown method: ' + msg.method); + break; + } + } else { + console.log('method not specified'); + } + }); + }); +}); + diff --git a/js/common.js b/js/common.js new file mode 100644 index 0000000..8770d65 --- /dev/null +++ b/js/common.js @@ -0,0 +1,11 @@ +require.config({ + shim: { + + }, + baseUrl: "/js/lib", + paths: { + }, + packages: [ + + ] +}); diff --git a/js/content.js b/js/content.js new file mode 100644 index 0000000..107be73 --- /dev/null +++ b/js/content.js @@ -0,0 +1,84 @@ +require(['c4/searchBar', 'c4/paragraphDetection', 'c4/namedEntityRecognition', 'c4/iframes'], function(searchBar, paragraphDetection, ner, iframes) { + searchBar.init(function(profile) { + chrome.runtime.sendMessage({method: 'triggerQuery', data: profile}); + iframes.sendMsgAll({event: 'eexcess.queryTriggered'}); + searchBar.show(); + }); + window.onmessage = function(e) { + console.log(e.data); + // do something + }; + + // detect paragraphs + var p = paragraphDetection.getParagraphs(); + + // enrich paragraphs with entities + ner.entitiesAndCategories(p.map(function(par) { + return { + id: par.id, + headline: par.headline, + content: par.content + }; + }), function(result) { + if (result.status && result.status === 'success') { + paragraphDetection.enrichParagraphs(p, result.data.paragraphs); + console.log(p); + } + }); + + // selection listener + $(document).mouseup(function() { + var selection = paragraphDetection.getSelection(p); + if(selection.selection.length > 0) { + var profile = { + // TODO: split terms + contextKeywords: [{ + text:selection.selection, + weight:1.0 + }] + }; + if(selection.entities) { + profile.contextNamedEntities = selection.entities; + } + // TODO: provide reason + chrome.runtime.sendMessage({method: 'triggerQuery', data: profile}); + iframes.sendMsgAll({event: 'eexcess.queryTriggered'}); + searchBar.show(); + } + console.log(selection); + }); + + // augment links + $(function() { + paragraphDetection.augmentLinks( + $('.' + paragraphDetection.getSettings().classname), + chrome.extension.getURL('media/icons/19.png'), + function(profile) { + // TODO: provide reason + chrome.runtime.sendMessage({method: 'triggerQuery', data: profile}); + iframes.sendMsgAll({event: 'eexcess.queryTriggered'}); + searchBar.show(); + }, + paragraphDetection.getSettings().classname, p + ); + }); + + chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { + console.log(msg); + if (msg.method) { + switch (msg.method) { + case 'newResults': + iframes.sendMsgAll({event: 'eexcess.newResults', data: msg.data}); + break; + case 'error': + iframes.sendMsgAll({event: 'eexcess.error', data: msg.data}); + break; + default: + console.log('unknown method'); + break; + } + } else { + console.log('method not specified'); + } + }); +}); \ No newline at end of file diff --git a/js/requireContent.js b/js/requireContent.js new file mode 100644 index 0000000..2632714 --- /dev/null +++ b/js/requireContent.js @@ -0,0 +1,12 @@ +require.load = function(context, moduleName, url) { + var xhr; + xhr = new XMLHttpRequest(); + xhr.open('GET', chrome.extension.getURL(url) + '?=' + (new Date()).getTime(), true); + xhr.onreadystatechange = function(e) { + if(xhr.readyState === 4 && xhr.status === 200) { + eval(xhr.responseText); + context.completeLoad(moduleName); + } + }; + xhr.send(null); +}; \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..6a0899c --- /dev/null +++ b/manifest.json @@ -0,0 +1,34 @@ +{ + "name": "EEXCESS_DEV", + "version": "0.11", + "background": { + "page": "html/background.html" + }, + "content_scripts": [ + { + "matches": [""], + "run_at":"document_end", + "js": ["js/lib/requirejs/require.js","js/requireContent.js","js/common.js","js/content.js"], + "css": [] + } + ], + + "web_accessible_resources": [ + "js/*", + "external/*", + "media/*" + ], + "manifest_version": 2, + "permissions": [ + "tabs", + "", + "geolocation", + "history", + "background", + "storage" + ], + "icons": {"16": "media/icons/16.png", + "48": "media/icons/48.png", + "128": "media/icons/128.png"} +} + diff --git a/media/icons/128.png b/media/icons/128.png new file mode 100644 index 0000000..6b156cd Binary files /dev/null and b/media/icons/128.png differ diff --git a/media/icons/16.png b/media/icons/16.png new file mode 100644 index 0000000..5113a01 Binary files /dev/null and b/media/icons/16.png differ diff --git a/media/icons/19.png b/media/icons/19.png new file mode 100644 index 0000000..3a8a3c3 Binary files /dev/null and b/media/icons/19.png differ diff --git a/media/icons/38.png b/media/icons/38.png new file mode 100644 index 0000000..04b286a Binary files /dev/null and b/media/icons/38.png differ diff --git a/media/icons/48.png b/media/icons/48.png new file mode 100644 index 0000000..36b04ab Binary files /dev/null and b/media/icons/48.png differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..f22f49c --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "engines": { + "node": ">= 0.10.0" + }, + "devDependencies": { + "bower": "^1.4.1", + "grunt": "^0.4.5", + "grunt-bower-requirejs": "^2.0.0" + } +}