function setCookie(key, value, expiredays) {
var todayDate = new Date();
todayDate.setDate(todayDate.getDate() + expiredays);
document.cookie = key + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
function getCookie(key) {
var result = null;
var cookie = document.cookie.split(';');
cookie.some(function (item) {
item = item.replace(' ', '');
var dic = item.split('=');
if (key === dic[0]) {
result = dic[1];
return true;
}
});
return result;
}
function setSearchWord(str) {
if(getCookie("searchword") != null && getCookie("searchword") !== undefined){
let searchword = unescape(getCookie("searchword"));
if(searchword.split("/").length >= 10){
searchword = searchword.substring(0, searchword.lastIndexOf("/"));
}
if(searchword.indexOf(str) != searchword.lastIndexOf(str)){
let imsi = str + "/" + searchword;
setCookie("searchword", imsi, 1);
return false;
}
if(searchword.indexOf(str) != -1){
let start = searchword.indexOf(str)-1;
if(start < 0) start = 0;
let end = searchword.indexOf(str)+str.length;
let imsi = searchword.substring(0, start);
let imsi2 = searchword.substring(end, searchword.length);
searchword = imsi + imsi2 + "/" + str;
if(searchword.indexOf("/") == 0){
searchword = searchword.substring(1, searchword.length);
}
setCookie("searchword", searchword, 1);
return false;
}
let imsi = str + "/" + searchword;
setCookie("searchword", imsi, 1);
return false;
}
setCookie("searchword", str, 1);
}
function delSearchWord(thisobj, str) {
if(getCookie("searchword") == null || getCookie("searchword") === undefined){
return false;
}
let searchword = unescape(getCookie("searchword"));
if(searchword.indexOf(str) != -1){
let start = searchword.indexOf(str)-1;
if(str < 0) str = 0;
let end = searchword.indexOf(str)+str.length;
let imsi = searchword.substring(0, start);
let imsi2 = searchword.substring(end, searchword.length);
searchword = imsi + imsi2;
setCookie("searchword", searchword, 1);
$(thisobj).closest("dd").remove();
}
}