From 9b97c9b516d0f63634e7ed24659989b8c86598a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=95=96=E6=AD=A6?= Date: Mon, 9 Sep 2019 12:44:44 +0800 Subject: [PATCH] Revert "Chinese pinyin search support" This reverts commit ddd3c1ac --- app.html | 2 - app.js | 40 +--- lib/chinese/pinyinUtil.js | 372 ------------------------------ lib/chinese/pinyin_dict_notone.js | 4 - 4 files changed, 7 insertions(+), 411 deletions(-) delete mode 100644 lib/chinese/pinyinUtil.js delete mode 100644 lib/chinese/pinyin_dict_notone.js diff --git a/app.html b/app.html index ef63bdd..825073e 100644 --- a/app.html +++ b/app.html @@ -102,8 +102,6 @@

What's New

- - diff --git a/app.js b/app.js index ab86b55..d7d6715 100644 --- a/app.js +++ b/app.js @@ -33,37 +33,16 @@ document.addEventListener("DOMContentLoaded", function() { }); function highlight(text, textToHighlight) { - if (textToHighlight.length > 0) { - var keywords = [getChineseKeyWordsByPinyin(text,textToHighlight)].concat(textToHighlight).filter(function(str){ - return str != null && str.trim() != ''; - }); - console.info('keywords is ',keywords) - var regex = new RegExp(keywords.join('|'),'g') - console.info('regex and text is ',regex,text) - return text.toLowerCase() - .replace(regex,function(kw){ - return "" + kw + "" - }) - } + if (textToHighlight.length > 0) + return text + .toLowerCase() + .replace( + textToHighlight, + "" + textToHighlight + "" + ); else return text; } - function getChineseKeyWordsByPinyin(text,pinyin){ - var chars = text.split(''); - var pinyins = chars.map(function(char){ - return pinyinUtil.getPinyin(char); - }) - var keywords = []; - for(var i = 0;i= 0 && _char != _pinyin && _char.trim() != ''){ - keywords.push(_char); - } - } - return keywords.join(''); - } - /** * removes the dom element and the corresponding tab from the browser * @param tabElement - DOM element from the list containing data-id attributes @@ -243,11 +222,6 @@ document.addEventListener("DOMContentLoaded", function() { .indexOf(searchInput.value.trim().toLowerCase()) == -1 && tab.url .toLowerCase() - .indexOf(searchInput.value.trim().toLowerCase()) == -1 && - - // chinese search - pinyinUtil.getPinyin(tab.title) - .replace(/\W/g,'') .indexOf(searchInput.value.trim().toLowerCase()) == -1 ) { continue; diff --git a/lib/chinese/pinyinUtil.js b/lib/chinese/pinyinUtil.js deleted file mode 100644 index 85c787f..0000000 --- a/lib/chinese/pinyinUtil.js +++ /dev/null @@ -1,372 +0,0 @@ - -/** - * 汉字与拼音互转工具,根据导入的字典文件的不同支持不同 - * 对于多音字目前只是将所有可能的组合输出,准确识别多音字需要完善的词库,而词库文件往往比字库还要大,所以不太适合web环境。 - * @start 2016-09-26 - * @last 2016-09-29 - */ -;(function(global, factory) { - if (typeof module === "object" && typeof module.exports === "object") { - module.exports = factory(global); - } else { - factory(global); - } -})(typeof window !== "undefined" ? window : this, function(window) { - - var toneMap = - { - "ā": "a1", - "á": "a2", - "ǎ": "a3", - "à": "a4", - "ō": "o1", - "ó": "o2", - "ǒ": "o3", - "ò": "o4", - "ē": "e1", - "é": "e2", - "ě": "e3", - "è": "e4", - "ī": "i1", - "í": "i2", - "ǐ": "i3", - "ì": "i4", - "ū": "u1", - "ú": "u2", - "ǔ": "u3", - "ù": "u4", - "ü": "v0", - "ǖ": "v1", - "ǘ": "v2", - "ǚ": "v3", - "ǜ": "v4", - "ń": "n2", - "ň": "n3", - "": "m2" - }; - - var dict = {}; // 存储所有字典数据 - var pinyinUtil = - { - /** - * 解析各种字典文件,所需的字典文件必须在本JS之前导入 - */ - parseDict: function() - { - // 如果导入了 pinyin_dict_firstletter.js - if(window.pinyin_dict_firstletter) - { - dict.firstletter = pinyin_dict_firstletter; - } - // 如果导入了 pinyin_dict_notone.js - if(window.pinyin_dict_notone) - { - dict.notone = {}; - dict.py2hz = pinyin_dict_notone; // 拼音转汉字 - for(var i in pinyin_dict_notone) - { - var temp = pinyin_dict_notone[i]; - for(var j=0, len=temp.length; j 汉字 - if(window.pinyin_dict_notone) - { - // 对于拼音转汉字,我们优先使用pinyin_dict_notone字典文件 - // 因为这个字典文件不包含生僻字,且已按照汉字使用频率排序 - dict.py2hz = pinyin_dict_notone; // 拼音转汉字 - } - else - { - // 将字典文件解析成拼音->汉字的结构 - // 与先分割后逐个去掉声调相比,先一次性全部去掉声调然后再分割速度至少快了3倍,前者大约需要120毫秒,后者大约只需要30毫秒(Chrome下) - var notone = pinyinUtil.removeTone(pinyin_dict_withtone).split(','); - var py2hz = {}, py, hz; - for(var i=0, len = notone.length; i= 19968 && unicode <= 40869) - { - ch = dict.firstletter.all.charAt(unicode-19968); - if(polyphone) ch = dict.firstletter.polyphone[unicode] || ch; - } - result.push(ch); - } - if(!polyphone) return result.join(''); // 如果不用管多音字,直接将数组拼接成字符串 - else return handlePolyphone(result, '', ''); // 处理多音字,此时的result类似于:['D', 'ZC', 'F'] - } - else - { - var py = this.getPinyin(str, ' ', false, polyphone); - py = py instanceof Array ? py : [py]; - var result = []; - for(var i=0; i