let bookmax=30;function LastRead(){this.bookList="bookList"}LastRead.prototype={set:function(bid,url,bookname,chaptername,author,readtime,cover){if(!(bid&&url&&bookname&&chaptername&&author&&readtime))return;var v=bid+'#'+url+'#'+bookname+'#'+chaptername+'#'+author+'#'+readtime+'#'+cover;var aBooks=lastread.getBook();var aBid=[];for(i=0;i=bookmax){lastread.remove(aBooks[0][0]);aBooks=lastread.getBook()}}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;i3)books.push(tem)}}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{reg=new RegExp("(^| )"+k+"=([^;]*)(;|\x24)");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(var i in v){var tem=this.removeItem(v[k])}}this.removeItem(this.bookList)}}};function removebook(k){layer.confirm('确定要从书架删除本书吗?', {btn: ['删除', '取消']}, function(index){lastread.remove(k);layer.close(index);window.location.reload();}, function(index){layer.close(index);});}function removeall(){layer.confirm('确定要清空临时书架吗?', {btn: ['清空', '取消']}, function(index){lastread.removeAll();layer.close(index);window.location.reload();}, function(index){layer.close(index);});}function showtempbooks(){var books=lastread.getBook().reverse();let bookhtml='
时间书名阅读到作者删除
';if(books.length){for(var i=0;i
'+books[i][2]+'
'+books[i][3]+'
'}}$("#tempBookcase").html(bookhtml)}}window.lastread=new LastRead();