Chinese/English vim/nvim documents jump

jump between online vim-English-document/vim-Chinese-document/nvim-document

  1. // ==UserScript==
  2. // @name Chinese/English vim/nvim documents jump
  3. // @name:zh 中文/英文 vim/nvim 文档切换跳转
  4. // @description jump between online vim-English-document/vim-Chinese-document/nvim-document
  5. // @namespace Violentmonkey Scripts
  6. // @match *://vimcdoc.sourceforge.net/doc/*
  7. // @match *://vimdoc.sourceforge.net/htmldoc/*
  8. // @match *://vimdoc.sourceforge.net/htmldoc/*
  9. // @match *://neovim.io/doc/user/*
  10. // @require https://cdn.bootcss.com/jquery/3.3.1/jquery.js
  11. // @grant none
  12. // @run-at document-end
  13. // @version 0.1
  14. // ==/UserScript==
  15.  
  16. /*jshint esversion: 6 */
  17. let currentURL = document.URL;
  18.  
  19. let documentBaseURL = {
  20. vim: 'http://vimdoc.sourceforge.net/htmldoc',
  21. cvim: 'http://vimcdoc.sourceforge.net/doc',
  22. nvim: 'https://neovim.io/doc/user'
  23. };
  24.  
  25. let suffixURL = currentURL.split('/').pop();
  26.  
  27. // 创建新的元素
  28. let otherDocuments = document.createElement('div');
  29.  
  30. otherDocuments.id = "otherLanguageDocuments";
  31.  
  32. for (let baseURL in documentBaseURL) {
  33. let oA = document.createElement('a');
  34. oA.innerHTML = baseURL;
  35. oA.href = `${documentBaseURL[baseURL]}/${suffixURL}`;
  36. //newDocumentURL[baseURL] = oA
  37. otherDocuments.appendChild(oA);
  38. otherDocuments.appendChild(document.createElement('br'));
  39. }
  40.  
  41. let body = document.getElementsByTagName('body')[0];
  42. body.appendChild(otherDocuments);
  43. otherDocuments.style = `visibility:hidden`
  44. //floatingDiv.css({position: 'fixed', bottom: bottom + 'px' , right: right + 'px'});
  45.  
  46.  
  47. $(document).ready(function() {
  48. let objWindow = $(window);
  49. let floatingDiv = $('#otherLanguageDocuments');
  50. let repositionTimes = 0;
  51. $(window).scroll(
  52. setInterval(function() {
  53. if(repositionTimes < 100) {
  54. setPostion(floatingDiv);
  55. repositionTimes += 1;
  56. }
  57. }, 100)
  58. );
  59.  
  60. $(window).mousemove(
  61. setInterval(function() {
  62. if(repositionTimes < 100) {
  63. setPostion(floatingDiv);
  64. repositionTimes += 1;
  65. }
  66. }, 100)
  67. );
  68.  
  69.  
  70. });
  71.  
  72. function setPostion(ele) {
  73. let bottom = Math.round(ele.height() * 2);
  74. let right = Math.round(ele.width() * 2);
  75. ele.css({position: 'fixed', bottom: bottom + 'px', right: right + 'px', visibility: 'visible'});
  76. }
  77.