diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /misc/chrome/gophertool | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-upstream/1.1_hg20130304.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'misc/chrome/gophertool')
-rw-r--r-- | misc/chrome/gophertool/background.html | 14 | ||||
-rw-r--r-- | misc/chrome/gophertool/background.js | 9 | ||||
-rw-r--r-- | misc/chrome/gophertool/gopher.js | 2 | ||||
-rw-r--r-- | misc/chrome/gophertool/manifest.json | 7 | ||||
-rw-r--r-- | misc/chrome/gophertool/popup.html | 51 | ||||
-rw-r--r-- | misc/chrome/gophertool/popup.js | 46 |
6 files changed, 70 insertions, 59 deletions
diff --git a/misc/chrome/gophertool/background.html b/misc/chrome/gophertool/background.html index 058c18142..06daa98b1 100644 --- a/misc/chrome/gophertool/background.html +++ b/misc/chrome/gophertool/background.html @@ -6,19 +6,7 @@ --> <head> <script src="gopher.js"></script> -<script> - -chrome.omnibox.onInputEntered.addListener(function(t) { - var url = urlForInput(t); - if (url) { - chrome.tabs.getSelected(null, function(tab) { - if (!tab) return; - chrome.tabs.update(tab.id, { "url": url, "selected": true }); - }); - } -}); - -</script> +<script src="background.js"></script> </head> </html> diff --git a/misc/chrome/gophertool/background.js b/misc/chrome/gophertool/background.js new file mode 100644 index 000000000..d18faa986 --- /dev/null +++ b/misc/chrome/gophertool/background.js @@ -0,0 +1,9 @@ +chrome.omnibox.onInputEntered.addListener(function(t) { + var url = urlForInput(t); + if (url) { + chrome.tabs.getSelected(null, function(tab) { + if (!tab) return; + chrome.tabs.update(tab.id, { "url": url, "selected": true }); + }); + } +}); diff --git a/misc/chrome/gophertool/gopher.js b/misc/chrome/gophertool/gopher.js index 847c1c70d..3238f0fcc 100644 --- a/misc/chrome/gophertool/gopher.js +++ b/misc/chrome/gophertool/gopher.js @@ -12,7 +12,7 @@ function urlForInput(t) { } if (numericRE.test(t)) { - if (t < 1000000) { + if (t < 150000) { return "http://code.google.com/p/go/issues/detail?id=" + t; } return "http://codereview.appspot.com/" + t + "/"; diff --git a/misc/chrome/gophertool/manifest.json b/misc/chrome/gophertool/manifest.json index 3a2540a86..04386594a 100644 --- a/misc/chrome/gophertool/manifest.json +++ b/misc/chrome/gophertool/manifest.json @@ -1,11 +1,14 @@ { "name": "Hacking Gopher", "version": "1.0", + "manifest_version": 2, "description": "Go Hacking utility", - "background_page": "background.html", + "background": { + "page": "background.html" + }, "browser_action": { "default_icon": "gopher.png", - "popup": "popup.html" + "default_popup": "popup.html" }, "omnibox": { "keyword": "golang" }, "icons": { diff --git a/misc/chrome/gophertool/popup.html b/misc/chrome/gophertool/popup.html index 4816c392b..8bb7795fa 100644 --- a/misc/chrome/gophertool/popup.html +++ b/misc/chrome/gophertool/popup.html @@ -6,49 +6,14 @@ --> <head> <script src="gopher.js"></script> -<script> - -function focusinput() { - document.getElementById("inputbox").focus(); -} - -function navigate() { - var box = document.getElementById("inputbox"); - box.focus(); - - var t = box.value; - if (t == "") { - return false; - } - - var success = function(url) { - console.log("matched " + t + " to: " + url) - box.value = ""; - openURL(url); - return false; // cancel form submission - }; - - var url = urlForInput(t); - if (url) { - return success(url); - } - - console.log("no match for text: " + t) - return false; -} - -function openURL(url) { - chrome.tabs.create({ "url": url }) -} - -</script> +<script src="popup.js"></script> </head> -<body onload="focusinput()" style='margin: 0.5em; font-family: sans;'> -<small><a href="#" onclick="openURL('http://code.google.com/p/go/issues/list')">issue</a>, -<a href="#" onclick="openURL('http://codereview.appspot.com/')">codereview</a>, -<a href="#" onclick="openURL('http://code.google.com/p/go/source/list')">commit</a>, or -<a href="#" onclick="openURL('http://golang.org/pkg/')">pkg</a> id/name:</small> -<form style='margin: 0' onsubmit="return navigate();"><nobr><input id="inputbox" size=10 /><input type="submit" value="go" /></nobr></form> -<small>Also: <a href="#" onclick="openURL('http://build.golang.org/')">buildbots</small> +<body style='margin: 0.5em; font-family: sans;'> +<small><a href="#" url="http://code.google.com/p/go/issues/list">issue</a>, +<a href="#" url="http://codereview.appspot.com/">codereview</a>, +<a href="#" url="http://code.google.com/p/go/source/list">commit</a>, or +<a href="#" url="http://golang.org/pkg/">pkg</a> id/name:</small> +<form style='margin: 0' id='navform'><nobr><input id="inputbox" size=10 tabindex=1 /><input type="submit" value="go" /></nobr></form> +<small>Also: <a href="#" url="http://build.golang.org">buildbots</a></small> </body> </html> diff --git a/misc/chrome/gophertool/popup.js b/misc/chrome/gophertool/popup.js new file mode 100644 index 000000000..410d65120 --- /dev/null +++ b/misc/chrome/gophertool/popup.js @@ -0,0 +1,46 @@ +function openURL(url) { + chrome.tabs.create({ "url": url }) +} + +function addLinks() { + var links = document.getElementsByTagName("a"); + for (var i = 0; i < links.length; i++) { + var url = links[i].getAttribute("url"); + if (url) + links[i].addEventListener("click", function () { + openURL(this.getAttribute("url")); + }); + } +} + +window.addEventListener("load", function () { + addLinks(); + console.log("hacking gopher pop-up loaded."); + document.getElementById("inputbox").focus(); +}); + +window.addEventListener("submit", function () { + console.log("submitting form"); + var box = document.getElementById("inputbox"); + box.focus(); + + var t = box.value; + if (t == "") { + return false; + } + + var success = function(url) { + console.log("matched " + t + " to: " + url) + box.value = ""; + openURL(url); + return false; // cancel form submission + }; + + var url = urlForInput(t); + if (url) { + return success(url); + } + + console.log("no match for text: " + t) + return false; +}); |