Greasy Fork

Ovearleaf-Enhanced

the script to enhance the function of overleaf

目前为 2025-01-22 提交的版本。查看 最新版本

// ==UserScript==
// @name         Ovearleaf-Enhanced
// @namespace    com.jw23.overleaf
// @version      0.1
// @description  the script to enhance the function of overleaf
// @author       jw23
// @match        https://www.overleaf.com/project/*
// @require      https://cdn.jsdelivr.net/npm/@floating-ui/[email protected]
// @require      https://cdn.jsdelivr.net/npm/@floating-ui/[email protected]
// @require      https://cdn.jsdelivr.net/npm/[email protected]/dist/simple-notify.min.js
// @resource notifycss   https://cdn.jsdelivr.net/npm/simple-notify/dist/simple-notify.css
// @grant        GM_setClipboard
// @grant        GM_xmlhttpRequest
// @grant        GM_getResourceText
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==

/* ==UserConfig== 
configure:
    origin:
        title: Orgin
        description: choose google scholar or its mirror
        type: select
        bind: $origins
==/UserConfig== */

// configure the origin
const origins = ["https://scholar.google.com.hk", "https://scholar.lanfanshu.cn", "https://xs.vygc.top"]
let oldOrigins = GM_getValue("origins", []);
const mergedArray = [...new Set([...origins, ...oldOrigins])];
GM_setValue("origins", mergedArray)

// If you are not using scriptable cat, just change the https://scholar.google.com.hk
let currentOrigin = () => { return GM_getValue("configure.origin", "https://scholar.google.com.hk") }



let scholarIcon = `<svg t="1737286106734" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1523" width="28" height="28"><path d="M409.17 707.09h446.16a23.53 23.53 0 0 1 23.53 23.53v90a92.68 92.68 0 0 1-92.68 92.68h-377a92.68 92.68 0 0 1-92.68-92.68v-20.85a92.68 92.68 0 0 1 92.68-92.68z" fill="#E9F1FF" p-id="1524"></path><path d="M799.2 943H224.8a81.7 81.7 0 0 1-78.18-57.15L98 743.31c-0.09-0.26-0.17-0.52-0.25-0.78A82 82 0 0 1 176.09 636h671.82a82.06 82.06 0 0 1 78.33 106.53c-0.09 0.26-0.17 0.52-0.26 0.78l-48.6 142.55A81.69 81.69 0 0 1 799.2 943zM158.76 723.14l48.55 142.41c0.09 0.26 0.17 0.52 0.26 0.78A18 18 0 0 0 224.8 879h574.4a18 18 0 0 0 17.23-12.67l0.26-0.78 48.55-142.41A18.06 18.06 0 0 0 847.91 700H176.09a18.06 18.06 0 0 0-17.33 23.14zM512 397c-88.22 0-160-71.78-160-160S423.78 77 512 77s160 71.78 160 160-71.78 160-160 160z m0-256a96 96 0 1 0 96 96 96.11 96.11 0 0 0-96-96z" fill="#2C5CCB" p-id="1525"></path><path d="M800 691.78a32 32 0 0 1-32-32c0-47.76-15.13-92.4-42.6-125.7-26-31.52-60-48.87-95.83-48.87H394.43c-35.8 0-69.83 17.35-95.83 48.87-27.47 33.3-42.6 77.92-42.6 125.7a32 32 0 0 1-64 0c0-62.59 20.33-121.7 57.23-166.43 18.44-22.36 40.06-40 64.26-52.38a175.88 175.88 0 0 1 80.94-19.76h235.14A175.88 175.88 0 0 1 710.51 441c24.2 12.4 45.81 30 64.26 52.38 36.9 44.7 57.23 103.81 57.23 166.4a32 32 0 0 1-32 32z" fill="#2C5CCB" p-id="1526"></path><path d="M511.72 522.44l-33.12 83.44a12.57 12.57 0 0 0 2.82 13.48l22 22a12.49 12.49 0 0 0 17.65 0.08l21.8-21.8a12.42 12.42 0 0 0 2.7-13.46z" fill="#2C5CCB" p-id="1527"></path><path d="M531.36 545.69h-38.72a11 11 0 0 1-10.64-8.33l-5.24-21a11 11 0 0 1 10.67-13.67h49.22a11 11 0 0 1 10.67 13.67l-5.24 21a11 11 0 0 1-10.72 8.33z" fill="#2C5CCB" p-id="1528"></path></svg>`;
let showBox = false;
let scholarURL = query => `${currentOrigin()}/scholar?hl=zh-CN&as_sdt=0%2C5&q=${query}&oq=a`;
let scholarRefPageURL = id => `${currentOrigin()}/scholar?q=info:${id}:scholar.google.com/&output=cite&scirp=1&hl=zh-CN`;

