Browse Source

add outdated alert

schtonn 2 years ago
parent
commit
83f8d0b690
3 changed files with 42 additions and 24 deletions
  1. 19 12
      chem/index.html
  2. 1 0
      index.html
  3. 22 12
      js/chem.js

+ 19 - 12
chem/index.html

@@ -41,6 +41,18 @@
             pointer-events: none;
             z-index: 0;
         }
+
+        .text-muted a {
+            color: rgb(173, 173, 173);
+        }
+
+        a {
+            transition-duration: 300ms;
+        }
+
+        a:hover {
+            box-shadow: inset 1px 1px 6px rgba(59, 86, 100, 0.3);
+        }
     </style>
     <script id="MathJax-script" src="https://cdn.bootcss.com/mathjax/3.0.5/es5/tex-mml-chtml.js"></script>
     <!-- <script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> -->
@@ -59,7 +71,7 @@
             <div class="input-group">
                 <span class="input-group-btn">
                     <button type="button" class="btn btn-default" onclick="balUp()" id="balShare" title="导入配平结果"> <span
-                            class="glyphicon glyphicon-share-alt" aria-hidden="true"></span></button>
+                            class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></button>
                 </span>
                 <input id="balInput" type="text" class="form-control" oninput="input()">
                 <span class="input-group-btn">
@@ -75,7 +87,7 @@
                         <li><a href="#" onclick="setWeigh2()" data-toggle="tooltip" data-placement="left"
                                 title="四位有效数字">相对质量*</a></li>
                         <li class="divider"></li>
-                        <li><a href="/chemist" data-toggle="tooltip" data-placement="left" title="将打开新页面">配不下了</a>
+                        <li><a href="/chemist" data-toggle="tooltip" data-placement="left" title="将打开新页面">配平接口</a>
                         </li>
                         <li class="divider"></li>
                         <li><a href="#" data-toggle="tooltip" data-placement="left" title="将会对所有人可见">发送到数据库</a></li>
@@ -88,10 +100,10 @@
             <hr>
             <div class="input-group">
                 <span class="input-group-btn">
-                    <button type="button" class="btn btn-default" onclick="balUp()" id="qryShare" title="导入配平结果"> <span
-                            class="glyphicon glyphicon-share-alt" aria-hidden="true"></span></button>
+                    <button type="button" class="btn btn-default" onclick="qryUp()" id="qryShare" title="导入配平结果"> <span
+                            class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></button>
                 </span>
-                <input id="balInput" type="text" class="form-control" oninput="input()">
+                <input id="qryInput" type="text" class="form-control" oninput="input()">
                 <span class="input-group-btn">
                     <button type="button" class="btn btn-default" onclick="balance()" id="qryBtn">查询</button>
                     <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
@@ -100,15 +112,10 @@
                     </button>
                     <ul class="dropdown-menu" role="menu">
                         <li class="dropdown-header">功能</li>
-                        <li><a href="#" onclick="setBal()">配平</a></li>
-                        <li><a href="#" onclick="setWeigh()">相对质量</a></li>
-                        <li><a href="#" onclick="setWeigh2()" data-toggle="tooltip" data-placement="left"
-                                title="四位有效数字">相对质量*</a></li>
+                        <li><a href="#" onclick="setBal()">查询</a></li>
                         <li class="divider"></li>
-                        <li><a href="/chemist" data-toggle="tooltip" data-placement="left" title="将打开新页面">配不下了</a>
+                        <li><a href="/chemist" data-toggle="tooltip" data-placement="left" title="将打开新页面">上传到数据库</a>
                         </li>
-                        <li class="divider"></li>
-                        <li><a href="#" data-toggle="tooltip" data-placement="left" title="将会对所有人可见">发送到数据库</a></li>
                     </ul>
                 </span>
             </div>

+ 1 - 0
index.html

@@ -142,6 +142,7 @@
 </head>
 
 <body itemscope itemtype="http://schema.org/WebPage" style="height:100vh">
+    <div class="alert alert-warning">注意:正在将网站迁移至<a href="http://43.143.233.184/">http://43.143.233.184/</a>,此页面内容可能已经过时。</div>
     <script src="js/cursorEffects.js"></script>
     <script type="text/javascript">
         new cursoreffects.bubbleCursor();

+ 22 - 12
js/chem.js

@@ -115,7 +115,7 @@ function weigh(hash, mode = 0) {
             if (weighList[key]) ans += hash[key] * weighList[key]
         }
     }
