Luogu-CopyMarkdown

获取洛谷部分页面源代码

27.06.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Luogu-CopyMarkdown
// @namespace    https://github.com/Luogu-Extended-Org/Luogu-CopyMarkdown
// @description  获取洛谷部分页面源代码
// @author       BlackPanda
// @license      MIT
// @version      0.2
// @match          https://*.luogu.com.cn/*
// @match          https://*.luogu.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var url = url = window.location.href;
    async function user_detail(){
        var button = document.createElement('button');
        button.textContent = 'Copy';
        button.classList.add('button', 'button-size');
        button.addEventListener('click', async function() {
            var introduction = _feInstance.currentData.user.introduction;
            await navigator.clipboard.writeText(introduction);
            alert('复制成功');
        });
        var tmp = document.getElementsByClassName('card padding-default');
        var pos = tmp[0];
        pos.appendChild(button);
    };
    //To do
    async function blog(){
        var button = document.createElement('button');
        button.textContent = 'Copy';
        button.classList.add('button-blog', 'button-size-blog');
        button.addEventListener('click', async function() {
            fetch('/api/blog/detail/' + BlogGlobals.blogID).then(res => res.json()).then(res => navigator.clipboard.writeText(res.data.Content));
            alert('复制成功');
        });
        var pos = document.querySelector('div>h2');
        pos.insertBefore(button, pos.children[0]);
    };
    async function contest_detail(){
        var button = document.createElement('button');
        button.textContent = 'Copy';
        button.classList.add('button', 'button-size');
        button.addEventListener('click', async function() {
            var introduction = _feInstance.currentData.contest.description;
            await navigator.clipboard.writeText(introduction);
            alert('复制成功');
        });
        var tmp = document.getElementsByClassName('card padding-default');
        var pos = tmp[0];
        pos.appendChild(button);
    };
    async function training_detail(){
        var button = document.createElement('button');
        button.textContent = 'Copy';
        button.classList.add('button', 'button-size');
        button.addEventListener('click', async function() {
            var introduction = _feInstance.currentData.training.description;
            await navigator.clipboard.writeText(introduction);
            alert('复制成功');
        });
        var tmp = document.getElementsByClassName('card padding-default');
        var pos = tmp[0];
        pos.appendChild(button);
    };
    var style = document.createElement('style');
    style.textContent = `
        .button {
            background-color: #6495ed;
            color: #fff;
            border-radius: 6px;
        }
         .button-blog {
            background-color: #6495ed;
            color: #fff;
            border-radius: 6px;
            font-size: 15px;
        }
        .button-size {
            width: 50px;
            height: 25px;
        }
        .button-size-blog {
            width: 40px;
            height: 25px;
        }
        * {
          margin: 0;
          padding: 0;
          border: none;
        }
        `;
    if (url.includes('blog')) {
        //To do
        //document.head.appendChild(style);
        //window.addEventListener('load', blog);
    } else if (url.includes('user')) {
        document.head.appendChild(style);
        window.addEventListener('load', user_detail);
    } else if (url.includes('contest')) {
        document.head.appendChild(style);
        window.addEventListener('load', contest_detail);
    } else if (url.includes('training')) {
        document.head.appendChild(style);
        window.addEventListener('load', training_detail);
    }
})();