用 Go 语言来编写 Chrome 扩展:Gopherjs Chrome Bindings

jopen 9年前

该项目可以让你用 Go 语言来编写 Chrome 扩展。在Gopherjs transpiler的帮助下,可以用Go编写能被转换为JS并能运行在浏览器的代码。此库以简单而直观的方式包括了与Chrome JS API交互的必要绑定, 以便你能够用Go编写Chrome插件和Chrome OS应用

Write Chrome extensions in Go!

With the help of the Gopherjs transpiler, you can now write Go code which will be converted into javascript and run in the browser. This library contains the necessary bindings to interact with the Chrome Javascript API in an easy and intuitive way so that you can write Chrome Extensions and Chrome OS apps in Go.

示例代码:

package main     import (      "strconv"      "honnef.co/go/js/dom"      "github.com/fabioberger/chrome"  )     func main() {      c := chrome.NewChrome()         tabDetails := chrome.Object{          "active": false,      }      c.Tabs.Create(tabDetails, func(tab chrome.Tab) {          notification := "Tab with id: " + strconv.Itoa(tab.Id) + " created!"          dom.GetWindow().Document().GetElementByID("notification").SetInnerHTML(notification)      })     }

项目主页:http://www.open-open.com/lib/view/home/1427774317193