[the-board/wip/http-api: 5/5] [chrome] Add initial code for The Board's chrome extension
- From: Lucas Rocha <lucasr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [the-board/wip/http-api: 5/5] [chrome] Add initial code for The Board's chrome extension
- Date: Tue, 23 Nov 2010 18:13:10 +0000 (UTC)
commit 653851a042dbe8bc7fdc11786fa1de3c2af18a65
Author: Lucas Rocha <lucasr gnome org>
Date: Tue Nov 23 18:11:21 2010 +0000
[chrome] Add initial code for The Board's chrome extension
src/chrome/background.html | 1 +
src/chrome/background.js | 91 ++++++++++++++++++++++++++++++++++++++++++++
src/chrome/icon.png | Bin 0 -> 353 bytes
src/chrome/manifest.json | 14 +++++++
4 files changed, 106 insertions(+), 0 deletions(-)
---
diff --git a/src/chrome/background.html b/src/chrome/background.html
new file mode 100644
index 0000000..ac3f43e
--- /dev/null
+++ b/src/chrome/background.html
@@ -0,0 +1 @@
+<script src="background.js"></script>
diff --git a/src/chrome/background.js b/src/chrome/background.js
new file mode 100644
index 0000000..34b69df
--- /dev/null
+++ b/src/chrome/background.js
@@ -0,0 +1,91 @@
+function callMethod(methodName, args, onLoad, onError) {
+ var req = new XMLHttpRequest();
+
+ var url = "http://localhost:2010/" + methodName;
+
+ if (args) {
+ url += "?";
+
+ var first = true;
+ for (argName in args) {
+ url += (first ? "" : "&") +
+ argName + "=" + args[argName];
+
+ first = false;
+ }
+ }
+
+ req.open("PUT", encodeURI(url), true);
+
+ if (onLoad) {
+ req.onload = onLoad;
+ }
+
+ if (onError) {
+ req.onerror = onError;
+ }
+
+ req.send(null);
+}
+
+function addNoteToTheBoard(text) {
+ var args = { thingId: "note",
+ text: text };
+
+ callMethod("addThing", args);
+}
+
+function addLabelToTheBoard(text) {
+ var args = { thingId: "label",
+ text: text };
+
+ callMethod("addThing", args);
+}
+
+function onMenuClick(info, tab) {
+ if ('linkUrl' in info) {
+ addLabelToTheBoard(info.linkUrl)
+ }
+
+ if ('selectionText' in info) {
+ addNoteToTheBoard(info.selectionText);
+ }
+}
+
+function pingTheBoard() {
+ var onPingError = function() {
+ console.log("#### error");
+ removeContextMenuItem();
+ };
+
+ var onPingResponse = function() {
+ console.log("#### success");
+ addContextMenuItem();
+ };
+
+ callMethod("ping", null, onPingResponse, onPingError);
+}
+
+var contextMenuItemId = null;
+
+function addContextMenuItem() {
+ if (contextMenuItemId) {
+ return;
+ }
+
+ contextMenuItemId =
+ chrome.contextMenus.create({ title: "Add to The Board",
+ contexts: ["selection", "link"],
+ onclick: onMenuClick });
+}
+
+function removeContextMenuItem() {
+ if (!contextMenuItemId) {
+ return;
+ }
+
+ chrome.contextMenus.remove(contextMenuItemId);
+ contextMenuItemId = null;
+}
+
+setInterval(pingTheBoard, 5000);
diff --git a/src/chrome/icon.png b/src/chrome/icon.png
new file mode 100644
index 0000000..265231f
Binary files /dev/null and b/src/chrome/icon.png differ
diff --git a/src/chrome/manifest.json b/src/chrome/manifest.json
new file mode 100644
index 0000000..3eba211
--- /dev/null
+++ b/src/chrome/manifest.json
@@ -0,0 +1,14 @@
+{
+ "name": "The Board",
+ "version": "0.1",
+ "description": "Chrome's integration with GNOME's The Board",
+ "background_page": "background.html",
+ "permissions": [
+ "contextMenus",
+ "notifications",
+ "http://localhost/"
+ ],
+ "icons": {
+ "16": "icon.png"
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]