Luogu-CopyMarkdown

获取洛谷部分页面源代码

2023-06-27 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==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);
    }
})();