<!doctype html>

<title>直播源修改插件-HFtalk</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="/code/doc/docs.css">
<link rel=stylesheet href="/code/doc/ziyong.css">
<link rel="stylesheet" href="/code/lib/codemirror.css">
<link rel="stylesheet" href="/code/addon/dialog/dialog.css">
<script src="/code/lib/codemirror.js"></script>
<script src="/code/addon/dialog/dialog.js"></script>
<script src="/code/addon/search/searchcursor.js"></script>
<script src="/code/mode/clike/clike.js"></script>
<script src="/code/addon/edit/matchbrackets.js"></script>
<script src="/code/keymap/vim.js"></script>
<article>
<body class='git-project'>
        <div class='twelve wide column'>
            <div class='git-project-content' id='git-project-content'>
                <div class='row column tree-holder' id='tree-holder'>
                    <div class='tree-content-holder' id='tree-content-holder'>
                        <div class='ui flat nopadding segment tree-content'>
                            <div class='git-project-recent-commit' id='git-project-info'>
                                <div class='recent-commit'>
                                    <h2 id="mulu">
                                        <img class="avatar circular ui image 20 mini" width="20" alt="" />
                                        修改在线直播源
                                    </h2>
                                </div>
                            </div>
                            <div class='recent-commit'>
                                <div class='row tree-item'>
                                    <div class='five wide column tree-item-file-name tree-list-item' style="width: 92%">
                                        <i class="iconfont icon-file"></i>
                                        <a id = "wangzhi" name = "{{filename}}">{{filename}}</a>

                                    </div>
                                    <span>
                                        <a onclick="Fanhui()"><i
                                                class='iconfont icon-commit'></i>
                                            返回
                                        </a>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</body>

<textarea id="code" name="code" type='text'>
{{text}}
</textarea>

<br>
<div>
<button type="button" onclick="tijiao()">修改提交</button>
</div>


  <div id="footer" style="text-align:center;">
    技术小白 BUG难免 介意勿用 ——韩风Talk <br><br>
    <a href="https://space.bilibili.com/472755599" target="_blank">
<img border="0" src="/code/doc/logos/Bilibili_logo.png" style="height: 20px;" />
</a>&emsp;&emsp;&emsp;
<a href="https://www.ixigua.com/home/106895204214" target="_blank">
<img border="0" src="/code/doc/logos/xigua.png" style="height: 20px;" />
</a>&emsp;&emsp;&emsp;
<a href="https://www.youtube.com/channel/UCNvrWFnraM8H1Zh8ASKyiqg" target="_blank">
<img border="0" src="/code/doc/logos/YouTube_Logo.png" style="height: 20px;" />
</a>
</div>

    <script>
    var hostName =  "http://" + location.hostname + ":" + location.port + "/";
	document.getElementById("wangzhi").innerHTML = hostName + document.getElementById("wangzhi").name; 	 
	 CodeMirror.commands.save = tijiao;	 
      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: true,
        mode: "text/x-csrc",
        matchBrackets: true,
        showCursorWhenSelecting: true
      });     
      var commandDisplay = document.getElementById('command-display');
      var keys = '';
      CodeMirror.on(editor, 'vim-keypress', function(key) {
        keys = keys + key;
        commandDisplay.innerText = keys;
      });
      CodeMirror.on(editor, 'vim-command-done', function(e) {
        keys = '';
        commandDisplay.innerHTML = keys;
      });
      var vimMode = document.getElementById('vim-mode');
      CodeMirror.on(editor, 'vim-mode-change', function(e) {
        vimMode.innerText = JSON.stringify(e);
      });
      
function Fanhui() {
	if (editor.getValue() == editor.getTextArea().value) {
		location.replace(hostName)
	} else {
		if (confirm("内容未保存，是否继续返回？")) {
			location.replace(hostName)
		}
	}
} 
	function tijiao(){    	 
	 if (editor.getValue() == editor.getTextArea().value){
	 alert("内容未更改");
	 }else{
	 if (confirm("确定更改？")){
	 editor.save();
	 result = editor.getTextArea().value;
	 var textValue = {"data":result,"name":"{{filename}}"};
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && xhttp.status == 200) {
      alert("保存成功");
      location.replace(hostName);}
	 };
	 xhttp.open("POST", "/submit", true);
      xhttp.setRequestHeader("Content-type", "application/json;charset=UTF-8");
      xhttp.send(JSON.stringify(textValue));
      }else{
	 };
	 }
	 }
    </script>
  </article>