CNKI-DOI-Jump

DOI-Jump with middle click on any DOI on schlr.cnki.net

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            CNKI-DOI-Jump
// @match           https://schlr.cnki.net/*
// @require         https://code.jquery.com/jquery-latest.min.js
// @license         MIT
// @grant           GM_addStyle
// @description     DOI-Jump with middle click on any DOI on schlr.cnki.net
// @version 0.0.1.20221102045724
// @namespace https://greasyfork.org/users/978257
// ==/UserScript==
//================================================== settings
//variables
const
    regex = '(10\.[0-9]{4,}(?:\.[0-9]+)*/(?:(?![%"&\'<>#? ])\\S)+)',
    doiRegex = new RegExp('(?:' + regex + ')', 'i')

//================================================== find DOI
function findDOI(element){
    if($(element).is("[href*='org/10.']"))
        return $(element).attr("href").split('org/')[1].trim();
    if($(element).text().match(doiRegex)!==null)
        return $(element).text().match(doiRegex)[0].trim();
    return false;
}
$(document).ready(function(){
//================================================== find middle click on doi
    $(document).on('mousedown', function(e){
        switch(e.which)
        {
        case 2:
            //prevent the default function of the clicked element
            e.preventDefault();

            //if clicked element returned valid DOI
            if(findDOI(e.target)){
                window.open('https://dx.doi.org/'+findDOI(e.target));
                }
        break;    
        }
    });
});