function format(source, params) { $.each(params,function (i, n) { source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n); }) return source; } function addHistory(pChapt) { lsReading = lscache.get('reading'); if (lsReading != null) { for (i = 0; i < lsReading.length; i++) { if (pChapt.str_id == lsReading[i].str_id) { lsReading.splice(i, 1); break; } } } else { lsReading = []; } obj = {}; obj.str_id = pChapt.str_id; obj.str_title = pChapt.str_title; obj.chp_id = pChapt.chp_id; obj.chp_title = pChapt.chp_title; obj.chp_index = pChapt.chp_index; d = new Date(); obj.time = d.getTime(); lsReading.splice(0, 0, obj); if (lsReading.length > 20) lsReading.length = 20; lscache.set('reading', lsReading); lsBookmark = lscache.get("bookmark"); if (lsBookmark != null) { for (i = 0; i < lsBookmark.length; i++) { if (pChapt.str_id == lsBookmark[i].str_id) { lsBookmark[i].str_id = pChapt.str_id; lsBookmark[i].str_title = pChapt.str_title; lsBookmark[i].chp_id = pChapt.chp_id; lsBookmark[i].chp_title = pChapt.chp_title; lsBookmark[i].chp_index = pChapt.chp_index; d = new Date(); lsBookmark[i].time = d.getTime(); lscache.set("bookmark", lsBookmark); break; } } } } function addBookmark(pChapt) { if (!pChapt.str_id) return; lsBookmark = lscache.get("bookmark"); if (lsBookmark != null) { for (i = 0; i < lsBookmark.length; i++) { if (pChapt.str_id == lsBookmark[i].str_id) { return; } } } else { lsBookmark = []; } obj = {}; obj.str_id = pChapt.str_id; obj.str_title = pChapt.str_title; obj.chp_id = pChapt.chp_id; obj.chp_title = pChapt.chp_title; obj.chp_index = pChapt.chp_index; d = new Date(); obj.time = d.getTime(); lsBookmark.splice(0, 0, obj); if (lsBookmark.length > 20) lsBookmark.length = 20; lscache.set("bookmark", lsBookmark); } function rmCache(ele, str_id, type) { lsStory = lscache.get(type); for (i = 0; i < lsStory.length; i++) { if (str_id == lsStory[i].str_id) { lsStory.splice(i, 1); lscache.set(type, lsStory); $(ele).parent().parent().remove(); break; } } } function loadReadingStory(e, type){ lsStory = lscache.get(type); lsIds = []; for (i = 0; i < lsStory.length; i++) { lsIds.push(lsStory[i].str_id); } if (lsIds.length == 0){ if (type == 'reading') $("#" + e).html("Bạn chưa đọc truyện nào"); else $("#" + e).html("Bạn chưa đánh dấu truyện nào"); return; } $.ajax({ type: 'POST', url: '/ajax.php?reading=1', data: { lsIds: lsIds } }).done(function (rs) { ls = JSON.parse(rs); szHtml = ""; $("#" + e).replaceWith(szHtml); }); } $(document).ready(function () { $("#loadReadingBtn").click(function () { loadReadingStory("loadReadingBtn", 'reading'); }); $("#loadBookmarkBtn").click(function () { loadReadingStory("loadBookmarkBtn", 'bookmark'); }); });