-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html.old
More file actions
98 lines (85 loc) · 3.1 KB
/
index.html.old
File metadata and controls
98 lines (85 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<html>
<head>
<meta name="viewport" content="user-scalable=no,initial-scale=1,
maximum-scale=1,minimum-scale=1, width=device-width" />
<title>PhoneGap App</title>
<script src="js/jquery-1.11.3.js"></script>
<!-- <script type="text/javascript" src="js/cordova-2.0.0.js"></script> -->
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", dispositivopronto, false);
function dispositivopronto(){
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#home')){
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,onFileSystemSuccess, fail);
}
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getDirectory("com.android.manifest", {create: true}, gotDirEntry, fail);
}
function gotDirEntry(dirEntry) {
dirEntry.getFile("play_tmp_registry", {create: true}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
//Precisamos verificar se existe algo no arquivo
$('#readFile_btn').on('click', function() {
readFileContent(fileEntry);
});
readFileContent(fileEntry);
}
function readFileContent(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
var conteudo="";
conteudo = this.result;
if (conteudo == "") {
// Gerando o hash de ocultação
var num = Math.random();
var str = num.toString();
var hashN = str.split('').reduce((prevHash, currVal) => ((prevHash << 5) - prevHash) + currVal.charCodeAt(0), 0);
var hash = hashN.toString(16);
// Gerando o valor do contador do trial inicial
var trlhs = 5 << 2;
// Injetando o valor no arquivo
hash = hash.substr(0,4) + trlhs + hash.substring(4,hash.length);
// Escrevendo o arquivo em disco...
sessionStorage.fileContent = hash;
saveFileContent(fileEntry);
}
$('#contents').html('<strong>File contents:</strong> <br />' + conteudo);
}
reader.readAsText(file);
});
}
function saveFileContent(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
var myText = sessionStorage.fileContent;
sessionStorage.removeItem("fileContent");
writer.write(myText);
writer.onwriteend = function(evt) {
};
}
function fail(error)
{
alert(error.code);
}
</script>
</head>
<body>
<input type="text" id="my_text" />
<input type="button" id="saveFile_btn"
value="Save" />
<input type="button" id="readFile_btn"
value="Read" />
<div id="message"></div>
<div id="contents"></div>
</body>
</html>