Greasy Fork

Scopus添加每年发文量查询按钮

方便点击查询每年发表的文献。Scopus添加每年发文量查询按钮

// ==UserScript==
// @name         Scopus添加每年发文量查询按钮
// @namespace    http://tampermonkey.net/
// @version      2025.02.12.001
// @author       You
// @match        https://www.scopus.com/sources.uri*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=scopus.com
// @license      MIT
// @description  方便点击查询每年发表的文献。Scopus添加每年发文量查询按钮
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // Your code here...
    function appendTo(parentEle, tagName = "a", attrs = {}, functions = {}, id = "") {
        attrs = typeof attrs !== "string" ? attrs : { textContent: attrs };
        functions = typeof functions !== "function" ? functions : { click: functions };
        if (id && document.getElementById(id)) return document.getElementById(id)
        const ele = document.createElement(tagName);
        if (id) ele.id = id;
        for (const key in attrs) { ele[key] = attrs[key]; ele.setAttribute(key, attrs[key]); }
        for (const key in functions) ele.addEventListener(key, functions[key]);
        if (parentEle) parentEle.appendChild(ele);
        return ele;
    }
    function add_years_query() {
        const trs = document.querySelectorAll("#sourceResults tr")
        for (const tr of trs) {
            const a = tr.querySelector("td:nth-child(2) > a")
            const td6 = tr.querySelector("td:nth-child(6)")
            if (a && !td6.querySelector("a")) {
                const href = a.href
                const sourceId = href.substring(href.lastIndexOf("/") + 1)
                a.style.wordWrap = "break-word"
                td6.style.wordWrap = "break-word"
                for (const years of ["2023", "2024", "2025"]) {
                    appendTo(td6, "a", {
                        href: `https://www.scopus.com/source/search/docType.uri?sourceId=${sourceId}&years=${years}&docType=ar,re,cp,dp,ch&pubstageExclusions=aip`, textContent: years, style: "background: yellow; margin: 3px; padding:3px; word-wrap: normal;"
                    })
                }
            }
        }
    }
    setInterval(add_years_query, 2000)

})();