Browse Source

fix&shorten chem

root 2 years ago
parent
commit
da9eef00ae
3 changed files with 24 additions and 76 deletions
  1. 0 31
      chem/query/index.html
  2. 24 45
      js/chem.js
  3. 0 0
      js/chem.min.js

+ 0 - 31
chem/query/index.html

@@ -1,31 +0,0 @@
-<!DOCTYPE html>
-
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>化学</title>
-    <script type="text/javascript" src="/js/jquery.min.js" crossorigin="anonymous"></script>
-    <link rel="stylesheet" href="/css/bootstrap.min.css" crossorigin="anonymous">
-    <script type="text/javascript" src="/js/bootstrap.min.js" crossorigin="anonymous"></script>
-    <link rel="stylesheet" href="/css/style.css">
-    <link rel="preconnect" href="https://fonts.gstatic.com">
-    <link href="https://fonts.loli.net/css2?family=Anonymous+Pro:ital,wght@0,400;0,700;1,400;1,700
-&family=Noto+Serif+SC:wght@300;400;500;600;700&display=swap" rel="stylesheet">
-
-</head>
-
-<body>
-    <h4 class="well">!! !。?<div class="well text-warning"><div class="alert alert-danger">WARNING!!!!</div><h3>YOUUUUUUUU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;re being watched.</h3></div><div style="font-size:10px">Do not loapp.post('/chess/setboard', (req, res) => {
-        board = req.body;
-        const from = req.body.from;
-        const result = { succeed: true };
-        wsClients['chess'].forEach((client) => {
-            // console.log(client)
-            client.send(JSON.stringify({
-                from,
-                content: req.body.content,
-                message: req.body.message
-            }));
-        });
-        res.json(result);
-    });.</div></h4>
-</body>

+ 24 - 45
js/chem.js

@@ -254,75 +254,54 @@ function balUp() {
 //QUERY-------------------------------
 
 var modeq = 'query', nameq = 'eq', strict = false, matchMode = 'mole'
+function toggl(str, e = 0, f = 0) {
+    $('#qryBtn').text(str)
+    if (e) {
+        $('#qryMatch').hide(), $('.addInput').show(), $('.ok').hide()
+        if (e == 2) $('#addId').show()
+        else $('#addId').hide()
+    }
+    else $('#qryMatch').show(), $('.addInput').hide(), $('.ok').show()
+    if (f) $('.qryInputHidable').show()
+    else $('.qryInputHidable').hide()
+}
 function setQryEq() {
-    $('#qryMatch').show()
-    $('.addInput').hide()
-    $('.ok').show()
+    toggl('查询方程式')
     modeq = 'query', nameq = 'eq', strict = false
-    $('.qryInputHidable').hide()
-    $('#qryBtn').text('查询方程式')
-    $('#qryInput').attr('placeholder', 'O2=H2O'+'(输入化学式查询数据库,支持模糊搜索)')
+    $('#qryInput').attr('placeholder', 'O2=H2O' + '(输入化学式查询数据库,支持模糊搜索)')
     input2();
 }
 function setQryEq2() {
-    $('#qryMatch').show()
-    $('.addInput').hide()
-    $('.ok').show()
+    toggl('查询方程式*', 0, 1)
     modeq = 'query', nameq = 'eq', strict = true
-    $('.qryInputHidable').show()
-    $('#qryBtn').text('查询方程式*')
     $('#qryInput').attr('placeholder', 'H2O')
     input2();
 }
 function setQryMo() {
-    $('#qryMatch').show()
-    $('.addInput').hide()
-    $('.ok').show()
+    toggl('查询分子')
     modeq = 'query', nameq = 'mo'
-    $('.qryInputHidable').hide()
-    $('#qryBtn').text('查询分子')
     input2();
 }
 function setAddEq() {
-    $('#qryMatch').hide()
-    $('.addInput').show()
-    $('#addId').hide()
-    $('.ok').hide()
+    toggl('上传方程式', 1)
     modeq = 'add', nameq = 'eq'
-    $('.qryInputHidable').hide()
-    $('#qryBtn').text('上传方程式')
-    $('#qryInput').attr('placeholder', 'H2+O2=H2O'+'(输入化学式上传至数据库)')
+    $('#qryInput').attr('placeholder', 'H2+O2=H2O' + '(输入化学式上传至数据库)')
 }
 function setAddMo() {
-    $('#qryMatch').hide()
-    $('.addInput').show()
-    $('#addId').hide()
-    $('.ok').hide()
+    toggl('上传分子', 1)
     modeq = 'add', nameq = 'mo'
-    $('.qryInputHidable').hide()
-    $('#qryBtn').text('上传分子')
 }
 function setUpdEq() {
-    $('#qryMatch').hide()
-    $('.addInput').show()
-    $('#addId').show()
-    $('.ok').hide()
+    toggl('修改方程式', 2)
     modeq = 'upd', nameq = 'eq'
-    $('.qryInputHidable').hide()
-    $('#qryBtn').text('修改方程式')
     $('#qryInput').attr('placeholder', '(输入 id 修改已有化学式)')
 }
 function setUpdMo() {
-    $('#qryMatch').hide()
-    $('.addInput').show()
-    $('#addId').show()
-    $('.ok').hide()
+    toggl('修改分子', 2)
     modeq = 'upd', nameq = 'mo'
-    $('.qryInputHidable').hide()
-    $('#qryBtn').text('修改分子')
 }
 function replaceRegex(s) {
-    return s.replace(/([\+\=\.;])+/g, '$1').replace(/([\(\)])/g, '\\\\$1')
+    return s.replace(/([\+\=\.;])+/g, '$1').replace(/([\(\)])/g, '\\\\$1').replace(/(<\d*)e\+/g, '$1%')
 }
 function getRegex() {
     var ret = ''
@@ -368,12 +347,12 @@ function getRegex() {
         }
         ret += '.*'
     }
-    return ret
+    return ret.replace(/%/g, 'e+')
 }
 function query() {
     if (modeq == 'query' || modeq == 'add') {
         var cont = getRegex();
-        $('.ok')[0].innerHTML = cont;
+        $('.ok').text(cont);
         var bd = JSON.stringify({
             content: cont,
         })
@@ -499,7 +478,7 @@ function query() {
 
 function input2() {
     if (modeq == 'query') {
-        $('.ok')[0].innerHTML = getRegex()
+        $('.ok').text(getRegex())
     }
     if ($('#qryInputRender')[0]) $('#qryInputRender')[0].innerHTML = (strict ? renderEquation($('#qryInput').val() + '=' + $('#qryInput2').val()) : renderEquation($('#qryInput').val()))
     MathJax.typeset()

File diff suppressed because it is too large
+ 0 - 0
js/chem.min.js


Some files were not shown because too many files changed in this diff