Greasy Fork is available in English.

Switch language button for tour.golang.org

给页面添加一个切换中/英文的按钮

Fra og med 16.11.2021. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

  1. // ==UserScript==
  2. // @name Switch language button for tour.golang.org
  3. // @namespace https://github.com/ipcjs/
  4. // @version 0.1
  5. // @description 给页面添加一个切换中/英文的按钮
  6. // @author ipcjs
  7. // @match https://tour.golang.org/*
  8. // @match https://tour.go-zh.org/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. const hosts = [
  13. "tour.golang.org",
  14. "tour.go-zh.org",
  15. ]
  16.  
  17.  
  18. function getNextHost() {
  19. const index = hosts.indexOf(location.host)
  20. return hosts[(index + 1) % hosts.length]
  21. }
  22.  
  23.  
  24. const $div = document.createElement('div')
  25.  
  26. $div.innerHTML = `<span class="nav" title="左键当前页面打开, 右键新页面打开">
  27. <svg height="100%" viewBox="0 0 24 24" width="100%">
  28. <path d="M0 0h24v24H0z" fill="none"/>
  29. <path d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"/>
  30. </svg>
  31. </span>`
  32. $div.addEventListener('click', () => {
  33. location.host = getNextHost()
  34. })
  35. $div.addEventListener('contextmenu', () => {
  36. const url = new URL(location.href)
  37. url.host = getNextHost()
  38. window.open(url)
  39. })
  40. const $topBar = document.querySelector('.top-bar')
  41. $topBar.appendChild($div)