(function () {
    'use strict';
    GM_addStyle(GM_getResourceText('notifycss'))
    injectScript()
    setInterval(() => {
        if (!document.getElementById('toggleIcon')) {
            injectScript()
        }
    }, 2000)
})();

function injectScript() {
    // query element by className
    waitUtil('div.ol-cm-toolbar-button-group.ol-cm-toolbar-end', el => {

        let iconBox = createToggleIcon();
        el.appendChild(iconBox);

        let popupBox = createBox();
        let oldPopup = document.querySelector("#popup");
        // toggle the search box with the icon.
        if (oldPopup) {
            popupBox = oldPopup;
        }

        document.body.appendChild(popupBox)
        popupBox.addEventListener('keydown', env => {
            if (env.key === 'Enter') {
                queryArticle()
            }
        })
        FloatingUIDOM.autoUpdate(iconBox, popupBox, () => {
            FloatingUIDOM.computePosition(iconBox, popupBox, {
                middleware: [FloatingUICore.shift(), FloatingUICore.flip(), FloatingUICore.offset(6)],

            }).then(({ x, y }) => {
                Object.assign(popupBox.style, {
                    top: `${y}px`,
                    left: `${x}px`
                })
            })
        })
        iconBox.onclick = (ev) => {
            if (showBox) {
                showBox = false;
                popupBox.style.display = 'none';
            } else {
                showBox = true;
                popupBox.style.display = 'block';
            }
        }
        let searchIcon = document.getElementById('search-word');
        let content = document.getElementById("search-content");
        content.onclick = (env) => {
            if (env.target.className == 'scholar-data') {
                let id = env.target.getAttribute("data-cid");
                getBibTex(id).then(bib => {
                    new Notify({
                        status: 'success',
                        title: 'Copy successfully',
                        text: 'Bib has been copied to clipboard',
                        effect: 'slide',
                        type: 'filled'
                    })
                    GM_setClipboard(bib);
                }).catch(_ => {
                    new Notify({
                        status: 'error',
                        title: "Copy failed",
                        text: "Failed to get bib tex",
                        effect: "slide",
                        type: "filled"
                    })
                })
            }
        }
        searchIcon.onclick = () => {
            queryArticle()
        }
    })
}

function queryArticle() {
    let content = document.getElementById("search-content");
    content.innerHTML = "Loading......"
    let word = document.querySelector('input.search-input').value;
    getArticleIDList(word).then(async lists => {
        let searchText = "";
        lists.forEach((article) => {
            let articleId = article.id;
            searchText += scholarContent(`${article.title}@${article.author}`, articleId)
        })
        return searchText

    }).then(text => {
        content.innerHTML = text;
    });
}

function waitUtil(el, callback, timeout = 6000) {
    let query = setInterval(() => {
        let target = document.querySelector(el)
        if (target) {
            // 如果找到了目标元素,则清除查询任务
            clearInterval(query)
            callback(target)
        }
    })
    // 超时则清除查询任务
    setTimeout(() => {
        clearInterval(query)
    }, timeout)
}

function createToggleIcon() {
    let iconBox = document.createElement('div');
    iconBox.className = 'ol-cm-toolbar-button';
    iconBox.style.display = 'flex';
    iconBox.style.justifyContent = 'center';
    iconBox.style.alignItems = 'center';
    iconBox.id = "toggleIcon"
    iconBox.innerHTML = scholarIcon;
    return iconBox;
}

