[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 23:16:58 +0000 (UTC)
commit a680fa3df8da808551f4a50eb175a564b57cd436
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 | 102 ++++++++++++++++++++++++++++++++++++++++++++
src/chrome/icon.png | Bin 0 -> 353 bytes
src/chrome/manifest.json | 14 ++++++
4 files changed, 117 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..da72c30
--- /dev/null
+++ b/src/chrome/background.js
@@ -0,0 +1,102 @@
+var _THE_BOARD_URL = "http://localhost:2010/";
+
+function callMethod(methodName, args, onLoad, onError) {
+ var req = new XMLHttpRequest();
+
+ var url = _THE_BOARD_URL + methodName;
+
+ if (args) {
+ url += "?";
+
+ var first = true;
+ for (argName in args) {
+ url += (first ? "" : "&") +
+ argName + "=" + args[argName];
+
+ first = false;
+ }
+ }
+
+ req.open("PUT", encodeURI(url), true);
+
+ var onLoadInternal = function() {
+ onLoad(req.responseText);
+ }
+
+ var onErrorInternal = function() {
+ onError();
+ }
+
+ if (onLoad) {
+ req.onload = onLoadInternal;
+ }
+
+ if (onError) {
+ req.onerror = onErrorInternal;
+ }
+
+ 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() {
+ removeContextMenuItem();
+ };
+
+ var onPingResponse = function() {
+ 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;
+}
+
+// FIXME: It's a bit bad that we have to keep
+// polling The Board to know if it's available.
+// Maybe there's a nicer way to do this?
+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]