feat: add diff online tool

This commit is contained in:
Baoshuo Ren 2023-02-04 11:29:12 +08:00
parent d4d98f6d55
commit 9880357433
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
5 changed files with 300 additions and 242 deletions

View File

@ -0,0 +1,49 @@
<?php
requireLib('bootstrap5');
?>
<?php echoUOJPageHeader(UOJLocale::get('diff online')) ?>
<h1>
<?= UOJLocale::get('diff online') ?>
</h1>
<div class="card">
<div class="card-body">
<div style="height: 700px" id="diff-editor-container">
<div class="border d-flex justify-content-center align-items-center w-100 h-100">
<div class="spinner-border text-muted" style="width: 3rem; height: 3rem;"></div>
</div>
</div>
</div>
<div class="card-footer bg-transparent text-end">
<a href="https://s2oj.github.io/#/user/apps/diff_online" target="_blank">使用教程</a>
</div>
</div>
<script>
var div_editor = $('#diff-editor-container');
require_monaco({}, function() {
$(div_editor).html('');
var originalModel = monaco.editor.createModel("", "text/plain");
var modifiedModel = monaco.editor.createModel("", "text/plain");
var diffEditor = monaco.editor.createDiffEditor(div_editor[0], {
originalEditable: true, // for left pane
readOnly: false, // for right pane
fontSize: "16px",
automaticLayout: true,
});
diffEditor.setModel({
original: originalModel,
modified: modifiedModel,
});
$(div_editor).addClass('border overflow-hidden');
});
</script>
<?php echoUOJPageFooter() ?>

View File

@ -102,4 +102,5 @@ return [
'apps' => 'Apps',
'image hosting' => 'Image Hosting',
'html to markdown' => 'HTML to Markdown',
'diff online' => 'Diff Online',
];

View File

@ -102,4 +102,5 @@ return [
'apps' => '应用',
'image hosting' => '图床',
'html to markdown' => 'HTML 转 Markdown',
'diff online' => '在线比较',
];

View File

@ -96,6 +96,7 @@ Route::group(
// Apps
Route::any('/apps/image_hosting', '/apps/image_hosting.php');
Route::any('/apps/html2markdown', '/apps/html2markdown.php');
Route::any('/apps/diff_online', '/apps/diff_online.php');
}
);

View File