// create box to show search box and result box
function createBox() {
    let box = document.createElement('div');
    box.id = "popup"
    box.style = 'width:265px;background:#eef;padding:5px;border:1px solid #ccc;border-radius:5px;position: absolute;display:none;top:0px;left:0px';
    box.innerHTML = `
     <style>
    .scholar-data:hover{
        background:#eee
    }
    .scholar-data{
        border-bottom:1px solid #ccc;
        cursor:pointer;
        font-size:12px;
        overflow:hidden;
    }
    input.search-input:hover{
        outline:none
    }
    </style>
    <div id="search" style="display:flex;">
    <input class="search-input" style="height:22px"></input>
    <div class="search-icon" id="search-word" style="display:flex;justify-content:center;align-items:center;margin-left:5px;outline:none">
<svg t="1737380661491" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4101" width="20" height="20"><path d="M473.728 128.042667l4.437333 0.042666 4.352 0.170667 4.394667 0.170667 4.309333 0.256 4.352 0.298666 4.352 0.384 4.266667 0.426667 4.266667 0.426667 4.309333 0.512 4.266667 0.597333 4.266666 0.64 4.224 0.682667 4.181334 0.682666 4.181333 0.768 4.224 0.853334 4.138667 0.853333 4.138666 0.938667 4.096 0.938666 4.138667 1.109334 4.053333 1.066666 4.053334 1.109334 4.053333 1.152 4.010667 1.237333 4.010666 1.28 3.968 1.28 3.925334 1.408 3.968 1.408 3.882666 1.450667 3.925334 1.493333 3.84 1.578667 3.84 1.578666 3.84 1.621334 3.797333 1.706666 3.754667 1.706667 3.754666 1.834667 3.669334 1.792 3.712 1.834666 3.669333 1.92 3.626667 1.962667 3.626666 2.005333 3.584 2.048 3.541334 2.090667 3.584 2.090667 3.413333 2.133333 3.541333 2.218667 3.456 2.218666 3.413334 2.304 3.370666 2.346667 3.370667 2.346667 3.328 2.389333 3.285333 2.432 3.285334 2.474667 3.242666 2.56 3.2 2.517333 3.2 2.56 3.114667 2.645333 3.114667 2.688 3.072 2.688 3.072 2.730667 2.986666 2.773333 3.029334 2.816 2.944 2.858667 2.901333 2.858667 2.901333 2.944 2.816 2.901333 2.816 3.029333 2.773334 2.986667 2.730666 3.072 2.688 3.072 2.688 3.114667 2.645334 3.114666 2.56 3.2 2.56 3.2 2.56 3.242667 2.432 3.285333 2.474666 3.328 2.389334 3.285334 2.304 3.413333 2.346666 3.328 2.304 3.413333 2.261334 3.456 2.176 3.498667 2.133333 3.498667 2.133333 3.541333 2.090667 3.541333 2.048 3.584 1.962667 3.669334 1.962666 3.584 1.92 3.669333 1.834667 3.712 1.792 3.712 1.834667 3.754667 1.706666 3.754666 1.706667 3.797334 1.664 3.797333 1.536 3.84 1.578667 3.84 1.493333 3.925333 1.450667 3.882667 1.450666 3.968 1.365334 3.925333 1.28 3.968 1.28 4.010667 1.237333 4.053333 1.152 4.010667 1.109333 4.053333 1.109334 4.053334 1.066666 4.138666 0.981334 4.096 0.896 4.138667 0.853333 4.181333 0.853333 4.181334 0.810667 4.181333 0.682667 4.181333 0.682666 4.266667 0.597334 4.266667 0.597333 4.224 0.512 4.266666 0.469333 4.266667 0.426667 4.309333 0.341333 4.352 0.298667 4.352 0.256 4.352 0.170667 4.352 0.170666 4.352 0.042667 4.437334L810.666667 469.333333l-0.042667 4.394667-0.042667 4.437333-0.170666 4.352-0.170667 4.352-0.256 4.352-0.298667 4.352-0.384 4.352-0.384 4.266667-0.469333 4.266667-0.512 4.309333-0.597333 4.266667-0.597334 4.266666-0.682666 4.224-0.682667 4.181334-0.810667 4.181333-0.853333 4.181333-0.853333 4.181334-0.896 4.138666-0.981334 4.096-1.066666 4.138667-1.109334 4.053333-1.109333 4.053334-1.152 4.010666-1.237333 4.053334-1.28 4.010666-1.28 3.968-1.365334 3.925334-1.450666 3.968-1.450667 3.882666-1.493333 3.925334-1.578667 3.84-1.536 3.84-1.706667 3.84-1.706666 3.754666-1.706667 3.754667-1.792 3.754667-1.792 3.712-1.834667 3.712-1.92 3.669333-1.962666 3.584-1.962667 3.669333-2.048 3.584-2.133333 3.541334-2.090667 3.541333-2.133333 3.498667-2.176 3.498666-2.261334 3.456-2.304 3.413334-2.346666 3.370666-2.304 3.370667-2.389334 3.285333-2.474666 3.328-2.474667 3.285334-2.56 3.242666-2.517333 3.2-2.56 3.2-2.645334 3.114667-2.688 3.114667-2.688 3.072-2.730666 3.072-2.773334 2.986666-2.816 2.986667-2.816 2.986667-2.901333 2.901333-2.901333 2.858667-2.944 2.858666-2.986667 2.816-2.986667 2.773334-3.114666 2.730666-3.072 2.688-3.114667 2.688-3.114667 2.645334-3.2 2.56-3.2 2.56-3.242666 2.517333-3.285334 2.474667-3.285333 2.432-3.328 2.389333-3.370667 2.346667-3.370666 2.346666-3.413334 2.304-3.456 2.218667-3.498666 2.218667-3.456 2.133333-3.584 2.133333-3.541334 2.048-3.584 2.048-3.626666 2.005334-3.626667 1.962666-3.669333 1.92-3.712 1.834667-3.669334 1.792-3.754666 1.834667-3.754667 1.706666-3.84 1.706667-3.797333 1.621333-3.84 1.578667-3.84 1.578667-3.925334 1.493333-3.882666 1.450667-3.968 1.408-3.925334 1.365333-3.968 1.322667-4.010666 1.28-4.010667 1.237333-4.053333 1.152-4.053334 1.109333-4.053333 1.066667-4.138667 1.109333-4.096 0.938667-4.138666 0.938667-4.138667 0.853333-4.224 0.853333-4.181333 0.768-4.181334 0.682667-4.266666 0.682667-4.266667 0.64-4.224 0.597333-4.266667 0.469333-4.266666 0.512-4.309334 0.384-4.352 0.426667-4.352 0.256-4.309333 0.256-4.394667 0.170667-4.352 0.170666h-4.437333L469.333333 810.666667l-4.394666-0.042667-4.437334-0.042667-4.309333-0.170666-4.394667-0.170667-4.352-0.256-4.352-0.298667-4.309333-0.384-4.309333-0.426666-4.266667-0.426667-4.309333-0.512-4.266667-0.597333-4.224-0.64-4.266667-0.682667-4.181333-0.682667-4.181333-0.768-4.181334-0.853333-4.138666-0.853333-4.181334-0.938667-4.096-0.938667-4.138666-1.109333-4.053334-1.066667-4.010666-1.109333-4.053334-1.152-4.053333-1.237333-4.010667-1.28-3.925333-1.28-3.968-1.408-3.968-1.408-3.882667-1.450667-3.882666-1.493333-3.84-1.578667-3.882667-1.578667-3.84-1.621333-3.754667-1.706667-3.754666-1.706666-3.754667-1.834667-3.712-1.792-3.712-1.834667-3.669333-1.92-3.584-1.962666-3.669334-2.005334-3.541333-2.048-3.584-2.090666-3.541333-2.090667-3.456-2.133333-3.541334-2.218667-3.413333-2.218667-3.413333-2.304-3.413334-2.346666-3.370666-2.346667-3.285334-2.389333-3.328-2.432-3.285333-2.474667-3.242667-2.56-3.157333-2.517333-3.242667-2.56-3.114666-2.645334-3.114667-2.688-3.072-2.688-3.072-2.730666-2.986667-2.773334-2.986666-2.816-2.986667-2.858666-2.901333-2.858667-2.858667-2.944-2.858667-2.901333-2.816-3.029334-2.773333-2.986666-2.730667-3.072-2.688-3.072-2.688-3.114667-2.602666-3.114667-2.602667-3.2-2.56-3.2-2.517333-3.242666-2.474667-3.285334-2.432-3.328-2.389333-3.285333-2.346667-3.413333-2.346667-3.328-2.304-3.413334-2.218666-3.456-2.218667-3.498666-2.133333-3.498667-2.133334-3.541333-2.048-3.541334-2.048-3.584-2.005333-3.669333-1.962667-3.584-1.877333-3.669333-1.877333-3.712-1.792-3.712-1.792-3.754667-1.706667-3.754667-1.706667-3.797333-1.706666-3.797333-1.536-3.84-1.536-3.84-1.536-3.925334-1.450667-3.882666-1.408-3.968-1.365333-3.925334-1.322667-3.968-1.28-4.010666-1.194667-4.053334-1.194666-4.010666-1.109334-4.053334-1.066666-4.053333-1.066667-4.138667-0.981333-4.096-0.938667-4.138666-0.853333-4.181334-0.853334-4.181333-0.768-4.181333-0.682666-4.181334-0.682667-4.266666-0.64-4.266667-0.597333-4.224-0.469334-4.266667-0.512-4.266666-0.384-4.309334-0.384-4.352-0.298666-4.352-0.256-4.352-0.170667-4.352-0.170667-4.352v-4.437333L128 469.333333l0.042667-4.394666 0.042666-4.437334 0.170667-4.352 0.170667-4.352 0.256-4.352 0.298666-4.352 0.426667-4.352 0.341333-4.266666 0.512-4.266667 0.469334-4.309333 0.597333-4.266667 0.64-4.266667 0.682667-4.224 0.682666-4.181333 0.768-4.181333 0.853334-4.181334 0.853333-4.181333 0.938667-4.138667 0.981333-4.096 1.066667-4.138666 1.066666-4.053334 1.109334-4.053333 1.194666-4.010667 1.194667-4.053333 1.28-4.010667 1.28-3.968 1.408-3.925333 1.408-3.968 1.450667-3.882667 1.536-3.925333 1.536-3.84 1.578666-3.84 1.664-3.84 1.706667-3.754667 1.706667-3.754666 1.792-3.754667 1.792-3.712 1.877333-3.712 1.877333-3.669333 1.962667-3.584 2.005333-3.669334 2.048-3.584 2.090667-3.541333 2.090667-3.541333 2.133333-3.498667 2.218667-3.498667 2.218666-3.456 2.304-3.413333 2.346667-3.370667 2.346667-3.370666 2.389333-3.285334 2.432-3.328 2.474667-3.285333 2.56-3.242667 2.517333-3.2 2.56-3.2 2.645333-3.114666 2.688-3.114667 2.688-3.072 2.730667-3.072 2.773333-2.986667 2.816-2.986666 2.858667-2.986667 2.858667-2.901333 2.944-2.858667 2.901333-2.858667 3.029333-2.816 2.986667-2.773333 3.072-2.730667 3.072-2.688 3.114667-2.688 3.114666-2.645333 3.242667-2.56 3.157333-2.56 3.242667-2.517333 3.285333-2.474667 3.328-2.432 3.285334-2.389333 3.413333-2.346667 3.328-2.346667 3.413333-2.304 3.456-2.218666 3.541334-2.218667 3.413333-2.133333 3.584-2.133334 3.584-2.048 3.541333-2.048 3.669334-2.005333 3.584-1.962667 3.669333-1.92 3.712-1.834666 3.712-1.792 3.754667-1.834667 3.754666-1.706667 3.797334-1.706666 3.797333-1.621334 3.84-1.578666 3.84-1.578667 3.925333-1.493333 3.882667-1.450667 3.968-1.408 3.968-1.365333 3.925333-1.322667 4.010667-1.28 4.053333-1.237333 4.053334-1.152 4.010666-1.109334 4.053334-1.066666 4.138666-1.109334 4.096-0.938666 4.181334-0.938667 4.138666-0.853333 4.181334-0.853334 4.181333-0.768 4.224-0.682666 4.224-0.682667 4.266667-0.64 4.224-0.597333 4.266666-0.469334 4.309334-0.512 4.266666-0.384 4.352-0.426666 4.352-0.256 4.352-0.256 4.394667-0.170667 4.309333-0.170667h4.437334L469.333333 128l4.394667 0.042667z m-8.234667 42.666666l-3.84 0.042667-3.84 0.170667-3.882666 0.128-3.84 0.213333-3.754667 0.298667-3.754667 0.256-3.84 0.426666-3.712 0.384-3.754666 0.426667-3.712 0.554667-3.712 0.512-3.712 0.597333-3.669334 0.64-3.712 0.682667-3.584 0.725333-3.669333 0.725333-3.584 0.853334-3.626667 0.810666-3.541333 0.938667-3.584 0.896-3.541333 0.981333L384 183.04l-3.498667 1.066667-3.456 1.152-3.456 1.152-3.456 1.152-3.498666 1.28-3.413334 1.28-3.328 1.28-3.413333 1.408-3.413333 1.365333-3.285334 1.450667-3.328 1.450666-3.285333 1.536-3.285333 1.536-3.2 1.621334-3.285334 1.621333-3.157333 1.664-3.242667 1.706667-3.114666 1.706666-3.157334 1.792-3.114666 1.834667-3.072 1.877333-3.072 1.834667-3.029334 1.962667-3.029333 1.962666-2.986667 1.962667-2.986666 2.048-2.986667 2.048-2.901333 2.133333-2.858667 2.133334-2.901333 2.176-2.816 2.218666-2.816 2.218667-2.773334 2.261333-2.730666 2.304-2.730667 2.304-2.688 2.389334-2.688 2.389333-2.645333 2.474667-2.602667 2.432-2.602667 2.474666-2.56 2.56-2.517333 2.517334-2.474667 2.56-2.432 2.645333-2.432 2.645333-2.389333 2.688-2.389333 2.688-2.346667 2.730667-2.304 2.730667-2.261333 2.816-2.218667 2.773333-2.218667 2.816-2.176 2.901333-2.133333 2.858667-2.133333 2.944-2.005334 2.901333-2.048 2.986667-2.005333 2.986667-1.962667 3.072-1.962666 2.986666-1.834667 3.114667-1.877333 3.072-1.834667 3.114667-1.749333 3.157333-1.749334 3.114667-1.706666 3.242666-1.706667 3.157334-1.578667 3.242666-1.621333 3.242667-1.536 3.242667-1.536 3.328-1.450667 3.328-1.450666 3.328-1.365334 3.328-1.365333 3.413333-1.322667 3.413333-1.28 3.413334-1.28 3.413333-1.152 3.498667-1.152 3.413333-1.152 3.498667L183.04 384l-1.024 3.584-0.981333 3.541333-0.896 3.541334-0.938667 3.584-0.853333 3.584-0.810667 3.626666-0.725333 3.669334-0.725334 3.584-0.682666 3.712-0.64 3.669333-0.597334 3.712-0.512 3.712-0.554666 3.669333-0.426667 3.754667-0.426667 3.754667-0.341333 3.84-0.298667 3.754666-0.298666 3.797334-0.213334 3.797333-0.128 3.84-0.170666 3.84v3.84L170.666667 469.333333l0.042666 3.84 0.042667 3.84 0.170667 3.84 0.128 3.882667 0.213333 3.84 0.298667 3.754667 0.298666 3.754666 0.384 3.84 0.384 3.754667 0.426667 3.754667 0.554667 3.669333 0.512 3.712 0.597333 3.712 0.64 3.669333 0.682667 3.712 0.725333 3.584 0.725333 3.669334 0.853334 3.626666 0.810666 3.584 0.938667 3.584 0.896 3.541334 0.981333 3.541333 1.024 3.584 1.066667 3.498667 1.152 3.456 1.152 3.456 1.194667 3.498666 1.28 3.413334 1.237333 3.413333 1.28 3.413333 1.408 3.413334 1.365333 3.328 1.450667 3.328 1.450667 3.328 1.536 3.328 1.536 3.242666 1.621333 3.242667 1.621333 3.242667 1.664 3.157333 1.706667 3.242667 1.706667 3.114666 1.792 3.157334 1.834666 3.114666 1.877334 3.072 1.834666 3.072 1.962667 3.029334 1.962667 3.029333 2.005333 3.029333 2.048 2.986667 2.048 2.901333 2.090667 2.944 2.133333 2.858667 2.176 2.901333 2.218667 2.816 2.218666 2.773334 2.261334 2.816 2.304 2.730666 2.346666 2.730667 2.389334 2.688 2.389333 2.688 2.432 2.645333 2.432 2.645334 2.474667 2.56 2.56 2.56 2.517333 2.517333 2.56 2.474667 2.645333 2.432 2.645334 2.474666 2.688 2.389334 2.688 2.389333 2.730666 2.304 2.730667 2.304 2.816 2.261333 2.773333 2.218667 2.816 2.218667 2.901334 2.176 2.858666 2.133333 2.944 2.133333 2.901334 2.048 2.986666 2.048 3.029334 1.962667 2.986666 1.962667 3.072 1.962666 3.072 1.834667 3.072 1.877333 3.114667 1.834667 3.157333 1.749333 3.114667 1.749334 3.242667 1.706666 3.157333 1.706667 3.285333 1.578667 3.2 1.621333 3.285334 1.536 3.285333 1.536 3.328 1.450667 3.328 1.450666 3.370667 1.365334 3.413333 1.365333 3.328 1.322667 3.413333 1.28 3.498667 1.28 3.413333 1.152 3.498667 1.152 3.456 1.152 3.498667 1.066666 3.584 1.024 3.541333 0.981334 3.584 0.896 3.541333 0.938666 3.626667 0.853334 3.584 0.810666 3.669333 0.725334 3.584 0.725333 3.712 0.682667 3.669334 0.64 3.712 0.597333 3.712 0.512 3.712 0.554667 3.754666 0.426666 3.754667 0.426667 3.797333 0.384 3.754667 0.256 3.797333 0.298667 3.797334 0.213333 3.84 0.128 3.84 0.170667h3.84L469.333333 768l3.84-0.042667 3.84-0.042666 3.882667-0.170667 3.84-0.128 3.84-0.213333 3.797333-0.298667 3.754667-0.256 3.797333-0.426667 3.754667-0.384 3.754667-0.426666 3.712-0.554667 3.669333-0.512 3.712-0.597333 3.669333-0.64 3.712-0.682667 3.584-0.725333 3.669334-0.725334 3.626666-0.853333 3.584-0.810667 3.584-0.938666 3.541334-0.896 3.584-0.981334 3.541333-1.024 3.498667-1.066666 3.456-1.152 3.498666-1.152 3.413334-1.152 3.498666-1.28 3.413334-1.28 3.370666-1.28 3.413334-1.408 3.370666-1.365334 3.285334-1.450666 3.328-1.450667 3.328-1.536 3.242666-1.536 3.242667-1.621333 3.242667-1.621334 3.2-1.664 3.2-1.706666 3.114666-1.706667 3.157334-1.792 3.157333-1.834667 3.072-1.877333 3.072-1.834667 2.986667-1.962666 3.029333-1.962667 3.029333-1.962667 2.986667-2.048 2.901333-2.048 2.944-2.133333 2.858667-2.133333 2.901333-2.176 2.816-2.218667 2.773334-2.218667 2.858666-2.261333 2.730667-2.304 2.730667-2.304 2.645333-2.389333 2.688-2.389334 2.645333-2.474666 2.645334-2.432 2.56-2.474667 2.56-2.56 2.56-2.517333 2.432-2.56 2.474666-2.645334 2.432-2.645333 2.389334-2.688 2.389333-2.688 2.346667-2.730667 2.261333-2.730666 2.261333-2.816 2.218667-2.773334 2.218667-2.816 2.176-2.901333 2.133333-2.858667 2.133333-2.944 2.048-2.901333 2.048-2.986667 2.005334-2.986666 1.92-3.072 1.962666-2.986667 1.834667-3.114667 1.877333-3.072 1.834667-3.114666 1.749333-3.157334 1.792-3.114666 1.706667-3.242667 1.621333-3.157333 1.621334-3.242667 1.621333-3.242667 1.536-3.242666 1.536-3.328 1.450667-3.328 1.450666-3.328 1.365334-3.328 1.365333-3.413334 1.322667-3.413333 1.28-3.413333 1.28-3.413334 1.152-3.498666 1.194666-3.413334 1.109334-3.498666 1.066666-3.498667 1.024-3.584 0.981334-3.541333 0.938666-3.541334 0.896-3.584 0.853334-3.584 0.853333-3.626666 0.682667-3.669334 0.725333-3.584 0.682667-3.712 0.64-3.669333 0.597333-3.712 0.554667-3.712 0.512-3.669333 0.426666-3.754667 0.426667-3.754667 0.384-3.84 0.298667-3.754666 0.256-3.797334 0.213333-3.797333 0.128-3.84 0.170667-3.84 0.042666-3.84L768 469.333333 768 465.493333l-0.042667-3.84-0.170666-3.84-0.128-3.882666-0.213334-3.84-0.256-3.754667-0.298666-3.754667-0.426667-3.84-0.384-3.754666-0.426667-3.754667-0.512-3.669333-0.554666-3.712-0.597334-3.712-0.64-3.669334-0.682666-3.712-0.725334-3.584-0.725333-3.669333-0.853333-3.626667-0.810667-3.584-0.896-3.584-0.938667-3.541333-0.981333-3.541333L755.669333 384l-1.066666-3.498667-1.109334-3.456-1.194666-3.456-1.152-3.498666-1.28-3.413334-1.28-3.413333-1.28-3.413333-1.408-3.413334-1.365334-3.328-1.450666-3.328-1.450667-3.328-1.536-3.328-1.536-3.242666-1.621333-3.242667-1.621334-3.242667-1.621333-3.157333-1.706667-3.242667-1.792-3.114666-1.706666-3.157334-1.877334-3.114666-1.877333-3.072-1.834667-3.072-1.962666-3.029334-1.92-3.029333-2.005334-3.029333-2.048-2.986667-2.048-2.901333-2.133333-2.944-2.133333-2.858667-2.176-2.901333-2.218667-2.816-2.218667-2.773334-2.261333-2.816-2.261333-2.730666-2.346667-2.730667-2.389333-2.688-2.389334-2.688-2.432-2.645333-2.474666-2.645334-2.474667-2.56-2.56-2.56-2.517333-2.517333-2.56-2.474667-2.645334-2.432-2.645333-2.474666-2.688-2.389334-2.645333-2.389333-2.730667-2.304-2.730667-2.304-2.816-2.261333-2.816-2.218667-2.816-2.218667-2.901333-2.176-2.858667-2.133333-2.944-2.133333-2.901333-2.048-2.986667-2.048-2.986666-1.962667-3.072-1.962667-2.986667-1.962666-3.072-1.834667-3.072-1.877333-3.157333-1.834667-3.157334-1.749333-3.114666-1.749334-3.2-1.706666-3.2-1.706667-3.242667-1.578667-3.242667-1.621333-3.242666-1.536-3.328-1.536-3.328-1.450667-3.285334-1.450666-3.413333-1.365334-3.413333-1.365333-3.328-1.322667-3.413334-1.28-3.456-1.28-3.456-1.152-3.498666-1.152-3.413334-1.152-3.541333-1.066666-3.541333-1.024-3.584-0.981334-3.541334-0.896-3.584-0.938666-3.584-0.853334-3.626666-0.810666-3.669334-0.725334-3.584-0.725333-3.712-0.682667-3.669333-0.64-3.712-0.597333-3.669333-0.512-3.712-0.554667-3.754667-0.426666-3.754667-0.426667-3.84-0.384-3.712-0.256-3.84-0.298667-3.797333-0.213333-3.84-0.128-3.84-0.170667h-3.84L469.333333 170.666667l-3.882666 0.042666z" fill="#0400FF" p-id="4102"></path><path d="M470.613333 213.76c24.917333 2.261333 27.690667 40.618667-14.933333 43.008-107.52 7.552-194.986667 101.888-199.381333 214.101333-1.365333 12.842667-4.992 13.312-9.514667 16.256-14.848 9.813333-33.706667-2.261333-32.896-27.648 5.888-132.181333 122.282667-249.301333 256.725333-245.76zM705.109333 682.709333a22.570667 22.570667 0 0 1 13.184 5.418667 4125.696 4125.696 0 0 1 150.912 150.912c13.866667 16.298667-10.410667 46.976-30.165333 30.165333a4125.696 4125.696 0 0 1-150.912-150.912c-11.136-13.056-1.834667-36.096 16.981333-35.584z" fill="#0400FF" p-id="4103"></path></svg>
    </div>
    </div>
    <div style="width:100%" id="search-content">
    </div>
    <div>
    `
    return box;
}
function scholarContent(ref, cid) {
    return ` <div class="scholar-data" data-cid=${cid}>${ref}</div>`
}

