Chinese/English vim/nvim documents jump

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name Chinese/English vim/nvim documents jump
// @name:zh 中文/英文 vim/nvim 文档切换跳转
// @description jump between online vim-English-document/vim-Chinese-document/nvim-document
// @namespace Violentmonkey Scripts
// @match *://vimcdoc.sourceforge.net/doc/*
// @match *://vimdoc.sourceforge.net/htmldoc/*
// @match *://vimdoc.sourceforge.net/htmldoc/*
// @match *://neovim.io/doc/user/*
// @require https://cdn.bootcss.com/jquery/3.3.1/jquery.js
// @grant none
// @run-at document-end
// @version 0.1
// ==/UserScript==

/*jshint esversion: 6 */
let currentURL = document.URL;

let documentBaseURL = {
  vim: 'http://vimdoc.sourceforge.net/htmldoc',
  cvim: 'http://vimcdoc.sourceforge.net/doc',
  nvim: 'https://neovim.io/doc/user'
};

let suffixURL = currentURL.split('/').pop();

// 创建新的元素
let otherDocuments = document.createElement('div');

otherDocuments.id = "otherLanguageDocuments";

for (let baseURL in documentBaseURL) {
  let oA = document.createElement('a');
  oA.innerHTML = baseURL;
  oA.href = `${documentBaseURL[baseURL]}/${suffixURL}`;
  //newDocumentURL[baseURL] = oA
  otherDocuments.appendChild(oA);
  otherDocuments.appendChild(document.createElement('br'));
}

let body = document.getElementsByTagName('body')[0];
body.appendChild(otherDocuments);
otherDocuments.style = `visibility:hidden`
//floatingDiv.css({position: 'fixed', bottom: bottom + 'px' , right: right + 'px'});


$(document).ready(function() {
  let objWindow = $(window);
  let floatingDiv = $('#otherLanguageDocuments');
  let repositionTimes = 0;
  $(window).scroll(
    setInterval(function() {
      if(repositionTimes < 100) {
        setPostion(floatingDiv);
        repositionTimes += 1;
      }
    }, 100)
  );

  $(window).mousemove(
    setInterval(function() {
      if(repositionTimes < 100) {
        setPostion(floatingDiv);
        repositionTimes += 1;
      }
    }, 100)
  );


});

function setPostion(ele) {
  let bottom = Math.round(ele.height() * 2);
  let right = Math.round(ele.width() * 2);
  ele.css({position: 'fixed', bottom: bottom + 'px', right: right + 'px', visibility: 'visible'});
}