mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-09 11:13:26 +08:00
made code simpler and separated
This commit is contained in:
+110
-22
@@ -1,24 +1,112 @@
|
||||
/**
|
||||
* Copyright 2018, Google LLC
|
||||
* Licensed under the Apache License, Version 2.0 (the `License`);
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an `AS IS` BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var Typer={
|
||||
text: null,
|
||||
accessCountimer:null,
|
||||
index:0,
|
||||
speed:2,
|
||||
file:"",
|
||||
accessCount:0,
|
||||
deniedCount:0,
|
||||
init: function(){
|
||||
accessCountimer=setInterval(function(){Typer.updLstChr();},500);
|
||||
$.get(Typer.file,function(data){
|
||||
Typer.text=data;
|
||||
Typer.text = Typer.text.slice(0, Typer.text.length-1);
|
||||
});
|
||||
},
|
||||
|
||||
// [START gae_python37_log]
|
||||
'use strict';
|
||||
content:function(){
|
||||
return $("#console").html();
|
||||
},
|
||||
|
||||
write:function(str){
|
||||
$("#console").append(str);
|
||||
return false;
|
||||
},
|
||||
|
||||
addText:function(key){
|
||||
|
||||
if(key.keyCode==18){
|
||||
Typer.accessCount++;
|
||||
|
||||
if(Typer.accessCount>=3){
|
||||
Typer.makeAccess();
|
||||
}
|
||||
}
|
||||
|
||||
else if(key.keyCode==20){
|
||||
Typer.deniedCount++;
|
||||
|
||||
if(Typer.deniedCount>=3){
|
||||
Typer.makeDenied();
|
||||
}
|
||||
}
|
||||
|
||||
else if(key.keyCode==27){
|
||||
Typer.hidepop();
|
||||
}
|
||||
|
||||
else if(Typer.text){
|
||||
var cont=Typer.content();
|
||||
if(cont.substring(cont.length-1,cont.length)=="|")
|
||||
$("#console").html($("#console").html().substring(0,cont.length-1));
|
||||
if(key.keyCode!=8){
|
||||
Typer.index+=Typer.speed;
|
||||
}
|
||||
else {
|
||||
if(Typer.index>0)
|
||||
Typer.index-=Typer.speed;
|
||||
}
|
||||
var text=Typer.text.substring(0,Typer.index)
|
||||
var rtn= new RegExp("\n", "g");
|
||||
|
||||
$("#console").html(text.replace(rtn,"<br/>"));
|
||||
window.scrollBy(0,50);
|
||||
}
|
||||
|
||||
if (key.preventDefault && key.keyCode != 122) {
|
||||
key.preventDefault()
|
||||
};
|
||||
|
||||
if(key.keyCode != 122){ // otherway prevent keys default behavior
|
||||
key.returnValue = false;
|
||||
}
|
||||
},
|
||||
|
||||
updLstChr:function(){
|
||||
var cont=this.content();
|
||||
|
||||
if(cont.substring(cont.length-1,cont.length)=="|")
|
||||
$("#console").html($("#console").html().substring(0,cont.length-1));
|
||||
|
||||
else
|
||||
this.write("|"); // else write it
|
||||
}
|
||||
}
|
||||
|
||||
function replaceUrls(text) {
|
||||
var http = text.indexOf("http://");
|
||||
var space = text.indexOf(".me ", http);
|
||||
|
||||
if (space != -1) {
|
||||
var url = text.slice(http, space-1);
|
||||
return text.replace(url, "<a href=\"" + url + "\">" + url + "</a>");
|
||||
}
|
||||
|
||||
else {
|
||||
return text
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', function () {
|
||||
|
||||
console.log("Hello World!");
|
||||
|
||||
});
|
||||
// [END gae_python37_log]
|
||||
Typer.speed=1;
|
||||
Typer.file="static/dungeondream.txt";
|
||||
Typer.init();
|
||||
|
||||
var timer = setInterval("t();", 30);
|
||||
function t() {
|
||||
Typer.addText({"keyCode": 123748});
|
||||
|
||||
if (Typer.index > Typer.text.length) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
<script type="text/javascript">
|
||||
var Typer={
|
||||
text: null,
|
||||
accessCountimer:null,
|
||||
index:0, // current cursor position
|
||||
speed:2, // speed of the Typer
|
||||
file:"", //file, must be setted
|
||||
accessCount:0, //times alt is pressed for Access Granted
|
||||
deniedCount:0, //times caps is pressed for Access Denied
|
||||
init: function(){// inizialize Hacker Typer
|
||||
accessCountimer=setInterval(function(){Typer.updLstChr();},500); // inizialize timer for blinking cursor
|
||||
$.get(Typer.file,function(data){// get the text file
|
||||
Typer.text=data;// save the textfile in Typer.text
|
||||
Typer.text = Typer.text.slice(0, Typer.text.length-1);
|
||||
});
|
||||
},
|
||||
|
||||
content:function(){
|
||||
return $("#console").html();// get console content
|
||||
},
|
||||
|
||||
write:function(str){// append to console content
|
||||
$("#console").append(str);
|
||||
return false;
|
||||
},
|
||||
|
||||
makeAccess:function(){//create Access Granted popUp FIXME: popup is on top of the page and doesn't show is the page is scrolled
|
||||
Typer.hidepop(); // hide all popups
|
||||
Typer.accessCount=0; //reset count
|
||||
var ddiv=$("<div id='gran'>").html(""); // create new blank div and id "gran"
|
||||
ddiv.addClass("accessGranted"); // add class to the div
|
||||
ddiv.html("<h1>ACCESS GRANTED</h1>"); // set content of div
|
||||
$(document.body).prepend(ddiv); // prepend div to body
|
||||
return false;
|
||||
},
|
||||
makeDenied:function(){//create Access Denied popUp FIXME: popup is on top of the page and doesn't show is the page is scrolled
|
||||
Typer.hidepop(); // hide all popups
|
||||
Typer.deniedCount=0; //reset count
|
||||
var ddiv=$("<div id='deni'>").html(""); // create new blank div and id "deni"
|
||||
ddiv.addClass("accessDenied");// add class to the div
|
||||
ddiv.html("<h1>ACCESS DENIED</h1>");// set content of div
|
||||
$(document.body).prepend(ddiv);// prepend div to body
|
||||
return false;
|
||||
},
|
||||
|
||||
hidepop:function(){// remove all existing popups
|
||||
$("#deni").remove();
|
||||
$("#gran").remove();
|
||||
},
|
||||
|
||||
addText:function(key){//Main function to add the code
|
||||
if(key.keyCode==18){// key 18 = alt key
|
||||
Typer.accessCount++; //increase counter
|
||||
if(Typer.accessCount>=3){// if it's presed 3 times
|
||||
Typer.makeAccess(); // make access popup
|
||||
}
|
||||
}else if(key.keyCode==20){// key 20 = caps lock
|
||||
Typer.deniedCount++; // increase counter
|
||||
if(Typer.deniedCount>=3){ // if it's pressed 3 times
|
||||
Typer.makeDenied(); // make denied popup
|
||||
}
|
||||
}else if(key.keyCode==27){ // key 27 = esc key
|
||||
Typer.hidepop(); // hide all popups
|
||||
}else if(Typer.text){ // otherway if text is loaded
|
||||
var cont=Typer.content(); // get the console content
|
||||
if(cont.substring(cont.length-1,cont.length)=="|") // if the last char is the blinking cursor
|
||||
$("#console").html($("#console").html().substring(0,cont.length-1)); // remove it before adding the text
|
||||
if(key.keyCode!=8){ // if key is not backspace
|
||||
Typer.index+=Typer.speed; // add to the index the speed
|
||||
}else{
|
||||
if(Typer.index>0) // else if index is not less than 0
|
||||
Typer.index-=Typer.speed;// remove speed for deleting text
|
||||
}
|
||||
var text=Typer.text.substring(0,Typer.index)// parse the text for stripping html enities
|
||||
var rtn= new RegExp("\n", "g"); // newline regex
|
||||
|
||||
$("#console").html(text.replace(rtn,"<br/>"));// replace newline chars with br, tabs with 4 space and blanks with an html blank
|
||||
window.scrollBy(0,50); // scroll to make sure bottom is always visible
|
||||
}
|
||||
if ( key.preventDefault && key.keyCode != 122 ) { // prevent F11(fullscreen) from being blocked
|
||||
key.preventDefault()
|
||||
};
|
||||
if(key.keyCode != 122){ // otherway prevent keys default behavior
|
||||
key.returnValue = false;
|
||||
}
|
||||
},
|
||||
|
||||
updLstChr:function(){ // blinking cursor
|
||||
var cont=this.content(); // get console
|
||||
if(cont.substring(cont.length-1,cont.length)=="|") // if last char is the cursor
|
||||
$("#console").html($("#console").html().substring(0,cont.length-1)); // remove it
|
||||
else
|
||||
this.write("|"); // else write it
|
||||
}
|
||||
}
|
||||
|
||||
function replaceUrls(text) {
|
||||
var http = text.indexOf("http://");
|
||||
var space = text.indexOf(".me ", http);
|
||||
if (space != -1) {
|
||||
var url = text.slice(http, space-1);
|
||||
return text.replace(url, "<a href=\"" + url + "\">" + url + "</a>");
|
||||
} else {
|
||||
return text
|
||||
}
|
||||
}
|
||||
Typer.speed=3;
|
||||
Typer.file="static/dungeondream.txt";
|
||||
Typer.init();
|
||||
|
||||
var timer = setInterval("t();", 30);
|
||||
function t() {
|
||||
Typer.addText({"keyCode": 123748});
|
||||
if (Typer.index > Typer.text.length) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
// request_story("Hello")
|
||||
|
||||
function request_story(prompt, callback){
|
||||
$.post("/generate", { story_block: true, prompt},
|
||||
function(data){
|
||||
alert(data)
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
<div id="console"></div>
|
||||
<script type="text/javascript">
|
||||
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-610661-7']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
|
||||
</script>
|
||||
+42
-2
@@ -1,4 +1,44 @@
|
||||
body {
|
||||
font-family: "helvetica", sans-serif;
|
||||
text-align: center;
|
||||
background-color: #000
|
||||
}
|
||||
|
||||
#console {
|
||||
font-family: courier, monospace;
|
||||
color: #fff;
|
||||
width:750px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
margin-top:100px;
|
||||
font-size:14px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #0bc;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#a {
|
||||
color: #0f0;
|
||||
}
|
||||
|
||||
#c {
|
||||
color: #0bc;
|
||||
}
|
||||
|
||||
#b {
|
||||
color: #ff0096;
|
||||
}
|
||||
|
||||
#k {
|
||||
animation: change 1s;
|
||||
}
|
||||
|
||||
#op{
|
||||
color: #888888
|
||||
}
|
||||
|
||||
@keyframes change {
|
||||
0% { color: #0f0; }
|
||||
50% { color: #0f0; }
|
||||
99% { color: black; }
|
||||
}
|
||||
|
||||
+14
-198
@@ -1,199 +1,15 @@
|
||||
<!--
|
||||
Copyright (c) 2011 Sam Phippen <samphippen@googlemail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Dungeon Dream</title>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-color: #000
|
||||
}
|
||||
#console {
|
||||
font-family: courier, monospace;
|
||||
color: #fff;
|
||||
width:750px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
margin-top:100px;
|
||||
font-size:14px;
|
||||
}
|
||||
a {
|
||||
color: #0bc;
|
||||
text-decoration: none;
|
||||
}
|
||||
#a {
|
||||
color: #0f0;
|
||||
}
|
||||
#c {
|
||||
color: #0bc;
|
||||
}
|
||||
#b {
|
||||
color: #ff0096;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
var Typer={
|
||||
text: null,
|
||||
accessCountimer:null,
|
||||
index:0, // current cursor position
|
||||
speed:2, // speed of the Typer
|
||||
file:"", //file, must be setted
|
||||
accessCount:0, //times alt is pressed for Access Granted
|
||||
deniedCount:0, //times caps is pressed for Access Denied
|
||||
init: function(){// inizialize Hacker Typer
|
||||
accessCountimer=setInterval(function(){Typer.updLstChr();},500); // inizialize timer for blinking cursor
|
||||
$.get(Typer.file,function(data){// get the text file
|
||||
Typer.text=data;// save the textfile in Typer.text
|
||||
Typer.text = Typer.text.slice(0, Typer.text.length-1);
|
||||
});
|
||||
},
|
||||
|
||||
content:function(){
|
||||
return $("#console").html();// get console content
|
||||
},
|
||||
|
||||
write:function(str){// append to console content
|
||||
$("#console").append(str);
|
||||
return false;
|
||||
},
|
||||
|
||||
makeAccess:function(){//create Access Granted popUp FIXME: popup is on top of the page and doesn't show is the page is scrolled
|
||||
Typer.hidepop(); // hide all popups
|
||||
Typer.accessCount=0; //reset count
|
||||
var ddiv=$("<div id='gran'>").html(""); // create new blank div and id "gran"
|
||||
ddiv.addClass("accessGranted"); // add class to the div
|
||||
ddiv.html("<h1>ACCESS GRANTED</h1>"); // set content of div
|
||||
$(document.body).prepend(ddiv); // prepend div to body
|
||||
return false;
|
||||
},
|
||||
makeDenied:function(){//create Access Denied popUp FIXME: popup is on top of the page and doesn't show is the page is scrolled
|
||||
Typer.hidepop(); // hide all popups
|
||||
Typer.deniedCount=0; //reset count
|
||||
var ddiv=$("<div id='deni'>").html(""); // create new blank div and id "deni"
|
||||
ddiv.addClass("accessDenied");// add class to the div
|
||||
ddiv.html("<h1>ACCESS DENIED</h1>");// set content of div
|
||||
$(document.body).prepend(ddiv);// prepend div to body
|
||||
return false;
|
||||
},
|
||||
|
||||
hidepop:function(){// remove all existing popups
|
||||
$("#deni").remove();
|
||||
$("#gran").remove();
|
||||
},
|
||||
|
||||
addText:function(key){//Main function to add the code
|
||||
if(key.keyCode==18){// key 18 = alt key
|
||||
Typer.accessCount++; //increase counter
|
||||
if(Typer.accessCount>=3){// if it's presed 3 times
|
||||
Typer.makeAccess(); // make access popup
|
||||
}
|
||||
}else if(key.keyCode==20){// key 20 = caps lock
|
||||
Typer.deniedCount++; // increase counter
|
||||
if(Typer.deniedCount>=3){ // if it's pressed 3 times
|
||||
Typer.makeDenied(); // make denied popup
|
||||
}
|
||||
}else if(key.keyCode==27){ // key 27 = esc key
|
||||
Typer.hidepop(); // hide all popups
|
||||
}else if(Typer.text){ // otherway if text is loaded
|
||||
var cont=Typer.content(); // get the console content
|
||||
if(cont.substring(cont.length-1,cont.length)=="|") // if the last char is the blinking cursor
|
||||
$("#console").html($("#console").html().substring(0,cont.length-1)); // remove it before adding the text
|
||||
if(key.keyCode!=8){ // if key is not backspace
|
||||
Typer.index+=Typer.speed; // add to the index the speed
|
||||
}else{
|
||||
if(Typer.index>0) // else if index is not less than 0
|
||||
Typer.index-=Typer.speed;// remove speed for deleting text
|
||||
}
|
||||
var text=Typer.text.substring(0,Typer.index)// parse the text for stripping html enities
|
||||
var rtn= new RegExp("\n", "g"); // newline regex
|
||||
|
||||
$("#console").html(text.replace(rtn,"<br/>"));// replace newline chars with br, tabs with 4 space and blanks with an html blank
|
||||
window.scrollBy(0,50); // scroll to make sure bottom is always visible
|
||||
}
|
||||
if ( key.preventDefault && key.keyCode != 122 ) { // prevent F11(fullscreen) from being blocked
|
||||
key.preventDefault()
|
||||
};
|
||||
if(key.keyCode != 122){ // otherway prevent keys default behavior
|
||||
key.returnValue = false;
|
||||
}
|
||||
},
|
||||
|
||||
updLstChr:function(){ // blinking cursor
|
||||
var cont=this.content(); // get console
|
||||
if(cont.substring(cont.length-1,cont.length)=="|") // if last char is the cursor
|
||||
$("#console").html($("#console").html().substring(0,cont.length-1)); // remove it
|
||||
else
|
||||
this.write("|"); // else write it
|
||||
}
|
||||
}
|
||||
|
||||
function replaceUrls(text) {
|
||||
var http = text.indexOf("http://");
|
||||
var space = text.indexOf(".me ", http);
|
||||
if (space != -1) {
|
||||
var url = text.slice(http, space-1);
|
||||
return text.replace(url, "<a href=\"" + url + "\">" + url + "</a>");
|
||||
} else {
|
||||
return text
|
||||
}
|
||||
}
|
||||
Typer.speed=3;
|
||||
Typer.file="static/dungeondream.txt";
|
||||
Typer.init();
|
||||
|
||||
var timer = setInterval("t();", 30);
|
||||
function t() {
|
||||
Typer.addText({"keyCode": 123748});
|
||||
if (Typer.index > Typer.text.length) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
// request_story("Hello")
|
||||
|
||||
function request_story(prompt, callback){
|
||||
$.post("/generate", { story_block: true, prompt},
|
||||
function(data){
|
||||
alert(data)
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
<div id="console"></div>
|
||||
<script type="text/javascript">
|
||||
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-610661-7']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dungeon</title>
|
||||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript" src="static/script.js">
|
||||
</script>
|
||||
<div id="console"></div>
|
||||
<script type="text/javascript", src="static/script2.js">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user