跳到正文

剪贴板

剪贴板 1o8w5c5w

原文
剪贴板信息

剪贴板信息

收录
更新

备注:http://www.gdfzoj.com/post/1038

C++
// ==UserScript==
// @name         EmojiGFOJ
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  /oh /hsh /zhq
// @author       ExplodingKonjac
// @license      GPLv3
// @match        http://*.gdfzoj.com/*
// @match        https://uoj.ac/*
// ==/UserScript==

(function() {

    const emoji_dic={
        'cyz': 'https://cdn.luogu.com.cn/upload/image_hosting/h6db8ps0.png',
        'yhy': 'https://cdn.luogu.com.cn/upload/image_hosting/vj60m5zk.png',
        'kao': 'https://cdn.luogu.com.cn/upload/image_hosting/jl4n59rr.png',
        'rickroll': 'https://cdn.luogu.com.cn/upload/image_hosting/4ghzapoo.png'
    }
    window.score_blocks=new Array()
    window.show_score=false
    window.extendScore=function(e) {
        e.firstChild.style.width='100pt'
        e.lastChild.style.width='100pt'
    }
    window.shrinkScore=function(e) {
        if(window.show_score) return
        e.firstChild.style.width='30pt'
        e.lastChild.style.width='30pt'
    }

    function getScoreLevel(x) { // 0<=x<=1
        if(x<=0.4) return 'yhy'
        else if(x<=0.7) return 'kao'
        else if(x<=0.99) return 'rickroll'
        else return 'cyz'
    }
    function newEmoji(url) { // create emoji element
        var res=document.createElement("img")
        res.className="emoji"
        res.src=url
        return res;
    }
    function newScoreBlock(score,emj) { // create score block element
        var res=document.createElement("span")
        res.oldw=score.offsetWidth
        score.style.width='30pt'
        res.className="score-block"
        res.appendChild(emj)
        res.innerHTML+=score.outerHTML
        res.onmouseover=function(){ window.extendScore(res) }
        res.onmouseleave=function(){ window.shrinkScore(res) }
        window.score_blocks.push(res)
        return res;
    }

    document.querySelectorAll('a[class="uoj-score"]').forEach(function(e) {
        var max_score=100
        if(e.hasAttribute('data-max'))
            max_score=Number(e.getAttribute('data-max'))
        var x=Number(e.innerHTML)/max_score
        var url=''
        if(e.innerHTML=='97') url=emoji_dic.zhm
        else url=emoji_dic[getScoreLevel(x)]
        e.parentNode.insertBefore(newScoreBlock(e,newEmoji(url)),e)
        e.remove()
    })

    var max_score_elem=document.querySelector('span[class="uoj-score"]')
    if(max_score_elem!=null) {
        var max_score=Number(max_score_elem.innerHTML);
        document.querySelectorAll('th').forEach(function(e) {
            var str=''
            if(e.innerHTML=='总分') str='赋分'
            else if(e.innerHTML=='Total Score') str='Relative Score'
            else return
            e.insertAdjacentHTML('afterend','<th style="width:5em">'+str+'</th>')
        })
        document.querySelectorAll('span[class="uoj-score"]').forEach(function(e) {
            var x=(max_score?Number(e.innerHTML)/max_score:0)
            var url=emoji_dic[getScoreLevel(x)]
            var str=String((x*100).toFixed(2))+'%'
            var pa=e.parentElement
            pa.insertBefore(newScoreBlock(e,newEmoji(url)),e)
            pa.parentElement.insertAdjacentHTML('afterend','<td style="width:5em">'+str+'</td>');
            e.remove()
        })
    }

    document.querySelectorAll('a[class="small"]').forEach(function(e) {
        var str=e.innerHTML
        var url=null
        if(url!=null) e.parentNode.appendChild(newEmoji(url))
    })

    var pre=document.querySelector('body > div > div.uoj-footer > div.custom-control.custom-switch')
    pre.querySelector('label').innerHTML="zlt AK IOI 1145141919810 times!"
    var now=document.createElement('div')
    now.classList.add('custom-control','custom-switch')
    now.innerHTML+='<input type="checkbox" class="custom-control-input" id="emojiSwitch">\n'
    now.innerHTML+='<label class="custom-control-label" for="emojiSwitch">Show Score</label>\n'
    pre.parentNode.insertBefore(now,pre.nextSibling)
    document.getElementById('emojiSwitch').addEventListener('change',function() {
        var emoji_switch=document.getElementById('emojiSwitch')
        window.show_score=emoji_switch.checked
        console.log(window.show_score)
        if(emoji_switch.checked) {
            window.score_blocks.forEach(function(e){ window.extendScore(e) })
        }
        else {
            window.score_blocks.forEach(function(e){ window.shrinkScore(e) })
        }
    })

    var sty=document.createElement("style")
    sty.type='text/css'
    sty.innerHTML=`/* some css */
.emoji {
  display: inline-block;
  vertical-align: middle;
  width: 30pt;
  height: 40pt;
  transition: width 1s;
}
.uoj-score {
  display: inline-block;
  vertical-align: middle;
  overflow: hidden;
  transition: width 1s;
}
.score-block {
  display: inline-block;
  white-space: nowrap;
  height: 30pt;
}
`
    document.head.appendChild(sty)
})();