Greasy Fork

Greasy Fork is available in English.

更换Sagepub中的下载链接按钮为中国易读通

把Sagepub的下载按钮链接到中国易读通,方便中国用户下载

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Replace download button in Sagepub with 易读通 for Chinese users
// @name:zh-CN   更换Sagepub中的下载链接按钮为中国易读通
// @namespace    http://tampermonkey.net/
// @version      2025-05-07
// @description  Add a link to download PDF from 易读通 for Chinese users on SAGE Journals
// @description:zh-cn 把Sagepub的下载按钮链接到中国易读通,方便中国用户下载
// @author       Hao_Tian
// @match        https://journals.sagepub.com/doi*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sagepub.com
// @grant        none
// @license      GPLv3
// ==/UserScript==

(function() {
    'use strict';

    // Extract DOI from the current URL
    const url = window.location.href;
    const doiMatch = url.match(/\/doi\/abs\/(.+)/);
    if (doiMatch && doiMatch[1]) {
        const doi = doiMatch[1];
        const downloadUrl = `https://sage.cnpereading.com/paragraph/download/?doi=${doi}`;

        // Locate the first specified element
        const targetElement1 = document.evaluate(
            '//*[@id="pb-page-content"]/div/div[4]/main/article/div[1]/ul/li[2]/a',
            document,
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null
        ).singleNodeValue;

        if (targetElement1) {
            // Update the href and span text content
            targetElement1.href = downloadUrl;
            const spanElement1 = targetElement1.querySelector('.link-text');
            if (spanElement1) {
                spanElement1.textContent = 'CN User: Get from 易读通';
            }
        }

        // Locate the second specified element
        const targetElement2 = document.evaluate(
            '//*[@id="bodymatter"]/div/section/div/a',
            document,
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null
        ).singleNodeValue;

        if (targetElement2) {
            // Update the href and span text content
            targetElement2.href = downloadUrl;
            const spanElement2 = targetElement2.querySelector('span');
            if (spanElement2) {
                spanElement2.textContent = 'CN User: Get from 易读通';
            }
        }
    }
})();