Rust Doc to Chinese ver

Jump to chinese version of this doc page

  1. // ==UserScript==
  2. // @name Rust Doc to Chinese ver
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Jump to chinese version of this doc page
  6. // @author 安逐悲
  7. // @match *://doc.rust-lang.org/*
  8. // @icon https://www.rust-lang.org/static/images/rust-logo-blk.svg
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. const AllUrl="https://rustwiki.org";
  16. const TargetUrl="https://rustwiki.org/zh-CN";
  17. let head=document.querySelector('.search-form');
  18. let btn = document.createElement('button');
  19. btn.type='button';
  20. let currentUrl= document.URL;
  21. const hostname = window.location.hostname;
  22. const path = currentUrl.split(hostname)[1];
  23.  
  24. btn.textContent = '转到中文站';
  25.  
  26. btn.addEventListener('click',() => {
  27. window.location.href = TargetUrl+path;
  28. });
  29. head.appendChild(btn);
  30. })();