From 9e811683f1e4138820f0caaec20041c57c302f73 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 7 Oct 2012 17:56:10 -0700 Subject: [PATCH] gophertool: make work with latest Chrome extension security restrictions No JavaScript in HTML anymore. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/6619066 --- misc/chrome/gophertool/background.html | 14 +-------- misc/chrome/gophertool/background.js | 9 ++++++ misc/chrome/gophertool/popup.html | 43 +++----------------------- misc/chrome/gophertool/popup.js | 38 +++++++++++++++++++++++ 4 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 misc/chrome/gophertool/background.js create mode 100644 misc/chrome/gophertool/popup.js diff --git a/misc/chrome/gophertool/background.html b/misc/chrome/gophertool/background.html index 058c18142b..06daa98b14 100644 --- a/misc/chrome/gophertool/background.html +++ b/misc/chrome/gophertool/background.html @@ -6,19 +6,7 @@ --> - + diff --git a/misc/chrome/gophertool/background.js b/misc/chrome/gophertool/background.js new file mode 100644 index 0000000000..d18faa986f --- /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/popup.html b/misc/chrome/gophertool/popup.html index a569392d0d..aec10048a3 100644 --- a/misc/chrome/gophertool/popup.html +++ b/misc/chrome/gophertool/popup.html @@ -6,49 +6,14 @@ --> - + - + issue, codereview, commit, or pkg id/name: -
-Also: buildbots + +Also: buildbots diff --git a/misc/chrome/gophertool/popup.js b/misc/chrome/gophertool/popup.js new file mode 100644 index 0000000000..717fc169cd --- /dev/null +++ b/misc/chrome/gophertool/popup.js @@ -0,0 +1,38 @@ +function openURL(url) { + chrome.tabs.create({ "url": url }) +} + +window.addEventListener("load", function () { + 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; +}); + +window.addEventListener("click", function () { + openURL("http://build.golang.org/"); +});