-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
324 lines (324 loc) · 11.6 KB
/
main.js
File metadata and controls
324 lines (324 loc) · 11.6 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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// Generated by LiveScript 1.2.0
(function(){
var split$ = ''.split, replace$ = ''.replace;
$(function(){
var score, key, record, items, MAX, LoadedScripts, restart, grokHash, refreshSeen, refreshTotal;
score = 0;
key = '';
record = '';
items = [];
$('.hidden').hide();
MAX = 10;
$('#quit').click(function(){
$('.log-line:last').remove();
return $('#main').fadeOut(function(){
return $('#again').show();
});
});
$('#next').click(function(){
var reason, choice, row;
score++;
reason = $('#reason').val().replace(/[\n,]/g, ',');
choice = $('.choice.green').attr('id');
row = key + "," + choice + "," + reason + "\n";
switch (choice) {
case 'x':
$('.log-x:last').addClass('positive');
$('.log-y:last').addClass('negative');
break;
case 'y':
$('.log-x:last').addClass('negative');
$('.log-y:last').addClass('positive');
break;
case 'z':
$('.log-x:last').addClass('warning');
$('.log-y:last').addClass('warning');
break;
case 'w':
$('.log-x:last').addClass('active');
$('.log-y:last').addClass('active');
}
if (choice !== 'w') {
window.total++;
}
if (choice !== 'w') {
window.unique++;
}
refreshTotal();
$('.log-reason:last').text(reason);
$.ajax({
dataType: 'jsonp',
url: "https://www.moedict.tw/dodo/log/?log=" + encodeURIComponent(row) + "&offset=" + window.seen.length,
success: function(arg$){
var delta;
delta = arg$.delta;
return refreshSeen(window.seen + delta);
}
});
record += row;
$('#progress-text').text(score + " / " + MAX);
$('#progress-bar').css('width', score / MAX * 100 + "%");
if (score >= MAX) {
$('#main').fadeOut(function(){
return $('#again').show();
});
return;
}
return refresh();
});
LoadedScripts = {};
function getScript(src, cb){
if (LoadedScripts[src]) {
return cb();
}
LoadedScripts[src] = true;
return $.ajax({
type: 'GET',
url: src,
dataType: 'script',
cache: true,
crossDomain: true,
complete: cb
});
}
window.restart = restart = function(idx){
idx == null && (idx = '');
return window.location = document.URL.replace(/#.*$/, idx);
};
window.grokHash = grokHash = function(){
if (/^#(\d+)/.exec(location.hash)) {
refresh(RegExp.$1);
return true;
}
return false;
};
getScript('geili.js', function(){
var retry;
items = window.dodoData;
if (grokHash()) {
return;
}
return (retry = function(){
if (!window.total) {
return setTimeout(retry, 100);
}
return refresh();
})();
});
/*
getScript \data.js ->
items := window.dodo-data
getScript \oxynyms.js? ->
items ++= window.dodo-oxynyms
return if grok-hash!
do retry = ->
return setTimeout retry, 100ms unless window.total
refresh!
*/
refreshSeen = function(data){
var processed, i$, ref$, len$, line, key;
window.seen = data;
window.total = 0;
window.unique = 0;
processed = '\n';
for (i$ = 0, len$ = (ref$ = data.split(/[\r\n]/)).length; i$ < len$; ++i$) {
line = ref$[i$];
if (/^([^,]+,[^,]+),[xyz]/.exec(line)) {
key = RegExp.$1;
window.total++;
if (!~processed.indexOf(key)) {
window.unique++;
}
processed += key;
}
}
return refreshTotal();
};
$.get("https://www.moedict.tw/dodo/log.txt?_=" + Math.random(), refreshSeen);
refreshTotal = window.refreshTotal = function(){
var percent, text;
if (!items.length) {
return setTimeout(refreshTotal, 100);
}
if (window.total < items.length) {
percent = Math.floor(window.total / items.length * 1000) / 10;
text = "第一階段「初校」。目前進度:" + window.total + " / " + items.length + " (" + percent + "%)";
} else if (window.unique < items.length) {
percent = Math.floor(window.unique / items.length * 1000) / 10;
text = "第二階段「交叉比對」。目前進度:" + window.unique + " / " + items.length + " (" + percent + "%)";
} else {
percent = 100;
text = "所有的源資料和備註都已寄送至教育部,非常感謝大家熱心參與!(1990/1990)";
}
$('#total-bar').css('width', percent + "%");
if ($('#total-text').text()) {
return $('#total-text').text(text);
}
return setTimeout(function(){
return $('#total-text').hide().text(text).fadeIn('fast');
}, 500);
};
function pickItem(idx){
var result, hash, e;
idx || (idx = Math.floor(Math.random() * items.length));
result = (function(){
try {
return items[+idx];
} catch (e$) {}
}());
if (!result) {
return pickItem();
}
items[idx] = null;
hash = "#" + idx;
if (/^#(\d+)/.exec(location.hash) && location.hash + "" !== hash) {
try {
history.pushState(null, null, hash);
} catch (e$) {
e = e$;
location.replace(hash);
}
}
$('#idx').text("#" + idx).attr('href', "https://www.moedict.tw/dodo/#" + idx);
$('.share.button').each(function(){
return $(this).attr('href', $(this).data('href') + "%23" + idx);
});
return result + "\n" + idx;
}
function refresh(fixedIdx){
var ref$, book, xKey, x, yKey, y, idx, example, comma, i$, len$, chunk;
ref$ = split$.call(pickItem(fixedIdx), '\n'), book = ref$[0], xKey = ref$[1], x = ref$[2], yKey = ref$[3], y = ref$[4], idx = ref$[5];
key = xKey + "," + yKey;
/*
if not fixed-idx and ~window.seen.indexOf "\n#key,"
# Reroll with 99% certainty if it's judged before
# Reroll with 75% certainty if it's passed before
factor = if window.seen is //\n#key,[xyz]// then 100 else 4
return refresh! if Math.floor(Math.random! * factor)
*/
$('#book').text(book);
$('#x').html(x.replace(/`/g, '<b>').replace(/~/g, '</b>'));
$('#y').html(y.replace(/`/g, '<b>').replace(/~/g, '</b>'));
$('#x-key').text(xKey);
$('#y-key').text(yKey);
$('#x-key-link').attr({
href: "https://www.moedict.tw/#" + xKey,
target: '_blank'
});
$('#y-key-link').attr({
href: "https://www.moedict.tw/#" + yKey,
target: '_blank'
});
$('#log').append($('<tr/>', {
'class': 'log-line'
}).append($('<td/>', {
'class': 'book'
}).text(book).append($("<span><br></span>").append($('<a/>', {
'class': 'ui button mini key-link',
href: "#" + idx,
target: '_blank'
}).text("重做").prepend($("<i class='icon repeat'></i>")))), $('<td/>', {
'class': 'log-x'
}).html($('#x').html()).append($("<span><br></span>").append($('<a/>', {
'class': 'key-link',
href: "https://www.moedict.tw/#" + xKey,
target: '_blank'
}).text(xKey).prepend($("<i class='icon external url'></i>")))), $('<td/>', {
'class': 'log-y'
}).html($('#y').html()).append($("<span><br></span>").append($('<a/>', {
'class': 'key-link',
href: "https://www.moedict.tw/#" + yKey,
target: '_blank'
}).text(yKey).prepend($("<i class='icon external url'></i>")))), $('<td/>', {
'class': 'log-reason'
})));
$('.do-search').attr('target', '_blank');
if (/^「/.exec(book)) {
$('#key-links').show();
$('#chain-links').hide();
$('#type').text("引文用字");
$('.do-search.x').attr('href', "https://www.google.com.tw/#q=\"" + x.replace(/[`~「」]/g, '').replace(/﹍+/, '*') + "\"");
$('.do-search.y').attr('href', "https://www.google.com.tw/#q=\"" + y.replace(/[`~「」]/g, '').replace(/﹍+/, '*') + "\"");
$('#maybe-duplicate').hide();
$('#example').text('');
if (/\|/.exec(book)) {
example = book;
book = replace$.call(book, /\|.*/, '');
example = replace$.call(example, /.*\|/, '');
$('#book').text(book);
$('#example').text(replace$.call(example, /。$/, ''));
$('a.ui.mini.button.tag').hide();
$('#reason').attr('placeholder', '');
$('#next').addClass('disabled');
}
$('#x-key-link').attr({
href: "https://www.moedict.tw/~" + xKey,
target: '_blank'
});
} else if (book === '教育部重編國語辭典修訂本') {
$('#chain-links').text('');
comma = "";
for (i$ = 0, len$ = (ref$ = (replace$.call(y, /中.*/, '').replace(/的意思.*/, '').replace(/[「」]/g, '')).split('、')).length; i$ < len$; ++i$) {
chunk = ref$[i$];
$('#chain-links').append(comma).append($('<a/>', {
'class': 'key-link',
href: "https://www.moedict.tw/#" + chunk,
target: '_blank'
}).text("「" + chunk + "」").prepend($("<i class='icon external url'></i>")));
comma = '、';
}
$('#key-links').hide();
$('#chain-links').show();
$('#type').text("相似相反詞類");
$('.do-search.x').attr('href', "https://www.google.com.tw/#q=\"" + xKey + "\" \"" + yKey + "\" \"反義\"");
$('.do-search.y').attr('href', "https://www.google.com.tw/#q=\"" + xKey + "\" \"" + yKey + "\" \"同義\"");
} else {
$('#key-links').show();
$('#chain-links').hide();
$('#type').text("引文用字");
$('.do-search.x').attr('href', "https://www.google.com.tw/#q=\"" + x.replace(/[`~「」]/g, '') + "\"");
$('.do-search.y').attr('href', "https://www.google.com.tw/#q=\"" + y.replace(/[`~「」]/g, '') + "\"");
}
$('#reason').val('');
$('#proceed').fadeOut('fast');
$('#notice').fadeIn('fast');
$('.choice').removeClass('green');
return $('.choice').off('click').click(function(){
$('.choice').removeClass('green');
$(this).addClass('green');
if ($(this).attr('id') === 'w') {
$('#next').removeClass('disabled');
$('#reason').addClass('disabled');
$('#reason-field').css('visibility', 'visible');
$('#reason-prompt').text('我覺得:a.這是現在國語會用的動詞,但兩個都不可以填入名詞;或是b. 這是現在國語不會用的動詞。');
} else if ($(this).attr('id') === 'q') {
$('#next').removeClass('disabled');
$('#reason-field').css('visibility', 'hidden');
$('#reason-prompt').text('');
} else {
$('#reason-prompt').text('我覺得底線處可填入的名詞為:');
$('#reason').removeClass('disabled');
$('#reason-field').css('visibility', 'visible');
$('#reason').one('change', function(){
return $('#next').removeClass('disabled');
});
$('#reason').one('keydown', function(){
return $('#next').removeClass('disabled');
});
}
$('.tag').off('click').click(function(){
var this$ = this;
return $('#reason').val(function(){
return $('#reason').val() + "[" + $(this$).text() + "]";
});
});
return $('#notice').fadeOut('fast', function(){
return $('#proceed').fadeIn('fast', function(){
return $('#reason').focus();
});
});
});
}
return refresh;
});
}).call(this);