-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
89 lines (80 loc) · 3.2 KB
/
functions.js
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
var myDataRef = new Firebase('https://fiery-torch-7339.firebaseio.com/');
var textDict = {}
// $('#annotation').keypress(function (e) {
// if (e.keyCode == 13) {
// var name = $('#annotation').val();
// var text = $('#emojicode').val();
// myDataRef.push({name: name, text: text});
// $('#annotation').val('');
// }
// });
myDataRef.on("value", function(snapshot) {
console.log(snapshot.val());
textDict = snapshot.val()
});
function printCaps()
{
var textstr = document.myform.text.value;
var res = textstr.split(" ");
var translate = []
var translate_alt = []
var tempList = []
for (var word in res)
{
var translate_all = []
found = false
for (var key in textDict) {
tempList = textDict[key]
for (var value in tempList) {
//console.log(tempList[value])
if (res[word].toLowerCase() === tempList[value])
{
console.log(res[word] === tempList[value])
translate_all.push(key)
//translate_all.push('<img class="emoji" draggable="false" src="images/' + key + '_apple.png">') //append key
found = true
}
}
}
if (!found)
{
translate.push(res[word])
translate_alt.push(res[word])
} else {
console.log(translate_all)
var rand_element = translate_all[Math.floor(Math.random()*translate_all.length)]
translate.push('<img class="emoji" draggable="false" src="images/' + rand_element + '_apple.png">')
intList = textDict[rand_element][0]
integer_List = intList.split('_')
if (integer_List.length === 1) {
translate_alt.push(String.fromCharCode(parseInt(integer_List[0])));
} else {
translate_alt.push(String.fromCharCode(parseInt(integer_List[0]),parseInt(integer_List[1])));
}
}
}
console.log(translate)
var toSend = String(translate.join(" "));
document.getElementById('result').innerHTML = toSend;
console.log(translate_alt)
return translate_alt
}
function myFacebookLogin() {
FB.login(function(){
// Note: The call will only work if you accept the permission request
intList = printCaps();
FB.api('/me/feed', 'post', {message: String(intList.join(" "))});
}, {scope: 'publish_actions'});}
function temp_function() {
intList = printCaps();
alert(String(intList.join(" ")));
}
// function getRandomImage() {
// num = Math.floor(Math.random() * (1281 - 1) + 1);
// console.log(num)
// keys = Object.keys(textDict)
// console.log(keys)
// str = "images/" + keys[num] + "_apple.png"
// console.log(str)
// return str
// }