Wiley Direct PDF

Download PDF from Wiley Online Library without redirecting page.

目前为 2017-11-24 提交的版本。查看 最新版本

// ==UserScript==
// @name         Wiley Direct PDF
// @namespace    http://itianda.com/
// @version      0.1
// @description  Download PDF from Wiley Online Library without redirecting page.
// @author       itianda
// @match        http://onlinelibrary.wiley.com/doi/*/*/abstract
// @match        http://onlinelibrary.wiley.com/doi/*/*/full
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var oPDFRedirecting = document.querySelector('a.js-infopane-pdf');
    if (oPDFRedirecting) {
        var sPDFRedirecting = oPDFRedirecting.getAttribute('href');
        fetch(sPDFRedirecting).then(function(res){
            if (res.ok) {
                res.text().then(function(text) {
                    var r = /<iframe id="pdfDocument" src="(.+?)" width="100%" height=/.exec(text);
                    if (r) {
                        var sPDFLink = r[1];
                        var oPDFRedirecting = document.querySelector('a.js-infopane-epdf');
                        oPDFRedirecting.setAttribute('href', sPDFLink);
                        oPDFRedirecting.onclick = function(event) {
                            event.preventDefault();
                        };
                        oPDFRedirecting.style.color = 'red';
                        return;
                    }
                });
            }
        });
    }
})();