Greasy Fork

Greasy Fork is available in English.

Enhanced arXiv

Add some functions for arXiv

当前为 2020-11-16 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Enhanced arXiv
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add some functions for arXiv
// @author       You
// @match        https://arxiv.org/abs/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function createButton(prompt, callback) {
        return `<button style="margin:0 8px;" class="button is-small" onclick='window.${callback}()'>${prompt}</button>`
    }

    function main() {
        init();
        let targetElement = document.getElementsByClassName("authors")[0];
        let copyTitleButton = createButton("Copy Title", "copyTitle");
        let copyPDFLinkButton = createButton("Copy PDF Link", "copyPDFLink");
        let searchGoogleButton = createButton("Search With Google", "searchGoogle");
        targetElement.insertAdjacentHTML('beforeend', copyTitleButton);
        targetElement.insertAdjacentHTML('beforeend', copyPDFLinkButton);
        targetElement.insertAdjacentHTML('beforeend', searchGoogleButton);
    }

    function init() {
        let hiddenTextArea = document.createElement('textarea');
        hiddenTextArea.setAttribute("id", "hiddenTextArea");
        hiddenTextArea.style.cssText = "display:hidden;";
        document.body.appendChild(hiddenTextArea);
        window.copyText = copyText;
        window.copyTitle = copyTitle;
        window.getPaperTitle = getPaperTitle;
        window.copyPDFLink = copyPDFLink;
        window.searchGoogle = searchGoogle;
    }

    function copyText(text) {
        const textArea = document.getElementById('hiddenTextArea');
        textArea.textContent = text;
        document.body.append(textArea);
        textArea.select();
        document.execCommand("copy");
    }

    function getPaperTitle() {
        let title = document.getElementsByTagName("h1")[2].textContent;
        title = title.replace("Title:", "");
        return title;
    }

    function copyTitle() {
        let title = window.getPaperTitle();
        window.copyText(title)
    }

    function copyPDFLink() {
        let link = document.getElementsByClassName("download-pdf")[0].href;
        window.copyText(link)
    }

    function searchGoogle() {
        let title = window.getPaperTitle();
        window.open(`https://www.google.com/search?q=${title}`);
    }
    main();
})();