@ -1,252 +1,258 @@
<?php
if (isset($REQUIRE_LIB['bootstrap5'])) {
$new_user_msg_num = DB::selectCount("select count(*) from user_msg where receiver = '".Auth::id()."' and read_time is null");
$new_system_msg_num = DB::selectCount("select count(*) from user_system_msg where receiver = '".Auth::id()."' and read_time is null");
$new_msg_tot = $new_user_msg_num + $new_system_msg_num;
}
?>
if (isset($REQUIRE_LIB['bootstrap5'])) {
$new_user_msg_num = DB::selectCount("select count(*) from user_msg where receiver = '" . Auth::id() . "' and read_time is null");
$new_system_msg_num = DB::selectCount("select count(*) from user_system_msg where receiver = '" . Auth::id() . "' and read_time is null");
$new_msg_tot = $new_user_msg_num + $new_system_msg_num;
}
?>
<div class="navbar navbar-light navbar-expand-md
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
bg-white shadow-sm
<?php else: ?>
<?php else : ?>
bg-light
<?php endif ?>
<?php if (!isset($disable_navbar_margin_bottom)): ?>
<?php if (!isset($disable_navbar_margin_bottom)) : ?>
mb-4
<?php endif ?>
" role="navigation">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="container">
<?php endif ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<div class="container">
<?php endif ?>
<a class="navbar-brand fw-normal" href="<?= HTML::url('/') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<img src="<?= HTML::url('/images/logo_small.png') ?>" alt="Logo" width="24" height="24" class="d-inline-block align-text-top"/>
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<img src="<?= HTML::url('/images/logo_small.png') ?>" alt="Logo" width="24" height="24" class="d-inline-block align-text-top" />
<?php endif ?>
<?= UOJConfig::$data['profile']['oj-name-short'] ?>
</a>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<?php else: ?>
<button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<?php endif ?>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/contests') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-bar-chart"></i>
<?php else: ?>
<span class="glyphicon glyphicon-stats"></span>
<?php endif ?>
<?= UOJLocale::get('contests') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/problems') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-list-task"></i>
<?php else: ?>
<span class="glyphicon glyphicon-th-list"></span>
<?php endif ?>
<?= UOJLocale::get('problems') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/groups') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-people"></i>
<?php else: ?>
<span class="glyphicon glyphicon-education"></span>
<?php endif ?>
<?= UOJLocale::get('groups') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/lists') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-card-list"></i>
<?php else: ?>
<span class="glyphicon glyphicon-list-alt"></span>
<?php endif ?>
<?= UOJLocale::get('problems lists') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/submissions') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-pie-chart"></i>
<?php else: ?>
<span class="glyphicon glyphicon-tasks"></span>
<?php endif ?>
<?= UOJLocale::get('submissions') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/hacks') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-flag"></i>
<?php else: ?>
<span class="glyphicon glyphicon-flag"></span>
<?php endif ?>
<?= UOJLocale::get('hacks') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::blog_list_url() ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-pencil-square"></i>
<?php else: ?>
<span class="glyphicon glyphicon-edit"></span>
<?php endif ?>
<?= UOJLocale::get('blogs') ?>
</a>
</li>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-grid-3x3-gap"></i>
<?= UOJLocale::get('apps') ?>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="<?= HTML::url('/apps/image_hosting') ?>">
<i class="bi bi-images"></i>
<?= UOJLocale::get('image hosting') ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/apps/html2markdown') ?>">
<i class="bi bi-markdown"></i>
<?= UOJLocale::get('html to markdown') ?>
</a>
</li>
</ul>
</li>
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<?php else : ?>
<button type="button" class="navbar-toggler collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<?php endif ?>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/faq') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<i class="bi bi-question-circle"></i>
<?php else: ?>
<span class="glyphicon glyphicon-info-sign"></span>
<?php endif ?>
<?= UOJLocale::get('help') ?>
</a>
</li>
</ul>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<hr class="d-md-none text-muted">
<ul class="nav navbar-nav ms-md-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-translate"></i>
<?= UOJLocale::get('_common_name') ?>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="<?= HTML::url(UOJContext::requestURI(), array('params' => array('locale' => 'zh-cn'))) ?>">
中文
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/contests') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-bar-chart"></i>
<?php else : ?>
<span class="glyphicon glyphicon-stats"></span>
<?php endif ?>
<?= UOJLocale::get('contests') ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url(UOJContext::requestURI(), array('params' => array('locale' => 'en'))) ?>">
English
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/problems') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-list-task"></i>
<?php else : ?>
<span class="glyphicon glyphicon-th-list"></span>
<?php endif ?>
<?= UOJLocale::get('problems') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/groups') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-people"></i>
<?php else : ?>
<span class="glyphicon glyphicon-education"></span>
<?php endif ?>
<?= UOJLocale::get('groups') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/lists') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-card-list"></i>
<?php else : ?>
<span class="glyphicon glyphicon-list-alt"></span>
<?php endif ?>
<?= UOJLocale::get('problems lists') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/submissions') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-pie-chart"></i>
<?php else : ?>
<span class="glyphicon glyphicon-tasks"></span>
<?php endif ?>
<?= UOJLocale::get('submissions') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/hacks') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-flag"></i>
<?php else : ?>
<span class="glyphicon glyphicon-flag"></span>
<?php endif ?>
<?= UOJLocale::get('hacks') ?>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::blog_list_url() ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-pencil-square"></i>
<?php else : ?>
<span class="glyphicon glyphicon-edit"></span>
<?php endif ?>
<?= UOJLocale::get('blogs') ?>
</a>
</li>
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-grid-3x3-gap"></i>
<?= UOJLocale::get('apps') ?>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="<?= HTML::url('/apps/image_hosting') ?>">
<i class="bi bi-images"></i>
<?= UOJLocale::get('image hosting') ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/apps/html2markdown') ?>">
<i class="bi bi-markdown"></i>
<?= UOJLocale::get('html to markdown') ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/apps/diff_online') ?>">
<i class="bi bi-file-earmark-diff"></i>
<?= UOJLocale::get('diff online') ?>
</a>
</li>
</ul>
</li>
<?php endif ?>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/faq') ?>">
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<i class="bi bi-question-circle"></i>
<?php else : ?>
<span class="glyphicon glyphicon-info-sign"></span>
<?php endif ?>
<?= UOJLocale::get('help') ?>
</a>
</li>
</ul>
</li>
<?php if (Auth::check()): ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-person-fill"></i>
<span class="position-relative">
<?= Auth::id() ?>
<?php if ($new_msg_tot): ?>
<span class="badge bg-danger rounded-pill">
<?= $new_msg_tot > 99 ? "99+" : $new_msg_tot ?>
</span>
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
<hr class="d-md-none text-muted">
<ul class="nav navbar-nav ms-md-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-translate"></i>
<?= UOJLocale::get('_common_name') ?>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="<?= HTML::url(UOJContext::requestURI(), array('params' => array('locale' => 'zh-cn'))) ?>">
中文
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url(UOJContext::requestURI(), array('params' => array('locale' => 'en'))) ?>">
English
</a>
</li>
</ul>
</li>
<?php if (Auth::check()) : ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-person-fill"></i>
<span class="position-relative">
<?= Auth::id() ?>
<?php if ($new_msg_tot) : ?>
<span class="badge bg-danger rounded-pill">
<?= $new_msg_tot > 99 ? "99+" : $new_msg_tot ?>
</span>
<?php endif ?>
</span>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="<?= HTML::url('/user/' . Auth::id()) ?>">
<?= UOJLocale::get('my profile') ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/user_msg') ?>">
<?= UOJLocale::get('private message') ?>
<?php if ($new_user_msg_num) : ?>
<span class="badge bg-danger rounded-pill">
<?= $new_user_msg_num > 99 ? "99+" : $new_user_msg_num ?>
</span>
<?php endif ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/user/' . Auth::id() . '/system_msg') ?>">
<?= UOJLocale::get('system message') ?>
<?php if ($new_system_msg_num) : ?>
<span class="badge bg-danger rounded-pill">
<?= $new_system_msg_num > 99 ? "99+" : $new_system_msg_num ?>
</span>
<?php endif ?>
</a>
</li>
<?php if (isSuperUser(Auth::user())) : ?>
<li>
<a class="dropdown-item" href="<?= HTML::url('/super_manage') ?>">
<?= UOJLocale::get('system manage') ?>
</a>
</li>
<?php endif ?>
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/logout?_token=' . crsf_token()) ?>">
<?= UOJLocale::get('logout') ?>
</a>
</li>
</ul>
</li>
<?php else : ?>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/login') ?>">
<i class="bi bi-box-arrow-in-right"></i>
<?= UOJLocale::get('login') ?>
</a>
</li>
<?php if (UOJConfig::$data['switch']['open-register'] || !DB::selectCount("SELECT COUNT(*) FROM user_info")) : ?>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/register') ?>">
<i class="bi bi-person-plus-fill"></i>
<?= UOJLocale::get('register') ?>
</a>
</li>
<?php endif ?>
<?php endif ?>
</span>
</a>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="<?= HTML::url('/user/' . Auth::id()) ?>">
<?= UOJLocale::get('my profile') ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/user_msg') ?>">
<?= UOJLocale::get('private message') ?>
<?php if ($new_user_msg_num): ?>
<span class="badge bg-danger rounded-pill">
<?= $new_user_msg_num > 99 ? "99+" : $new_user_msg_num ?>
</span>
<?php endif ?>
</a>
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/user/'.Auth::id().'/system_msg') ?>">
<?= UOJLocale::get('system message') ?>
<?php if ($new_system_msg_num): ?>
<span class="badge bg-danger rounded-pill">
<?= $new_system_msg_num > 99 ? "99+" : $new_system_msg_num ?>
</span>
<?php endif ?>
</a>
</li>
<?php if (isSuperUser(Auth::user())): ?>
<li>
<a class="dropdown-item" href="<?= HTML::url('/super_manage') ?>">
<?= UOJLocale::get('system manage') ?>
</a>
</li>
<?php endif ?>
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item" href="<?= HTML::url('/logout?_token=' . crsf_token()) ?>">
<?= UOJLocale::get('logout') ?>
</a>
</li>
</ul>
</li>
<?php else: ?>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/login') ?>">
<i class="bi bi-box-arrow-in-right"></i>
<?= UOJLocale::get('login') ?>
</a>
</li>
<?php if (UOJConfig::$data['switch']['open-register'] || !DB::selectCount("SELECT COUNT(*) FROM user_info")): ?>
<li class="nav-item">
<a class="nav-link" href="<?= HTML::url('/register') ?>">
<i class="bi bi-person-plus-fill"></i>
<?= UOJLocale::get('register') ?>
</a>
</li>
<?php endif ?>
<?php endif ?>
</ul>
<?php else: ?>
<form id="form-search-problem" class="form-inline my-2 my-lg-0" method="get">
<div class="input-group">
<input type="text" class="form-control" name="search" id="input-search" placeholder="<?= UOJLocale::get('search')?>" />
<div class="input-group-append">
<button type="submit" class="btn btn-search btn-outline-primary" id="submit-search"><span class="glyphicon glyphicon-search"></span></button>
</div>
</ul>
<?php else : ?>
<form id="form-search-problem" class="form-inline my-2 my-lg-0" method="get">
<div class="input-group">
<input type="text" class="form-control" name="search" id="input-search" placeholder="<?= UOJLocale::get('search') ?>" />
<div class="input-group-append">
<button type="submit" class="btn btn-search btn-outline-primary" id="submit-search"><span class="glyphicon glyphicon-search"></span></button>
</div>
</div>
</form>
<?php endif ?>
</div>
</form>
<?php endif ?>
</div>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php if (isset($REQUIRE_LIB['bootstrap5'])) : ?>
</div>
<?php endif ?>
</div>
@ -254,22 +260,22 @@ mb-4
var zan_link = '';
</script>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
<script type="text/javascript">
$('#form-search-problem').submit(function(e) {
e.preventDefault();
<?php if (!isset($REQUIRE_LIB['bootstrap5'])) : ?>
<script type="text/javascript">
$('#form-search-problem').submit(function(e) {
e.preventDefault();
url = '<?= HTML::url('/problems') ?>';
qs = [];
$(['search']).each(function () {
if ($('#input-' + this).val()) {
qs.push(this + '=' + encodeURIComponent($('#input-' + this).val()));
url = '<?= HTML::url('/problems') ?>';
qs = [];
$(['search']).each(function() {
if ($('#input-' + this).val()) {
qs.push(this + '=' + encodeURIComponent($('#input-' + this).val()));
}
});
if (qs.length > 0) {
url += '?' + qs.join('&');
}
location.href = url;
});
if (qs.length > 0) {
url += '?' + qs.join('&');
}
location.href = url;
});
</script>
</script>
<?php endif ?>