github.com/MangoDowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/misc/chrome/gophertool/popup.js (about) 1 function openURL(url) { 2 chrome.tabs.create({ "url": url }) 3 } 4 5 function addLinks() { 6 var links = document.getElementsByTagName("a"); 7 for (var i = 0; i < links.length; i++) { 8 var url = links[i].getAttribute("url"); 9 if (url) 10 links[i].addEventListener("click", function () { 11 openURL(this.getAttribute("url")); 12 }); 13 } 14 } 15 16 window.addEventListener("load", function () { 17 addLinks(); 18 console.log("hacking gopher pop-up loaded."); 19 document.getElementById("inputbox").focus(); 20 }); 21 22 window.addEventListener("submit", function () { 23 console.log("submitting form"); 24 var box = document.getElementById("inputbox"); 25 box.focus(); 26 27 var t = box.value; 28 if (t == "") { 29 return false; 30 } 31 32 var success = function(url) { 33 console.log("matched " + t + " to: " + url) 34 box.value = ""; 35 openURL(url); 36 return false; // cancel form submission 37 }; 38 39 var url = urlForInput(t); 40 if (url) { 41 return success(url); 42 } 43 44 console.log("no match for text: " + t) 45 return false; 46 });