Semantic Scholar Citation Badge Generator

Add a button to generate a citation badge and copy it to clipboard on Semantic Scholar website pages, based on the article ID in the URL. The badge shows the citation count for the article. It generates an API URL with the citation count and copies it to clipboard.

目前為 2023-03-16 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Semantic Scholar Citation Badge Generator
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Add a button to generate a citation badge and copy it to clipboard on Semantic Scholar website pages, based on the article ID in the URL. The badge shows the citation count for the article. It generates an API URL with the citation count and copies it to clipboard.
// @match        https://www.semanticscholar.org/*
// @grant        GM_setClipboard
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 获取当前页面 URL 的最后一段字符串
    const urlLastPart = window.location.pathname.split('/').pop();

    // 生成 API URL
    const apiUrl = `https://img.shields.io/badge/dynamic/json?label=citation&query=citationCount&url=https://api.semanticscholar.org/graph/v1/paper/${urlLastPart}?fields=citationCount`;

    // 创建要保存到剪贴板的字符串
    const clipboardStr = `![](${apiUrl})`;

    // 添加按钮到页面
    const button = document.createElement('button');
    button.style.position = 'fixed';
    button.style.top = '100px';
    button.style.left = '20px';
    button.textContent = 'Generate Citation Badge';
    button.addEventListener('click', () => {
        GM_setClipboard(clipboardStr);
        button.textContent = 'Citation Badge Copied!';
        window.setTimeout(() => {
            button.textContent = 'Generate Citation Badge';
        }, 1000); // 1秒钟后将按钮文本更改回 "Generate Citation Badge"
    });
    document.body.appendChild(button);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址