213 lines
5.8 KiB
JavaScript
213 lines
5.8 KiB
JavaScript
var _num = 100;
|
|
|
|
function LastRead(){
|
|
this.bookList="bookList"
|
|
}
|
|
LastRead.prototype={
|
|
set:function(bid,tid,title,texttitle,read_page,author){
|
|
if(!(bid&&tid&&title&&texttitle,read_page))return;
|
|
var v=bid+'#'+tid+'#'+title+'#'+texttitle+'#'+read_page+'#'+author;
|
|
this.setItem(bid,v);
|
|
this.setBook(bid)
|
|
},
|
|
|
|
get:function(k){
|
|
return this.getItem(k)?this.getItem(k).split("#"):"";
|
|
},
|
|
|
|
remove:function(k){
|
|
this.removeItem(k);
|
|
this.removeBook(k)
|
|
},
|
|
|
|
setBook:function(v){
|
|
var reg=new RegExp("(^|#)"+v);
|
|
var books = this.getItem(this.bookList);
|
|
if(books==""){
|
|
books=v
|
|
}
|
|
else{
|
|
if(books.search(reg)==-1){
|
|
books+="#"+v
|
|
}
|
|
else{
|
|
books.replace(reg,"#"+v)
|
|
}
|
|
}
|
|
this.setItem(this.bookList,books)
|
|
|
|
},
|
|
|
|
getBook:function(){
|
|
var v=this.getItem(this.bookList)?this.getItem(this.bookList).split("#"):Array();
|
|
var books=Array();
|
|
if(v.length){
|
|
|
|
for(var i=0;i<v.length;i++){
|
|
var tem=this.getItem(v[i]).split('#');
|
|
if(i>v.length-(_num+1)){
|
|
if (tem.length>3) books.push(tem);
|
|
}
|
|
else{
|
|
lastread.remove(tem[0]);
|
|
}
|
|
}
|
|
}
|
|
return books
|
|
},
|
|
|
|
removeBook:function(v){
|
|
var reg=new RegExp("(^|#)"+v);
|
|
var books = this.getItem(this.bookList);
|
|
if(!books){
|
|
books=""
|
|
}
|
|
else{
|
|
if(books.search(reg)!=-1){
|
|
books=books.replace(reg,"")
|
|
}
|
|
|
|
}
|
|
this.setItem(this.bookList,books)
|
|
|
|
},
|
|
|
|
setItem:function(k,v){
|
|
if(!!window.localStorage){
|
|
localStorage.setItem(k,v);
|
|
}
|
|
else{
|
|
var expireDate=new Date();
|
|
var EXPIR_MONTH=30*24*3600*1000;
|
|
expireDate.setTime(expireDate.getTime()+12*EXPIR_MONTH)
|
|
document.cookie=k+"="+encodeURIComponent(v)+";expires="+expireDate.toGMTString()+"; path=/";
|
|
}
|
|
},
|
|
|
|
getItem:function(k){
|
|
var value=""
|
|
var result=""
|
|
if(!!window.localStorage){
|
|
result=window.localStorage.getItem(k);
|
|
value=result||"";
|
|
}
|
|
else{
|
|
var reg=new RegExp("(^| )"+k+"=([^;]*)(;|\x24)");
|
|
var result=reg.exec(document.cookie);
|
|
if(result){
|
|
value=decodeURIComponent(result[2])||""}
|
|
}
|
|
return value
|
|
|
|
},
|
|
|
|
removeItem:function(k){
|
|
if(!!window.localStorage){
|
|
window.localStorage.removeItem(k);
|
|
}
|
|
else{
|
|
var expireDate=new Date();
|
|
expireDate.setTime(expireDate.getTime()-1000)
|
|
document.cookie=k+"= "+";expires="+expireDate.toGMTString()
|
|
}
|
|
},
|
|
removeAll:function(){
|
|
if(!!window.localStorage){
|
|
window.localStorage.clear();
|
|
}
|
|
else{
|
|
var v=this.getItem(this.bookList)?this.getItem(this.bookList).split("#"):Array();
|
|
var books=Array();
|
|
if(v.length){
|
|
for( i in v ){
|
|
var tem=this.removeItem(v[k])
|
|
}
|
|
}
|
|
this.removeItem(this.bookList)
|
|
}
|
|
}
|
|
}
|
|
|
|
function showbook(){
|
|
var showbook=document.getElementById('tmpbook');
|
|
var books=lastread.getBook();
|
|
var bookhtml = '';
|
|
if(books.length){
|
|
var k = 1;
|
|
for(var i=books.length-1;i>-1;i--){
|
|
var articleid = parseInt(books[i][0]);
|
|
var shortid = parseInt(articleid/1000);
|
|
var articlename = books[i][2];
|
|
var lastchapter = books[i][3];
|
|
var lastchapterid = books[i][1];
|
|
var read_page = parseInt(books[i][4]);
|
|
var author = books[i][5];
|
|
var read_ym = parseInt(read_page+1);
|
|
info_url = info_rewrite.replace(/{aid}/, articleid);
|
|
info_url = info_url.replace(/{bid}/, shortid);
|
|
read_url = read_rewrite.replace(/{aid}/, articleid);
|
|
read_url = read_url.replace(/{bid}/,shortid);
|
|
read_url = read_url.replace(/{cid}/,lastchapterid);
|
|
read_page_url = read_page_rewrite.replace(/{aid}/, articleid);
|
|
read_page_url = read_page_url.replace(/{bid}/,shortid);
|
|
read_page_url = read_page_url.replace(/{cid}/,lastchapterid);
|
|
read_page_url = read_page_url.replace(/{pid}/,read_page);
|
|
var info_url,read_url;
|
|
var c = '';
|
|
if((k % 2) == 0){
|
|
c = 'hot_saleEm';
|
|
}
|
|
if(read_page == 0){
|
|
page_word='';
|
|
}else{
|
|
page_word='第'+read_ym+'页';
|
|
}
|
|
/*
|
|
if(read_page == 0){
|
|
jxyd ='<a href="'+read_url+'" class="a3"><span class="iconfont icon-yuedu1"></span>继续阅读</a></div>';
|
|
}else{
|
|
jxyd ='<a href="'+read_page_url+'" class="a3"><span class="iconfont icon-yuedu1"></span>继续阅读</a></div>';
|
|
}
|
|
*/
|
|
if(read_page == 0){
|
|
jxyd ='<a href="'+read_url+'" class="mark_read layui-btn layui-bg-cyan">继续阅读</a></div>';
|
|
}else{
|
|
jxyd ='<a href="'+read_page_url+'" class="mark_read layui-btn layui-bg-cyan">继续阅读</a></div>';
|
|
}
|
|
var jxyd;
|
|
//bookhtml+='<li id="'+articleid+'"><span class="s1"><a href="'+info_url+'">《'+articlename+'》</a></span><span class="s2">作 者:'+author+'</span><span class="s3">阅读至:'+lastchapter+page_word+'</span><span class="s5"><a href="javascript:removebook('+articleid+')" class="xsdel">删除</a><a onclick=\'shuqian('+articleid+','+lastchapterid+',"'+tmpbook_rewrite+'")\' class="a2"><span class="iconfont icon-gengxin"></span>保存至书架</a>'+jxyd+'</span></li>';
|
|
|
|
bookhtml+='<li>'+jxyd+'<a href="'+info_url+'"><img src="/'+Math.floor(articleid/1000)+'/'+articleid+'/'+articleid+'s.jpg" onerror="this.onerror=null;this.src=\'/qs_theme/defaultimg.png\'"></a><p class="bookname"><a href="'+info_url+'">'+articlename+'</a></p><p class="author"><a href="/author/'+author+'.html"><i class="layui-icon i_author"></i> '+author+'</a></p><p></p><p class="chapter">读到:'+lastchapter+page_word+'</p><p><a href="javascript:removebook('+articleid+')" class="layui-btns layui-btn-danger">删除</a><a href="'+info_url+'" class="layui-btns layui-btn-danger">收藏</a></p></li>';
|
|
|
|
|
|
k++;
|
|
}
|
|
showbook.innerHTML = bookhtml;
|
|
}
|
|
else{
|
|
showbook.innerHTML = '<li>您还木有阅读本站小说,未产生阅读记录。</li>';
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function removebook(k){
|
|
lastread.remove(k);
|
|
showbook()
|
|
}
|
|
|
|
|
|
|
|
function yuedu(){
|
|
//document.write("<a href='javascript:showbook();' target='_self'>点击查看阅读记录</a>");
|
|
showbook();
|
|
}
|
|
|
|
window.lastread = new LastRead();
|
|
|
|
|
|
function removebook(k){
|
|
lastread.remove(k);
|
|
showbook()
|
|
}
|