跳转到AlphaXiv

增加到 AlphaXiv 的链接,并添加一个回到 ArXiv 的按钮

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name               ToAlphaXiv
// @name:zh-CN        跳转到AlphaXiv
// @name:ja            AlphaXivへ
// @namespace          http://tampermonkey.net/
// @version            2025-03-19-1
// @description        Add AlphaXiv link to arXiv abstract page, and add a button to go back
// @description:zh-cn  增加到 AlphaXiv 的链接,并添加一个回到 ArXiv 的按钮
// @description:ja     AlphaXiv へのリンクをインサート、そして戻るボタンも。
// @author             [email protected], [email protected]
// @match              https://arxiv.org/abs/*
// @match              https://www.arxiv.org/abs/*
// @match              https://www.alphaxiv.org/abs/*
// @match              https://alphaxiv.org/abs/*
// @icon               https://alphaxiv.org/icon.ico
// @grant              none
// @license            MIT
// ==/UserScript==
if (window.location.hostname === 'arxiv.org') {
    (function() {
        'use strict';
        const createLink = function(name, url) {
            const link = document.createElement('a');
            link.style.cssText = `display: inline-block; border-left: 2px solid #fff; padding-left: 10px; margin-left: 10px;`;
            link.target = '_blank';
            link.href = url;
            link.textContent = name;
            return link;
        };

        const href = window.location.href;
        const alphaXivEntry = createLink('AlphaXiv', href.replace('arxiv.org', 'alphaxiv.org'));

        const target = document.querySelector('.header-breadcrumbs');
        target.appendChild(alphaXivEntry);
    })();
} else {
    (function() {
        'use strict';
        const createLink = function(name, url) {
            const newButton = document.createElement('a');
            newButton.href = url;
            newButton.target = '_blank';
            newButton.className = 'group flex h-[30px] items-center justify-between rounded-lg border px-2 text-sm transition-all border-gray-600 bg-white text-gray-600 hover:bg-gray-100';

            const buttonText = document.createElement('span');
            buttonText.textContent = name;
            buttonText.className = 'font-medium text-gray-600';

            newButton.appendChild(buttonText);

            return newButton;
        };
        const observer = new MutationObserver(() => {
            const targetContainer = document.querySelector(".flex.items-center.space-x-2");
            if (targetContainer) {
                const href = window.location.href;
                const alphaXivEntry = createLink('Back to ArXiv', href.replace('alphaxiv.org', 'arxiv.org'));

                targetContainer.appendChild(alphaXivEntry);
                observer.disconnect(); // 停止监听
            }
        });

        observer.observe(document.body, { childList: true, subtree: true });
    })();
}