arXiv Redirect and Rename

Slove the "Access Denied" problem in arXiv

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         arXiv Redirect and Rename
// @include      https://arxiv.org/*
// @version      1.0
// @description  Slove the "Access Denied" problem in arXiv
//               And rename the download pdf
// @author       Daqing Liu
// @date         2020.01.07
// @namespace    http://home.ustc.edu.cn/~liudq/
// ==/UserScript==

// fork from EvanL00
var dow = function() {
    'use strict';
    // find the title
    var title = document.getElementsByClassName("title mathjax")[0].innerText;
    //find where to put the tag
    var loc = document.getElementsByClassName("full-text")[0].getElementsByTagName('ul');
    var obj = document.createElement("li");
    //get the pdf url
    var pdfurl = document.getElementsByClassName("full-text")[0].getElementsByTagName('ul')[0].getElementsByTagName('a')[0].href;
    //check name
    if (!pdfurl.endsWith(".pdf")) {
     pdfurl = pdfurl + '.pdf';
    }
    //change name
    var fileName = document.title.replace(/\.\d*/, '') + '.pdf';
    obj.innerHTML = '<a download='+ '"'+ fileName + '"' + ' href=' + pdfurl +'>Save as PDF</a>';
    loc[0].insertBefore(obj, loc[0].childNodes[0]);
};
dow();

var rename = function() {
    var content;
    var CheckStr = 'Access Denied';
    var IsRedirect = false;

    var stre = document.getElementsByTagName('h1');

    var i;
    for (i = 0; i < stre.length; i++) {
        content = stre[i].innerText;
        if(content.indexOf(CheckStr) != -1){
            IsRedirect = true;
        }
    }

    if(IsRedirect){
        var url = window.location.toString();
        window.location = url.replace('https://arxiv.org/', 'http://cn.arxiv.org/');
    }
};
rename();