2012-10-07 18:56:10 -06:00
|
|
|
function openURL(url) {
|
|
|
|
chrome.tabs.create({ "url": url })
|
|
|
|
}
|
|
|
|
|
2012-10-21 11:05:21 -06:00
|
|
|
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"));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-07 18:56:10 -06:00
|
|
|
window.addEventListener("load", function () {
|
2012-10-21 11:05:21 -06:00
|
|
|
addLinks();
|
2012-10-07 18:56:10 -06:00
|
|
|
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;
|
|
|
|
});
|