Sage Journals Redirect

将Sage期刊请求重定向至中国镜像站

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Sage Journals Redirect
// @version      0.3
// @description  将Sage期刊请求重定向至中国镜像站
// @namespace    https://greasyfork.org/en/users/30-opsomh
// @match        *://journals.sagepub.com/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const currentUrl = new URL(location.href);

    // 仅处理主站请求
    if (currentUrl.hostname !== 'journals.sagepub.com') return;

    // 提取DOI编号(支持多种URL结构)
    const doiPathRegex = /^\/(?:doi|loi)\/(?:abs|full|pdf|epub)\/(.+)/;
    const match = currentUrl.pathname.match(doiPathRegex);

    if (match) {
        window.stop(); // 立即停止加载

        const doi = match[1].replace(/\/$/, ''); // 去除可能存在的末尾斜杠
        const newUrl = new URL(`https://sage.cnpereading.com/paragraph/article/`);

        // 构建查询参数
        newUrl.searchParams.set('doi', doi);

        // 保留原始锚点(如有)
        newUrl.hash = currentUrl.hash;

        // 执行重定向
        location.replace(newUrl.href);
    }
})();