您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Extend 124OJ!
当前为
// ==UserScript== // @name ex124OJ // @namespace http://tampermonkey.net/ // @version 0.4.4 // @description Extend 124OJ! // @author Sukwants // @license MIT // @match http://124.221.194.184 // @match http://124.221.194.184/* // @icon http://124.221.194.184/images/logo_small.png // @grant GM_addStyle // ==/UserScript== /* ==User Settings== */ // Change Page Background. (Image URL, Opacity) const BackgroundSettings = ['https://www.imageoss.com/images/2022/11/22/Waterleidingduinen_ZH-CN1430683267_1920x1080a4af60c7b974ccd7.jpg']; // Change username color. const NameColorList = {'Sukwants':'#8e44ad','Star32':'#e74c3c','2745518585':'#996600','syysongyuyang':'#e67e22'}; // Add CCF level badge. const CCFBadgeList = {}; // Add name tag badge. const TagBadgeList = {'Sukwants':['#8e44ad','旅客'],'Star32':['#e74c3c','陌生人'],'2745518585':['#996600','作弊者'],'syysongyuyang':['#e67e22','原批']}; function getBackground() { if (BackgroundSettings[0]) return BackgroundSettings[0]; else return ''; } function getOpacity() { if (BackgroundSettings[1]) return BackgroundSettings[1]; else return '0.85'; } function BackgroundImage() { document.getElementsByClassName('navbar-brand')[0].innerHTML = '<img src="http://124.221.194.184/images/logo_small.png" alt="Logo" class="img-rounded" style="width:39px; height:39px;">'; document.getElementsByClassName('container')[0].children[0].children[1].innerHTML = document.getElementsByClassName('container')[0].children[0].children[1].innerHTML.match(/(.*> ){0,1}(.*)/)[2]; GM_addStyle('\ body {\ background: url("' + getBackground() + '");\ background-repeat: no-repeat;\ background-attachment: fixed;\ background-position: 50% 50%;\ background-size: cover;\ }\ .uoj-content {\ background-color: #fff;\ margin: 16px -16px;\ padding: 16px 16px;\ opacity: ' + getOpacity() + ';\ border-radius: 8px;\ }\ .navbar {\ margin: 16px -16px;\ padding: 8px 16px;\ opacity: ' + getOpacity() + ';\ border-radius: 8px;\ }'); } function CodeBlock() { GM_addStyle('\ @import url(https://cdn.jsdelivr.net/npm/[email protected]/distr/fira_code.css);\ code {\ font-family: "Fira Code";\ }\ code.sh_cpp>span {\ font-style: normal !important;\ font-weight: 400 !important;\ }\ code.sh_cpp>span.sh_preproc,\ code.sh_cpp>span.sh_keyword,\ code.sh_cpp>span.sh_type {\ color: #8959a8;\ }\ code.sh_cpp>span.sh_string {\ color: #718c00;\ }\ code.sh_cpp>span.sh_cbracket {\ color: #4d4d4c;\ }\ code.sh_cpp>span.sh_symbol {\ color: #3e999f;\ }\ code.sh_cpp>span.sh_number {\ color: #f5871f;\ }\ code.sh_cpp>span.sh_function {\ color: #4271ae;\ }\ code.sh_cpp>span.sh_comment {\ color: #8e908c;\ }'); } function NameColor() { var Names = document.getElementsByClassName('uoj-username'); var NeedsRepeat = false; for (var i in Names) { if (Names[i].innerHTML && NameColorList[Names[i].innerHTML]) { Names[i].style = 'color:' + NameColorList[Names[i].innerHTML]; if (Names[i].parentElement.getAttribute('class') == 'legendLabel') { NeedsRepeat = true; } } } if (NeedsRepeat) { setInterval(function(){ var Names = document.getElementsByClassName('uoj-username'); for (var i in Names) { if (Names[i].innerHTML && Names[i].parentElement.getAttribute('class') == 'legendLabel' && NameColorList[Names[i].innerHTML]) { Names[i].style = 'color:' + NameColorList[Names[i].innerHTML]; } } }, 200); } var Honors = document.getElementsByClassName('uoj-honor'); for (var j in Honors) { if (Honors[j].innerHTML && NameColorList[Honors[j].innerHTML]) { Honors[j].style = "color:" + NameColorList[Honors[j].innerHTML]; } } } const NameWithBadge = /^(.{1,}?)( <.*){0,1}$/; function CCFBadge() { var Names = document.getElementsByClassName('uoj-username'); for (var i in Names) { if (!Names[i].innerHTML || !NameWithBadge.test(Names[i].innerHTML)) continue; var name = Names[i].innerHTML.match(NameWithBadge)[1]; if (CCFBadgeList[name] && Names[i].parentElement.getAttribute('class') != 'legendLabel') { Names[i].innerHTML = Names[i].innerHTML + ' <svg width="1em" height="1em" data-v-303bbf52="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="margin-bottom:.25em!important;bottom:10px;--fa-primary-color:#fff;--fa-secondary-color:' + CCFBadgeList[name] + ';--fa-secondary-opacity:1;"><g data-v-303bbf52="" class="fa-group"><path data-v-303bbf52="" fill="var(--fa-secondary-color)" d="M512 256a88 88 0 0 0-57.1-82.4A88 88 0 0 0 338.4 57.1a88 88 0 0 0-164.8 0A88 88 0 0 0 57.1 173.6a88 88 0 0 0 0 164.8 88 88 0 0 0 116.5 116.5 88 88 0 0 0 164.8 0 88 88 0 0 0 116.5-116.5A88 88 0 0 0 512 256zm-144.8-44.25l-131 130a11 11 0 0 1-15.55-.06l-75.72-76.33a11 11 0 0 1 .06-15.56L171 224a11 11 0 0 1 15.56.06l42.15 42.49 97.2-96.42a11 11 0 0 1 15.55.06l25.82 26a11 11 0 0 1-.08 15.56z" class="fa-secondary"></path></g></svg>'; } } var Honors = document.getElementsByClassName('uoj-honor'); for (var j in Honors) { if (!Honors[j].innerHTML || !NameWithBadge.test(Honors[j].innerHTML)) continue; var honor = Honors[j].innerHTML.match(NameWithBadge)[1]; if (CCFBadgeList[honor]) { Honors[j].innerHTML = Honors[j].innerHTML + ' <svg width="1em" height="1em" data-v-303bbf52="" aria-hidden="true" focusable="false" data-prefix="fad" data-icon="badge-check" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="margin-bottom:.25em!important;bottom:10px;--fa-primary-color:#fff;--fa-secondary-color:' + CCFBadgeList[honor] + ';--fa-secondary-opacity:1;"><g data-v-303bbf52="" class="fa-group"><path data-v-303bbf52="" fill="var(--fa-secondary-color)" d="M512 256a88 88 0 0 0-57.1-82.4A88 88 0 0 0 338.4 57.1a88 88 0 0 0-164.8 0A88 88 0 0 0 57.1 173.6a88 88 0 0 0 0 164.8 88 88 0 0 0 116.5 116.5 88 88 0 0 0 164.8 0 88 88 0 0 0 116.5-116.5A88 88 0 0 0 512 256zm-144.8-44.25l-131 130a11 11 0 0 1-15.55-.06l-75.72-76.33a11 11 0 0 1 .06-15.56L171 224a11 11 0 0 1 15.56.06l42.15 42.49 97.2-96.42a11 11 0 0 1 15.55.06l25.82 26a11 11 0 0 1-.08 15.56z" class="fa-secondary"></path></g></svg>'; } } } function TagBadge() { var Names = document.getElementsByClassName('uoj-username'); for (var i in Names) { if (!Names[i].innerHTML || !NameWithBadge.test(Names[i].innerHTML)) continue; var name = Names[i].innerHTML.match(NameWithBadge)[1]; if (TagBadgeList[name] && Names[i].parentElement.getAttribute('class') != 'legendLabel') { Names[i].innerHTML = Names[i].innerHTML + ' <span style="background-color:' + TagBadgeList[name][0] + ';padding:0.2em 0.6em;border-radius:.2em;color:#fff;font-size:0.7em;font-weight:bold;display:inline-block">' + TagBadgeList[name][1] + '</span>'; } } var Honors = document.getElementsByClassName('uoj-honor'); for (var j in Honors) { if (!Honors[j].innerHTML || !NameWithBadge.test(Honors[j].innerHTML)) continue; var honor = Honors[j].innerHTML.match(NameWithBadge)[1]; if (TagBadgeList[honor]) { Honors[j].innerHTML = Honors[j].innerHTML + ' <span style="background-color:' + TagBadgeList[honor][0] + ';padding:0.2em 0.6em;border-radius:.2em;color:#fff;font-size:0.7em;font-weight:bold;display:inline-block">' + TagBadgeList[honor][1] + '</span>'; } } } function TableStyle() { var Tables = document.getElementsByTagName('table'); for (var table in Tables) { if (Tables[table].nodeType && Tables[table].parentNode.getAttribute('class') != 'legend' && !Tables[table].classList.length) { Tables[table].classList.add('table', 'table-bordered'); } } var ths = document.getElementsByTagName('th'); for (var th in ths) { if (ths[th].nodeType && ths[th].getAttribute('align')) { ths[th].setAttribute('style', 'text-align:' + ths[th].getAttribute('align')); } } } const submissionRegExp = /^http:\/\/124.221.194.184\/submission\/\d{1,}/; function isSubmission() { return submissionRegExp.test(window.location.href); } function SubmissionCard() { setTimeout(function() { var Content = document.getElementsByClassName('uoj-content')[0]; if (Content.childElementCount == 3) { var Table = Content.children[0]; var TabList = document.createElement('ul'); TabList.setAttribute('class', 'nav nav-tabs'); TabList.setAttribute('role', 'tablist'); TabList.innerHTML = '<li class="nav-item"><a class="nav-link active" href="#test-cases" role="tab" data-toggle="tab" aria-selected="true"><span class="glyphicon glyphicon-check"></span> 测试点信息</a></li><li class="nav-item"><a class="nav-link" href="#source" role="tab" data-toggle="tab" aria-selected="false"><span class="glyphicon glyphicon-file"></span> 源代码</a></li>'; var TabContent = document.createElement('div'); TabContent.setAttribute('class', 'tab-content'); TabContent.innerHTML = '<div class="tab-pane card active" id="test-cases"><div class="card-body">' + Content.children[2].children[1].innerHTML + '</div></div><div class="tab-pane card" id="source"><div class="card-body">' + Content.children[1].children[1].innerHTML + '</div></div>'; Content.innerHTML = ""; Content.appendChild(Table); Content.appendChild(TabList); Content.appendChild(TabContent); } }, 10); } const ProblemRegExp = /^http:\/\/124.221.194.184.*\/problem\/(\d{1,})/; function isProblem() { return ProblemRegExp.test(window.location.href); } function downloadData() { var DownloadTag = document.createElement('a'); DownloadTag.setAttribute('role', 'button'); DownloadTag.setAttribute('class', 'btn btn-primary float-right'); DownloadTag.setAttribute('href', '/download.php?type=problem&id=' + window.location.href.match(ProblemRegExp)[1]); DownloadTag.setAttribute('target', '_blank'); DownloadTag.innerHTML = '<span class="glyphicon glyphicon-download-alt"></span> 下载数据'; document.getElementsByClassName("btn btn-info float-right")[0].after(DownloadTag); } const UserProfileRegExp = /^http:\/\/124.221.194.184\/user\/profile\/.{1,}/; function isUserProfile() { return UserProfileRegExp.test(window.location.href); } const BlogRegExp = /^http:\/\/124.221.194.184\/blog\/.{1,}/; function isBlog() { return BlogRegExp.test(window.location.href); } const GravatarURLRegExp = /\/\/cn.gravatar.com\/avatar\/(.*)$/; function changeGravatarURL() { var Gravatar = document.getElementsByClassName('img-thumbnail')[0]; if (Gravatar && Gravatar.nodeType){ console.log(Gravatar); Gravatar.setAttribute('src', '//gravatar.loli.net/avatar/' + Gravatar.getAttribute('src').match(GravatarURLRegExp)[1]); } var Gravatars = document.getElementsByClassName('img-rounded'); for (var gravatar in Gravatars) { if (Gravatars[gravatar] && Gravatars[gravatar].nodeType && GravatarURLRegExp.test(Gravatars[gravatar].getAttribute('src'))) { Gravatars[gravatar].setAttribute('src', '//gravatar.loli.net/avatar/' + Gravatars[gravatar].getAttribute('src').match(GravatarURLRegExp)[1]); } } } (function() { 'use strict'; if (BackgroundSettings[0]) BackgroundImage(); CodeBlock(); NameColor(); CCFBadge(); TagBadge(); TableStyle(); if (isSubmission()) SubmissionCard(); if (isProblem()) downloadData(); if (isUserProfile() || isBlog()) changeGravatarURL(); })();