-    return eps(ans,mode);
+    return eps(ans, mode);
 }
 function weighEquation(str, mode = 0) {
     str = str.replace(/<\d*e[\+\-]>*/g, "").replace(/[^\dA-Za-z<>\(\)\+\-=\.;]/g, "");
@@ -127,10 +127,10 @@ function weighEquation(str, mode = 0) {
     for (let i = 0; i <= n; i++) {
         var k = weigh(parseMolecule(q[i]), mode)
         sum += k
-        if (p.charAt(i) == '=') gsum += eps(sum,mode) + '=', sum = 0;
+        if (p.charAt(i) == '=') gsum += eps(sum, mode) + '=', sum = 0;
         ans = ans + k + p.charAt(i)
     }
-    if (n) ans += '\\)<br>\\(' + gsum + eps(sum,mode)
+    if (n) ans += '<br>' + gsum + eps(sum, mode)
     return ans.replace(/\*/g, "\\cdot");
 }
 
@@ -152,16 +152,20 @@ function parseEquation(str) {
 
 function renderEquation(str) {
     str = str.replace(/[\[{]/g, "(").replace(/[\]}]/g, ")");
+    str=str.replace(/([\+\=\.;])\1+/g,'$1')
     str = str.replace(/[^\dA-Za-z<>\(\)\+\-=\.;]/g, "");
     // console.log('Rendering equation', str)
     str = str.replace(/([A-Za-z]+)/g, "\\text{$1}");
     str = str.replace(/<(\d*)\\text\{e\}([\+\-])>/g, "^{$1$2}");
     str = str.replace(/([\}\)])(\d+)/g, "$1_{$2}");
     str = str.replace(/\./g, "\\cdot");
+    str = "<a href='#'>\\(" + str.replace(/([\+\-=\.;])([^\}])/g, "\\)</a> \\($1\\) <a href='#'>\\($2") + '\\)</a>';
     // console.log(str)
     return str
 }
 
+//PROCESS-------------------------------
+
 var mode = 'bal', balInput, balText = '', inputText
 $().ready(function () {
     balInput = $("#balInput")[0]
@@ -174,7 +178,7 @@ $().ready(function () {
     $(function () { $("[data-toggle='tooltip']").tooltip(); });
 })
 function setBal() {
-    $('#frame')[0].innerHTML = '\\(' + renderEquation(balText) + '\\)';
+    $('#frame')[0].innerHTML = renderEquation(balText);
     MathJax.typeset()
     $('#balBtn').text('配平')
     $('#balShare').removeClass('disabled')
@@ -205,16 +209,16 @@ function setWeigh2() {
 function input() {
     inputText = balInput.value
     if (mode == 'bal') {
-        $('#frame')[0].innerHTML = '\\(' + renderEquation((inputText == '') ? 'CrI3+Cl2+KOH=K2CrO4+KIO4+KCl+H2O' : inputText) + '\\)<br>'
-            + '<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span><br>' + ((balText != '') ? ('\\(' + renderEquation(balText) + '\\)') : ('...'));
+        $('#frame')[0].innerHTML = renderEquation((inputText == '') ? 'CrI3+Cl2+KOH=K2CrO4+KIO4+KCl+H2O' : inputText) + '<br>'
+            + '<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span><br>' + ((balText != '') ? (renderEquation(balText)) : ('...'));
         MathJax.typeset()
     } else if (mode == 'weigh') {
-        $('#frame')[0].innerHTML = '\\(' + renderEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText) + '\\)<br>\\('
-            + weighEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText) + '\\)';
+        $('#frame')[0].innerHTML = renderEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText) + '<br>'
+            + weighEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText);
         MathJax.typeset()
     } else if (mode == 'weigh2') {
-        $('#frame')[0].innerHTML = '\\(' + renderEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText) + '\\)<br>\\('
-            + weighEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText, 1) + '\\)';
+        $('#frame')[0].innerHTML = renderEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText) + '<br>'
+            + weighEquation((inputText == '') ? 'CH3CHO+2Ag(NH3)2OH=CH3COONH4+2Ag+3NH3+H2O' : inputText, 1);
         MathJax.typeset()
     }
 }
@@ -226,8 +230,8 @@ function balance() {
     $('#frame').addClass('text-muted')
     running = 1;
     $.get('/chem?' + ((inputText == '') ? 'CrI3+Cl2+KOH=K2CrO4+KIO4+KCl+H2O' : inputText), function (e) {
-        $('#frame')[0].innerHTML = (e.charAt(0) == '!') ? ('<pre class="text-danger bg-danger">' + e.slice(1, e.length) + '</pre>') : ('\\(' + renderEquation((inputText == '') ? 'CrI3+Cl2+KOH=K2CrO4+KIO4+KCl+H2O' : inputText)
-            + '\\)<br><span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span><br>' + '\\(' + renderEquation(e) + '\\)');
+        $('#frame')[0].innerHTML = (e.charAt(0) == '!') ? ('<pre class="text-danger bg-danger">' + e.slice(1, e.length) + '</pre>') : (renderEquation((inputText == '') ? 'CrI3+Cl2+KOH=K2CrO4+KIO4+KCl+H2O' : inputText)
+            + '<br><span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span><br>' + renderEquation(e));
         if (e.charAt(0) != '!') balText = e
         MathJax.typeset()
         $('#balBtn').text('配平')
@@ -240,4 +244,10 @@ function balUp() {
     if (mode != 'bal') return;
     $('#balInput').val(balText);
     input()
+}
+
+//QUERY-------------------------------
+
+function qryUp() {
+    $('#qryInput').val($('#balInput').val());
 }