Add new language specified script
[platform/core/uifw/vc-webview-js.git] / js / vc-webview-zh_HK.js
1 /**
2  *   Copyright 2017 Samsung Electronics Co., Ltd.
3  *
4  *   Licensed under the Flora License, Version 1.1 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at
7  *
8  *       http://floralicense.org/license/
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  */
16
17 /**
18  * vc-webview-zh_HK.js
19  *
20  *  This source code is a language specified script for Chinese(zh_HK).
21  */
22
23 /**
24  * vc_search_word function found the text with similarity calculated using words in the @param.
25  *
26  * @param param  param from voice-control.
27  * @param replace  If replace true, function correct some confused charaters and try again.
28  */
29 function vc_search_word(param, replace) {
30         /* phase 2. search partial word in the webpage */
31         /* First, compare with links in html documents */
32         if (vc_flag_log == true) {
33                 vc_rec_result.style.background = 'rgba(0, 100, 200, 1)';
34         }
35         var resultTokenArr = param.replace(/ /gi, '');
36         var threshold = resultTokenArr.length * 0.6;
37         var temp = [];
38         var el = undefined;
39
40         vc_print_log('=== start vc_search_word');
41
42         for (var i = 0; i < vc_text_indicators.length; ++i) {
43                 var text = vc_text_indicators[i].textContent.replace(/[ `~!‘’@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '').toLowerCase();
44                 temp[i] = 0;
45
46                 for (var j = 0; j < resultTokenArr.length; j++) {
47                         if (vc_is_visible(vc_text_indicators[i], vc_scr, true) && text.indexOf(resultTokenArr[j].toLowerCase()) != -1) {
48                                 temp[i]++;
49                         }
50                 }
51         }
52
53         var max = -1;
54
55         for (var i = 0; i < vc_text_indicators.length; i++) {
56                 if (temp[i] >= threshold && (max == -1 || temp[i] > temp[max])) {
57                         el = vc_text_indicators[i];
58                         max = i;
59                 }
60         }
61
62         if (el != undefined) {
63                 return el;
64         }
65
66         /* Second, compare with whole text of elements in html documents */
67         var result = [];
68         for (var i = 0; i < resultTokenArr.length; i++) {
69                 var obj = vc_selector([resultTokenArr[i]]);
70                 for (var j = 0; j < obj.length; j++) {
71                         temp = obj[j];
72                         if (temp.childElementCount === 0) {
73                                 if (temp.hasAttribute('vc_count') == false) {
74                                         temp.setAttribute('vc_count', 1);
75                                         result.push(temp);
76                                 } else {
77                                         temp.setAttribute('vc_count', parseInt(temp.getAttribute('vc_count')) + 1);
78                                 }
79                         }
80                 }
81         }
82
83         for (var i = 0; i < result.length; i++) {
84                 var vccnt = parseInt(result[i].getAttribute('vc_count'));
85                 if (vccnt >= threshold && (el == undefined || vccnt > parseInt(el.getAttribute('vc_count')))) {
86                         el = result[i];
87                 }
88         }
89
90         for (var i = 0; i < result.length; i++) {
91                 result[i].removeAttribute('vc_count');
92         }
93
94         return el;
95 }
96
97 /**
98  * vc_search_word function found the text with similarity calculated using characters in the @param.
99  *
100  * @param param  param from voice-control.
101  */
102 function vc_search_character(param) {
103         var el = undefined;
104
105         /* TODO: Fill the logic here to find the link or text include the character keys in param.
106          * If you find the link or text, then allocate that into el.
107          * If the language does not need to pronunciation comapring, you can erase this function.
108          */
109
110         return el;
111 }
112
113 /**
114  * vc_search_word function found the text with similarity calculated using pronunciation keys in the @param.
115  *
116  * @param param  param from voice-control.
117  */
118 function vc_search_pronunciation(param) {
119         var el = undefined;
120
121         /* TODO: Fill the logic here to find the link or text include the pronunciation keys in param.
122          * If you find the link or text, then allocate that into el.
123          * If the language does not need to pronunciation comapring, you can erase this function.
124          */
125
126         return el;
127 }
128
129 /**
130  * vc_is_included_number function separate a number value from the @text.
131  *
132  * @param text  text string from voice-control-webview.cpp.
133  */
134 function vc_is_included_number(text) {
135         var numbers = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十',
136                 '十一', '十二', '十三', '十四', '十五', '十六', '十七', '十八', '十九', '二十',
137                 '二十一', '二十二', '二十三', '二十四', '二十五', '二十六', '二十七', '二十八', '二十九', '三十',
138                 '三十一', '三十二', '三十三', '三十四', '三十五', '三十六', '三十七', '三十八', '三十九', '四十',
139                 '四十一', '四十二', '四十三', '四十四', '四十五', '四十六', '四十七', '四十八', '四十九', '五十',
140                 '五十一', '五十二', '五十三', '五十四', '五十五', '五十六', '五十七', '五十八', '五十九', '六十',
141                 '六十一', '六十二', '六十三', '六十四', '六十五', '六十六', '六十七', '六十八', '六十九', '七十',
142                 '七十一', '七十二', '七十三', '七十四', '七十五', '七十六', '七十七', '七十八', '七十九', '八十',
143                 '八十一', '八十二', '八十三', '八十四', '八十五', '八十六', '八十七', '八十八', '八十九', '九十',
144                 '九十一', '九十二', '九十三', '九十四', '九十五', '九十六', '九十七', '九十八', '九十九', '百'];
145         var convert = text.toLowerCase();
146         var result;
147
148         for (var i = 0; numbers.length > i; i++) {
149                 if (true == convert.startsWith(numbers[i]) && (' ' == text[numbers[i].length] || text.length == numbers[i].length)) {
150                         var partial = text.substr(numbers[i].length);
151
152                         if (vc_visible_hints[i].type == 'input' || text.length == numbers[i].length) {
153                                 result = {
154                                         cmd : (i + 1),
155                                         param : partial.trim()
156                                 };
157                                 return result;
158                         }
159                 }
160         }
161
162         result = {
163                 cmd : NaN,
164                 param : text.trim()
165         };
166
167         return result;
168 }
169
170 /**
171  * vc_correct_parameter function correct the voice recognition result.
172  *
173  * @param text  text string from voice-control-webview.cpp.
174  */
175 function vc_correct_parameter(text) {
176         var result = vc_is_included_number(text),
177         words = result.param.split(' ');
178
179         if (isNaN(result.cmd) == true && isNaN(words[0]) == false) {
180                 result.cmd = parseFloat(words[0]);
181                 result.param = result.param.substr(words[0].length + 1).trim();
182         }
183
184         return result
185 }
186
187 /**
188  * vc_check_web_control function check some special keyword and run it.
189  *
190  * @param spokenWord  voice recognized result string.
191  */
192 function vc_check_web_control(text) {
193         text = text.toLowerCase();
194         var convert = text.replace(/ /g, '');
195
196         if (convert == '刷新' || convert == '重新加载') {
197                 location.reload();
198         } else if (convert == '向下滚动' || convert == '向下滾動') {
199                 vc_scroll_event_firing('DOWN');
200         } else if (convert == '向上滚动' || convert == '向上滾動') {
201                 vc_scroll_event_firing('UP');
202         } else if (convert == '去顶部' || convert == '去頂部') {
203                 vc_scroll_event_firing('TOP');
204         } else if (convert == '源代碼' || convert == '源代码') {
205                 vc_print_html();
206         } else if (convert == '下一个' || convert == '下一個' || convert == '向前' || convert == '前进' || convert == '前進') {
207                 history.forward();
208         } else if (convert == '背部' || convert == '背部' || convert == '前' || convert == '以前') {
209                 history.back();
210         } else if ((convert == '记录' || convert == '記錄') && vc_flag_log) {
211                 if (vc_log_area.style.visibility == 'visible') vc_log_area.style.visibility = 'hidden';
212                 else vc_log_area.style.visibility = 'visible';
213         } else {
214                 return false;
215         }
216         return true;
217 }