summaryrefslogtreecommitdiffstats
path: root/misc/chrome/gophertool/popup.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 13:14:23 +0000
commit73df946d56c74384511a194dd01dbe099584fd1a (patch)
treefd0bcea490dd81327ddfbb31e215439672c9a068 /misc/chrome/gophertool/popup.js
parentInitial commit. (diff)
downloadgolang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.tar.xz
golang-1.16-73df946d56c74384511a194dd01dbe099584fd1a.zip
Adding upstream version 1.16.10.upstream/1.16.10upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/chrome/gophertool/popup.js')
-rw-r--r--misc/chrome/gophertool/popup.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/misc/chrome/gophertool/popup.js b/misc/chrome/gophertool/popup.js
new file mode 100644
index 0000000..410d651
--- /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;
+});