gcc更多的数据库访问

跳转与链接

// ==UserScript==
// @name         gcc更多的数据库访问
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  跳转与链接
// @author       LinXingJun
// @match        *://*.vpn.gcc.edu.cn:8118/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';
    const domain = window.location.hostname.toLowerCase();
    if (domain.includes('engineeringvillage')) {
        console.log("进行gccei数据库访问.....");
        // 功能: 自动跳转
        const currentPath = window.location.pathname;
        if (currentPath === '/app/search/quick/') {
            window.location.replace('/search/expert.url');
            return;
        }
        if (domain === 'id-elsevier-com-s.vpn.gcc.edu.cn'){
            window.location = 'http://www-elsevier-com-s.vpn.gcc.edu.cn:8118/'
            return;
        }
        // 功能: 修改 链接行为
        function modifyLinks() {
            document.querySelectorAll('a').forEach(link => {
                const href = link.getAttribute('href');
                if (!href) return;

                try {
                    const url = new URL(href, window.location.href);

                    const path = url.pathname;
                    if (
                        path.startsWith('/search/results/') ||
                        path.startsWith('/app/doc/')
                    ) {
                        link.setAttribute('target', '_blank');
                        link.setAttribute('rel', 'noopener noreferrer');
                    }
                } catch (e) {
                    // 忽略无效链接
                }
            });
        }

        // 初始处理页面已加载的链接
        modifyLinks();

        // 监听 DOM 变化,处理动态加载的链接(如 AJAX 加载的内容)
        const observer = new MutationObserver(() => {
            modifyLinks();
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    }
    if (domain.includes('navi-cnki-net-s.vpn.gcc.edu.cn')) {
        const url = new URL(window.location.href);
        url.searchParams.delete('uniplatform');
        window.location.href = url.toString();
    }

})();