Skip to content

Commit

Permalink
Revert "Chinese pinyin search support"
Browse files Browse the repository at this point in the history
This reverts commit ddd3c1a
  • Loading branch information
敖武 committed Sep 9, 2019
1 parent e27ce5f commit 9b97c9b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 411 deletions.
2 changes: 0 additions & 2 deletions app.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ <h3 id="announcement-title">What's New</h3>
</div>
</div>
</div>
<script src="./lib/chinese/pinyin_dict_notone.js"></script>
<script src="./lib/chinese/pinyinUtil.js"></script>
<script src="app.js"></script>
</body>
</html>
40 changes: 7 additions & 33 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<span class='highlight'>" + kw + "</span>"
})
}
if (textToHighlight.length > 0)
return text
.toLowerCase()
.replace(
textToHighlight,
"<span class='highlight'>" + textToHighlight + "</span>"
);
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<pinyins.length;i++){
var _char = chars[i];
var _pinyin = pinyins[i]
if(pinyin.indexOf(_pinyin) >= 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
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 9b97c9b

Please sign in to comment.