Greasy Fork

Greasy Fork is available in English.

Arxiv跳转翻译

Jump to translation from any arxiv papaers!

当前为 2023-12-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Arxiv跳转翻译
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  Jump to translation from any arxiv papaers!
// @author       ziuch
// @match        https://arxiv.org/abs/*
// @match        https://arxiv.org/pdf/*
// @icon         https://static.arxiv.org/static/browse/0.3.4/images/icons/favicon-32x32.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';
  // Your code here...
  if (window.top !== window.self) {
    return
  }
  function _appendCss(css, name) {
    var head = document.head || document.getElementsByTagName('head')[0];
    var style = document.createElement('style');
    style.setAttribute("data-component", name);
    style.innerHTML = css;
    head.appendChild(style);

      // Create a new style element
      var style1 = document.createElement('style');
      style.type = 'text/css';

      // Define your keyframes and other CSS as a string
      var keyFrames = `
@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.85;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}`;

      // Set the innerHTML of the style element to your CSS string
      style1.innerHTML = keyFrames;

      // Append the style element to the head of the document
      document.head.appendChild(style1);

  }
  function addStyle() {
    //debugger;
    let via_markdown_css = `.via-markdown-btn{display: inline-block; vertical-align: middle; height: 80px; width:80px; border: 1px solid transparent; padding: 0 18px; background-color: #009688; color: #fff; white-space: nowrap; text-align: center; font-size: 18px; border-radius: 2px; cursor: pointer; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none;}.via-markdown-btn-sm{height: 20px; line-height: 20px; padding: 0 6px; font-size: 18px;}`;
    _appendCss(via_markdown_css, "btn");
  }
  //创建复制按钮
  function addBtn() {
    var btn = document.createElement('button');
    btn.style = "top: 280px;left:8px; position: fixed;z-index:1000;cursor:pointer;background:rgba(179, 27, 27,0.9);height: 80px;wight:80px;border-radius: 50%; animation: pulse 2s infinite;font-size: 25px;"
    btn.className = "via-markdown-btn via-markdown-btn-sm"
    btn.innerHTML = "翻译"
    btn.id = "copyBtn"
    document.body.appendChild(btn);
  }
  addStyle();
  addBtn();
  let isclick = false; // 防止过快重复点击
  var $btn = document.getElementById("copyBtn")
  $btn.addEventListener("click", jump);
  document.addEventListener("dblclick",jump);
  function jump() {
      if (!isclick) {
          var url = `${document.URL}`
          console.log("orgin => " + url);
          // 使用 replace 方法进行替换
          var target_url = url.replace('arxiv', 'ar5iv');
          console.log("new => " + target_url);
          window.open(target_url);
      }
  }
})();