Add Solution To GMOJ

添加一份 solution 到 GMOJ

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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');
    }
);