// query article list , the function returns article ids
function getArticleIDList(query) {
    return new Promise((resolve, reject) => {
        GM_xmlhttpRequest({
            url: scholarURL(query),
            method: "GET",
            onload: response => {
                let parser = new DOMParser();
                let doc = parser.parseFromString(response.responseText, 'text/html');
                let searchItems = doc.querySelectorAll('div[data-cid]');
                let articlesIDs = [];
                searchItems.forEach((article, key) => {
                    let cid = article.getAttribute('data-cid');
                    try {
                        let title = article.querySelector("h3").textContent;
                        let author = article.querySelector("div.gs_a").textContent;
                        if (!cid.startsWith("gs") && key <= 8) {
                            articlesIDs.push({
                                id: cid,
                                title: title,
                                author: author
                            });
                        }
                    } catch (err) {
                        console.log(err)
                    }

                })
                resolve(articlesIDs)
            },
            onerror: err => {
                reject(err)
            }
        })
    })

}

// get reference page by ID
function getRefPage(id) {
    return new Promise((resolve, reject) => {
        GM_xmlhttpRequest({
            url: scholarRefPageURL(id),
            method: "GET",
            onload: res => {
                resolve(res.response)
            },
            onerror: err => {
                reject(err)
            }
        })
    })
}

function getGBRef(id) {
    return getRefPage(id).then(page => {
        let dom = document.createElement("div");
        dom.innerHTML = page;
        let refs = dom.querySelectorAll("#gs_citt tr");
        for (let ref of refs) {
            let v = ref.querySelector('.gs_citr').textContent.trim();
            let styleName = ref.querySelector('.gs_cith').textContent.trim();
            if ("GB/T 7714" == styleName) {
                return v;
            }
        }
    })
}
function getBibTex(id) {
    return new Promise((resolve, reject) => {
        getRefPage(id).then(page => {
            let dom = document.createElement("div");
            dom.innerHTML = page;
            let first = dom.querySelector("#gs_citi>a.gs_citi").href;
            return GM_xmlhttpRequest({
                url: first,
                method: "GET",
                onload: (res) => {
                    resolve(res.responseText);
                },
                onerror: err => {
                    console.log("获取bib发生了错误:", err);
                    reject(err)
                }
            });
        })
    })

}