Browse Source

test local

schtonn 2 years ago
parent
commit
2842416a0a
10 changed files with 214 additions and 95 deletions
  1. 19 3
      chess/index.html
  2. 2 2
      crypty/index.html
  3. 1 4
      gravity/index.html
  4. 1 2
      index.html
  5. 84 68
      js/chess.js
  6. 3 6
      paint/index.html
  7. 4 3
      random/index.html
  8. 4 5
      score/index.html
  9. 1 2
      score/tutor/index.html
  10. 95 0
      test/index.html

+ 19 - 3
chess/index.html

@@ -4,8 +4,7 @@
 <head>
     <!-- <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
         integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
-    <link rel="stylesheet" href="../css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+    <link rel="stylesheet" href="../css/bootstrap.min.css" crossorigin="anonymous">
     <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
@@ -115,7 +114,7 @@
             filter: drop-shadow(0 0 5px white);
         }
 
-        .red:active{
+        .red:active {
             background: radial-gradient(transparent, rgb(15 15 15 / 25%));
         }
 
@@ -182,6 +181,21 @@
         .noshadow {
             text-shadow: none;
         }
+
+        input {
+            outline-style: none;
+            text-shadow: rgb(85, 85, 85) 3px 2px 4px;
+            border: 1px solid #ccc;
+            border-radius: 2px;
+            background: rgb(215 215 215 / 50%);
+        }
+        input:hover {
+            outline-style: none;
+            text-shadow: rgb(85, 85, 85) 3px 2px 4px;
+            border: 1px solid #ccc;
+            border-radius: 2px;
+            background: rgb(215 215 215 / 40%);
+        }
     </style>
 
     <script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
@@ -208,10 +222,12 @@
             <button class="btn btn-danger word message1">快</button>
             <button class="btn btn-danger word message2">再想想?</button>
             <button class="btn btn-danger word message3">拜拜</button>
+            <button class="btn btn-danger word message4"><input id="messageText"></button>
         </div>
         <div id="game" class="center-block">
             <span class="black pointer"></span>
         </div>
+        <div style="display:inline-block">在线人数:<p style="display: inline-block" class="curnum">0</p></div>
     </div>
     <script src="../js/chess.js"></script>
 </body>

+ 2 - 2
crypty/index.html

@@ -3,6 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
 
 <head>
+	<meta charset="UTF-8">
 	<title>crypty</title>
 	<script src="../js/jquery-1.7.2.js"></script>
 	<script src="../js/aes.js"></script>
@@ -11,8 +12,7 @@
 	<script src="../js/rc4.js"></script>
 	<!-- <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
         integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
-	<link rel="stylesheet" href="../css/bootstrap.min.css"
-		integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+	<link rel="stylesheet" href="../css/bootstrap.min.css" crossorigin="anonymous">
 	<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">

+ 1 - 4
gravity/index.html

@@ -3,10 +3,7 @@
 
 <head>
     <link rel="manifest" href="/site.webmanifest">
-    <!-- <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
-    <link rel="stylesheet" href="../css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+    <link rel="stylesheet" href="../css/bootstrap.min.css" crossorigin="anonymous">
     <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

+ 1 - 2
index.html

@@ -17,8 +17,7 @@
     <link rel="canonical" href="https://schtonn.github.io/">
     <!-- <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
         integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
-    <link rel="stylesheet" href="../css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+    <link rel="stylesheet" href="css/bootstrap.min.css" crossorigin="anonymous">
     <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">

+ 84 - 68
js/chess.js

@@ -1,9 +1,3 @@
-AV.init({
-    appId: "BmologYYnRqCv0SLHDeDdA17-gzGzoHsz",
-    appKey: "w9mVebFMdCmY6Nh9vfcBGaGt",
-    serverURL: "https://bmologyy.lc-cn-n1-shared.com",
-});
-
 $(window).on({
     contextmenu: function () {
         return false;
@@ -76,17 +70,19 @@ function updateMessages() {
     else $('.message2').removeClass("red");
     if (messages[2]) $('.message3').addClass("red");
     else $('.message3').removeClass("red");
+    if (messages[3]) $('.message4').addClass("red");
+    else $('.message4').removeClass("red");
+    $("#messageText")[0].value = messages[4];
 }
 
 var timer, st = 1;
 function uploadMessages() {
     timer && clearTimeout(timer);
-    timer = setTimeout(function () { st = 1; }, 500);
+    timer = setTimeout(function () { st = 1; }, 100);
     //FUUUULL BRiDGE RECtiFyer!!!
     if (st) {
         console.log('Messages updated.')
-        cur.set('messages', messages)
-        cur.save();
+        sendMessage()
     }
     st = 0;
 }
@@ -103,6 +99,7 @@ function updateCol() {
     }
 }
 
+
 class Chess {
     constructor(ele) {
         this.ele = ele;
@@ -170,6 +167,17 @@ class Chess {
             updateMessages();
             uploadMessages();
         })
+        $(".message4").on('click', function () {
+            messages[3] = !messages[3];
+            messages[4] = $("#messageText")[0].value;
+            updateMessages();
+            uploadMessages();
+        })
+        $("#messageText").on('input blur', function () {
+            messages[4] = $("#messageText")[0].value;
+            updateMessages();
+            uploadMessages();
+        })
     }
     render() {
         let div = $("<div id='xq-tips'>").appendTo($(this.ele))
@@ -225,8 +233,7 @@ class Chess {
                 // return;
             }
         })
-        cur.set('data', this.arr)
-        cur.save();
+        sendMessage(this.arr)
     }
     win() {
         let this_ = this;
@@ -275,8 +282,7 @@ class Chess {
         curCol = num % 2;
         updateCol();
         this.arr.pop();
-        cur.set('data', this.arr)
-        cur.save();
+        sendMessage(this.arr)
     }
     reset() {
         this.arr = [];
@@ -297,8 +303,7 @@ class Chess {
         $("#xq-tips").hide();
         $(".xq-txt").html("");
         $("#regret").show();
-        cur.set('data', this.arr)
-        cur.save();
+        sendMessage(this.arr)
     }
     check() {
         $(this.span).each((index, item) => {
@@ -309,65 +314,76 @@ class Chess {
         })
     }
 }
-var game;
+var game = new Chess($("#game"));
 
 checkCookie();
 
-const query = new AV.Query('chess');
-query.descending('updatedAt')
-query.limit(1)
-query.find().then((result) => {
-    $("#begin").hide();
-    $("#regret").show();
-    $("#agin").show();
-    $("#game").show();
-    if (result.length) {
-        console.log('Data loaded from LeanCloud')
-        cur = result[0]
-        var map = result[0].get('data')
-        messages = result[0].get('messages')
+var conversation = document.getElementById('conversation');
+var sendBtn = document.getElementById('sendBtn');
+var socket = null;
+var createSocket = function () {
+    if (socket) {
+        socket.close();
+    }
+    var url = 'ws://' + window.location.host + '/ws/chess';
+    socket = new WebSocket(url);
+    socket.onopen = function () {
+        console.log('connected to ' + url);
+    }
+    socket.onmessage = function (event) {
+        var map = JSON.parse(event.data).content;
+        messages = JSON.parse(event.data).message
+        console.log(messages)
         updateMessages();
+        game.reset();
+        game.arr = map;
+        game.upd();
+        curCol = map.length % 2;
         if (map.length) {
-            game = new Chess($("#game"));
-            game.arr = map;
-            game.upd();
-            updateCol();
+            game.win()
         } else {
-            game = new Chess($("#game"));
+            $('.pointer').removeClass("white");
+            $('.pointer').addClass("black");
+            checkCookie();
+            var exp = new Date();
+            exp.setTime(exp.getTime() - 1)
+            setCookie('color', myCol, exp)
+            myCol = 2;
+            $("#xq-tips").hide();
+            $(".xq-txt").html("");
+            $("#regret").show();
         }
+        console.log('Updated')
     }
-})
-
-setTimeout(function () {
-
-    query.subscribe().then((liveQuery) => {
-        console.log('Subscribed')
-        liveQuery.on('update', (result) => {
-            var map = result.get('data')
-            messages = result.get('messages')
-            updateMessages();
-            console.log('Updated')
-            game.reset();
-            game.arr = map;
-            game.upd();
-            curCol = map.length % 2;
-            if (map.length) {
-                game.win()
-            } else {
-                $('.pointer').removeClass("white");
-                $('.pointer').addClass("black");
-                checkCookie();
-                var exp = new Date();
-                exp.setTime(exp.getTime() - 1)
-                setCookie('color', myCol, exp)
-                myCol = 2;
-                $("#xq-tips").hide();
-                $(".xq-txt").html("");
-                $("#regret").show();
-            }
-        });
-    }, (error) => {
-        alert(error + "\n无法与服务器同步,请稍后再试")
-    });
+    socket.onclose = function () {
+        console.log('close connect to' + url);
+    }
+};
+var sendMessage = function (map = game.arr, msg = messages, type = '') {
+    var bd = JSON.stringify({
+        from: myCol,
+        content: map,
+        message: msg,
+        type: type
+    })
+    console.log(bd)
+    fetch('/chess/setboard', {
+        method: 'POST',
+        headers: {
+            'Content-type': 'application/json',
+        },
+        body: bd
+    }).then(res => {
+        return res.json();
+    })
+};
 
-}, 1000)
+createSocket();
+checkCookie();
+game.upd();
+updateCol();
+updateMessages();
+$("#begin").hide();
+$("#regret").show();
+$("#agin").show();
+$("#game").show();

+ 3 - 6
paint/index.html

@@ -1,9 +1,7 @@
 <head>
+    <meta charset="UTF-8">
     <link rel="manifest" href="/site.webmanifest">
-    <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
-    <link rel="stylesheet" href="../css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+    <link rel="stylesheet" href="../css/bootstrap.min.css" crossorigin="anonymous">
     <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
@@ -208,8 +206,7 @@
 </head>
 
 <body>
-    <a class="btn btn-info" href="/"><span
-            class="glyphicon glyphicon-home" aria-hidden="true"></span>&nbsp;返回</a>
+    <a class="btn btn-info" href="/"><span class="glyphicon glyphicon-home" aria-hidden="true"></span>&nbsp;返回</a>
     <div id="main" style="text-align:center">
         <div id="draw"></div>
         <div id="tools">

+ 4 - 3
random/index.html

@@ -2,10 +2,10 @@
 <html lang="en">
 
 <head>
+    <meta charset="UTF-8">
     <!-- <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
         integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
-    <link rel="stylesheet" href="../css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+    <link rel="stylesheet" href="../css/bootstrap.min.css" crossorigin="anonymous">
     <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">
@@ -85,7 +85,8 @@
     <div class="bg">
         <div class="content">
             <a class="btn btn-default" href="/"><span class="glyphicon glyphicon-home" aria-hidden="true"></span></a>
-            <a class="btn btn-default" onclick="location.reload()"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></a>
+            <a class="btn btn-default" onclick="location.reload()"><span class="glyphicon glyphicon-refresh"
+                    aria-hidden="true"></span></a>
             <h1>> schtonn</h1>
         </div>
     </div>

+ 4 - 5
score/index.html

@@ -1,8 +1,6 @@
 <head>
-    <!-- <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
-    <link rel="stylesheet" href="../css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+    <meta charset="UTF-8">
+    <link rel="stylesheet" href="../css/bootstrap.min.css" crossorigin="anonymous">
     <script src="https://cdn.jsdelivr.net/npm/echarts@4.3.0/dist/echarts.min.js"></script>
     <script src="https://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
     <script src="../js/av-min.js"></script>
@@ -65,7 +63,8 @@
         <p>6. 此时应看到“{data: {,...”等数据,一定在数据第一行右键(或在其最后一行下方空白处右键),随后“<b>复制物体</b>”或“<b>Copy Object</b>”;</p>
         <p>7. 新建文本文档(格式为 txt,不可用 Word 文档),将所复制的内容粘贴并保存,于下方按钮打开。</p>
         <p style="font-size: 12px;font-style: italic;">
-            注:图表整理均在本地进行,你的成绩不会上传到网络。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>你获取的数据在心意答上未经加密并可直接访问,本质上对学生都是公开的,</del>(现在加密了,好在<a href="../crypty/">加密算法</a>不算复杂,不过各位且用且珍惜吧);但恶意使用这些数据造成的后果自负。
+            注:图表整理均在本地进行,你的成绩不会上传到网络。<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<del>你获取的数据在心意答上未经加密并可直接访问,本质上对学生都是公开的,</del>(现在加密了,好在<a
+                href="../crypty/">加密算法</a>不算复杂,不过各位且用且珍惜吧);但恶意使用这些数据造成的后果自负。
         </p>
         <h4>操作指南</h4>
         <p>1. 加载多个文件后,使用方向键、数字键或右下角控件可在文件间快速切换,方便比较;</p>

+ 1 - 2
score/tutor/index.html

@@ -1,8 +1,7 @@
 <head>
     <!-- <link async rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
         integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> -->
-    <link rel="stylesheet" href="../../css/bootstrap.min.css"
-        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
+    <link rel="stylesheet" href="../../css/bootstrap.min.css" crossorigin="anonymous">
     <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">

+ 95 - 0
test/index.html

@@ -0,0 +1,95 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+    <title>websocket demo</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+    <style>
+        .row {
+            margin: 1rem
+        }
+    </style>
+</head>
+
+<body>
+    <div class='row'>发送方:
+        <select id='sender'>
+            <option value="Bob" selected>Bob</option>
+            <option value="Alice">Alice</option>
+            <option value="Jack">Jack</option>
+        </select>
+    </div>
+    <div class='row'>接收方:
+        <select id='receiver'>
+            <option value="Bob">Bob</option>
+            <option value="Alice" selected>Alice</option>
+            <option value="Jack">Jack</option>
+        </select>
+    </div>
+    <textarea id='msg' class='row' rows="10" cols="30"></textarea>
+    <div class='row'>
+        <button id='sendBtn'>发送</button>
+    </div>
+    <h3 class='row'>收到的消息:</h3>
+    <div id='conversation' class='row'></div>
+    <script>
+        var sender = document.getElementById('sender');
+        var receiver = document.getElementById('receiver');
+        var conversation = document.getElementById('conversation');
+        var sendBtn = document.getElementById('sendBtn');
+        var socket = null;
+        var createSocket = function () {
+            if (socket) {
+                socket.close();
+            }
+            var url = 'ws://' + window.location.host + '/ws/' + sender.options[sender.selectedIndex].value;
+            socket = new WebSocket(url);
+            socket.onopen = function () {
+                console.log('connected to ' + url);
+            }
+            socket.onmessage = function (event) {
+                var data = JSON.parse(event.data);
+                conversation.innerHTML = conversation.innerHTML + data.from + ':' + data.content + '<br/>';
+            }
+            socket.onclose = function () {
+                console.log('close connect to' + url);
+            }
+        };
+        var sendMessage = function () {
+            var msg = document.getElementById('msg').value;
+            var bd=JSON.stringify({
+                from: sender.options[sender.selectedIndex].value,
+                content: msg,
+                to: receiver.options[receiver.selectedIndex].value
+            })
+            console.log(bd)
+            fetch('/rest/message', {
+                method: 'POST',
+                headers: {
+                    'Content-type': 'application/json',
+                },
+                body: bd
+            }).then(res => {
+                return res.json();
+            }).then(data => {
+                if (!data.succeed) {
+                    alert(data.msg);
+                }
+            })
+        };
+
+        sender.onchange = function () {
+            createSocket();
+        }
+
+        sendBtn.onclick = function () {
+            sendMessage();
+        }
+
+        createSocket();
+
+    </script>
+</body>
+
+</html>