-
Notifications
You must be signed in to change notification settings - Fork 1
/
password001.html
200 lines (174 loc) · 5.98 KB
/
password001.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<body>
<script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://dglittle.github.io/cdn/aes001.js"></script>
<script src="https://cdn.jsdelivr.net/ace/1.2.6/min/ace.js"></script>
<script src="https://cdn.jsdelivr.net/ace/1.2.6/min/ext-language_tools.js"></script>
<script src="https://dglittle.github.io/github-oauth/index.js"></script>
<script>
var x = aes_encrypt('blah', 'bloop')
console.log(x)
var y = aes_decrypt(x, 'bloop')
console.log(y)
// aes_encrypt = function (plaintext, password) {
// return Aes.Ctr.encrypt(plaintext, password, 256);
// }
// aes_decrypt = function (ciphertext, password) {
// return Aes.Ctr.decrypt(ciphertext, password, 256);
// }
define('ace/mode/example', function(require, exports, module) {
var oop = require("ace/lib/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var ExampleHighlightRules = require("ace/mode/example_highlight_rules").ExampleHighlightRules;
var Mode = function() {
this.HighlightRules = ExampleHighlightRules
};
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here. (see below)
}).call(Mode.prototype);
exports.Mode = Mode;
})
define('ace/mode/example_highlight_rules', function(require, exports, module) {
var oop = require("ace/lib/oop");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var ExampleHighlightRules = function() {
this.$rules = {
"start" : [{
token : ["asdf1", "asdf2"],
regex : '(:: *)(.*)'
}, {
token : ["asdf1", "asdf2"],
regex : '(password: *)(.*)'
}, {
token : "empty_line",
regex : '^$'
}, {
defaultToken : "text"
}]
};
}
oop.inherits(ExampleHighlightRules, TextHighlightRules);
exports.ExampleHighlightRules = ExampleHighlightRules;
})
var input = document.createElement('div')
input.id = 'input'
input.style.position = 'absolute'
input.style.top = '0px'
input.style.left = '0px'
input.style.width = '100%'
input.style.height = '100%'
document.body.appendChild(input)
ace.require('ace/ext/language_tools')
var editor = ace.edit('input')
editor.setTheme('ace/theme/monokai')
editor.renderer.setShowGutter(false)
editor.setShowPrintMargin(false)
editor.setShowFoldWidgets(false)
editor.setOptions({
fontFamily: 'Menlo,monospace',
fontSize: '9pt',
wrap: true,
enableBasicAutocompletion: true,
enableLiveAutocompletion: true
})
//editor.getSession().setMode('ace/mode/javascript')
editor.getSession().setMode("ace/mode/example")
var s = document.createElement('style')
s.innerHTML = '.ace-monokai .ace_asdf1 { color:grey; } .ace-monokai .ace_asdf2 { color:grey;background:grey; }'
document.head.append(s)
var save_notification = document.createElement('div')
save_notification.innerHTML = 'save me!'
save_notification.style.position = 'absolute'
save_notification.style.right = '0px'
save_notification.style.top = '0px'
save_notification.style.color = 'red'
save_notification.style.zIndex = 1000000
save_notification.style.display = 'none'
document.body.append(save_notification)
// db.child('pima_text').once('value', function (x) {
// editor.getSession().setValue(x.val() || '')
// var first = true
// editor.on('input', function () {
// if (first) { first = false; return }
// save_notification.innerHTML = 'save me!'
// save_notification.style.display = 'block'
// })
// })
// document.body.onkeydown = function (e) {
// if ((e.shiftKey || e.ctrlKey || e.metaKey) && ((e.keyCode == 83 && !e.shiftKey) || e.keyCode == 13)) {
// e.preventDefault()
// var x = editor.getSession().getValue()
// save_notification.innerHTML = 'saving...'
// db.child('pima_text').set(x, function () {
// save_notification.style.display = 'none'
// })
// }
// }
var pimaPassword = null
var access_token = null
var last_sha = null
function ensurePimaPassword(cb) {
if (pimaPassword) cb()
else {
pimaPassword = prompt('enter password')
cb()
}
}
function ensureAccessToken(cb) {
if (access_token) cb()
else github_oauth('repo', function (x) {
access_token = x
cb()
})
}
function openFile(cb) {
$.get('https://api.github.com/repos/dglittle/glittle.org/contents/pima_data.txt', function (x) {
last_sha = x.sha
cb(Base64.decode(x.content.replace(/\s/g, '')))
}).fail(function () {
last_sha = null
cb('')
})
}
function saveFile(text, cb) {
ensureAccessToken(function () {
$.ajax({
type : 'PUT',
url : 'https://api.github.com/repos/dglittle/glittle.org/contents/pima_data.txt?access_token=' + access_token,
data : JSON.stringify({
path : '/pima_data.txt',
message : 'my commit message',
content : Base64.encode(text),
sha : last_sha
}),
success : function (x) {
last_sha = x.content.sha
cb()
}
})
})
}
ensurePimaPassword(function () {
openFile(function (text) {
if (text) text = aes_decrypt(text, pimaPassword)
editor.getSession().setValue(text)
var first = true
editor.on('input', function () {
if (first) { first = false; return }
save_notification.innerHTML = 'save me!'
save_notification.style.display = 'block'
})
})
})
document.body.onkeydown = function (e) {
if ((e.shiftKey || e.ctrlKey || e.metaKey) && ((e.keyCode == 83 && !e.shiftKey) || e.keyCode == 13)) {
e.preventDefault()
save_notification.innerHTML = 'saving...'
saveFile(aes_encrypt(editor.getSession().getValue(), pimaPassword), function () {
save_notification.style.display = 'none'
})
}
}
</script>
</body>