HTML introduction

Display HTML from luogu paste

Από την 14/04/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         HTML introduction
// @namespace    http://tampermonkey.net/
// @version      v1.0.5
// @description  Display HTML from luogu paste
// @author       limesarine
// @match        https://luogu.com/user/*
// @match        https://luogu.com.cn/user/*
// @match        https://*.luogu.com/user/*
// @match        https://*.luogu.com.cn/user/*
// @license      © 2024 Limesarine. All rights reserved.
// @icon         https://www.google.com/s2/favicons?sz=64&domain=luogu.com.cn
// @grant        none
// ==/UserScript==

function deal(id) {
    fetch('/paste/'+id+'?_contentOnly').then(d=>d.text()).then(t=>{
        console.log(t);
        alert(t);
        let data=JSON.parse(t).currentData.paste.data;
        let e=document.getElementsByClassName('introduction marked')[0];
        e.innerHTML=e.innerHTML.replaceAll('LS.PASTE.'+id,data);
    });
}
function deal_float(id) {
    fetch('/paste/'+id+'?_contentOnly').then(d=>d.text()).then(t=>{
        let data=JSON.parse(t).currentData.paste.data;
        let e=document.getElementsByClassName('introduction marked')[0];
        data=`<div style=" position: fixed; left: 50%; transform: translateX(-50%); text-align: center; bottom: 0; background-color: rgba(0,0,0,0);">${data}</div>`;
        e.innerHTML=e.innerHTML.replaceAll('LS.FLOAT.PASTE.'+id,data);
    });
}
function dd() {
    let matches=document.getElementsByClassName('introduction marked')[0].innerHTML.match(/LS\.PASTE\.(........)/g);
    if(matches)
    {
        for(let i=0;i<matches.length;i++)
        {
            let x=matches[i];
            if(x.startsWith('LS.PASTE.') && x.slice(9).length==8)
            {
                console.log(x.slice(9));
                deal(x.slice(9));
            }
        }
    }
    matches=document.getElementsByClassName('introduction marked')[0].innerHTML.match(/LS\.FLOAT\.PASTE\.(........)/g);
    if(matches)
    {
        for(let i=0;i<matches.length;i++)
        {
            let x=matches[i];
            if(x.startsWith('LS.FLOAT.PASTE.') && x.slice(15).length==8)
            {
                console.log(x.slice(15));
                deal_float(x.slice(15));
            }
        }
    }
    return;
}
(function(){
    'use strict';
    let local=location.href.includes('luogu.com.cn')
    const observer=new MutationObserver(()=>{
        const introduction=document.getElementsByClassName("introduction marked")[0];
        if(introduction)
        {
            if(local)
            {
                let e=document.getElementsByClassName("introduction marked")[0];
                if(e.getAttribute('marked')){}
                else
                {
                    e.innerHTML+=`<div style="border: 0; border-radius: 10px; position: fixed; left: 50%; transform: translateX(-50%); text-align: center; bottom: 0; background-color: #ccf"><p style="margin: 3px;">您现在在洛谷国内站,所以无法显示剪贴板中的HTML</p></div>`;
                }
                e.setAttribute('marked',true);
            }
            else
            {
                dd();
            }
        }
    });
    observer.observe(document.documentElement,{childList:true,subtree:true});
})();