Add Solution To GMOJ

添加一份 solution 到 GMOJ

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Add Solution To GMOJ
// @namespace    https://greasyfork.org/zh-CN/users/1342573-lnw143
// @version      1.2
// @description  添加一份 solution 到 GMOJ
// @author       lnw143
// @match        https://gmoj.net/senior/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gmoj.net
// @grant        none
// @connect      lnw143.github.io
// @license      MIT
// ==/UserScript==

function waitElement(selector, callback) {
    if ($(selector).length) {
        callback();
    } else {
        setTimeout(() => {
            waitElement(selector, callback);
        }, 100);
    }
}

waitElement(
    '#sidebar',
    function() {
        'use strict';
        console.log("running");
        let urls = location.href.split('/');
        const pid = urls[urls.length-1];
        if(pid.length != 4){
            console.error('pid is not 4 digits');
            return;
        }
        console.log('pid is ' + pid);
        $('#sidebar .well:contains("题解")').append(`<div id="solution">
		<div class="link_solution" data-toggle="tooltip" title="" data-original-title="By lnw143">
		<a href="https://lnw143.github.io/blog/gmoj/p` + pid + `/">solution</a>
		</div> </div>`);
        $('#solution').css({
            'margin-bottom': '4px',
            'display': 'flex',
        })
        $('.link_solution').tooltip();
        console.log('finished');
    }
);