// ==UserScript== // @name Switch language button for tour.golang.org // @namespace https://github.com/ipcjs/ // @version 0.2 // @description 给页面添加一个切换中/英文的按钮 // @author ipcjs // @icon https://www.google.com/s2/favicons?domain=golang.org // @match https://tour.golang.org/* // @match https://tour.go-zh.org/* // @grant none // @downloadURL none // ==/UserScript== const hosts = [ "tour.golang.org", "tour.go-zh.org", ] function getNextHost() { const index = hosts.indexOf(location.host) return hosts[(index + 1) % hosts.length] } const $div = document.createElement('div') $div.innerHTML = ` ` $div.addEventListener('click', () => { location.host = getNextHost() }) $div.addEventListener('contextmenu', () => { const url = new URL(location.href) url.host = getNextHost() window.open(url) }) const $topBar = document.querySelector('.top-bar') $topBar.appendChild($div)