204 lines
9.2 KiB
JavaScript
204 lines
9.2 KiB
JavaScript
/*
|
||
if (navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null) {
|
||
let url = window.location.href;
|
||
window.location = url.replace("//www", "//m");
|
||
}
|
||
*/
|
||
// function login() {
|
||
// if ($.cookie('ss_username')) {
|
||
// document.writeln('欢迎你: '+$.cookie('ss_username')+' | <a href="/logout/">退出登录</a>');
|
||
// } else {
|
||
// document.writeln('<a href="/login/">用户登陆</a> | <a href="/register/">用户注册</a>');
|
||
// }
|
||
// }
|
||
|
||
function search() {
|
||
document.writeln('<form target="_blank" style="margin:0;padding:0;" action="/search.html" method="post">');
|
||
document.writeln('<input type="hidden" name="searchtype" value="all">');
|
||
document.writeln("<input class=\"search\" id=\"bdcsMain\" name=\"s\" type=\"text\" maxlength=\"30\" value=\"可搜书名和作者,请您少字也别输错字。\" title=\"请正确输入\" onfocus=\"this.style.color = '#000000';this.focus();if(this.value=='可搜书名和作者,请您少字也别输错字。'){this.value='';}\" ondblclick=\"javascript:this.value=''\" />");
|
||
document.writeln('<input type="submit" class="searchBtn" value="搜索" title="搜索" /></form>');
|
||
}
|
||
|
||
function textselect() {
|
||
document.writeln('<ul class="tools">\
|
||
<li class="theme"><p>主题:</p><a class="day"></a><a class="night"></a><a class="pink"></a><a class="yellow"></a><a class="blue"></a><a class="green"></a><a class="gray"></a></li>\
|
||
<li class="size"><p>字体:</p><a class="dec">-</a><p id="fontsize">18</p><a class="inc">+</a></li>\
|
||
<li class="reset">重置</li>\
|
||
</ul>');
|
||
}
|
||
|
||
|
||
function formatDate(time) {
|
||
var date = new Date(time);
|
||
var month = date.getMonth()+1;
|
||
var day = date.getDate();
|
||
var hour = date.getHours();
|
||
var minute = date.getMinutes();
|
||
if (month < 10) month = '0' + month;
|
||
if (day < 10) day = '0' + day;
|
||
if (hour < 10) hour = '0' + hour;
|
||
if (minute < 10) minute = '0' + minute;
|
||
return month+'-'+day+' '+hour+':'+minute;
|
||
}
|
||
|
||
|
||
function init(type){
|
||
var articleid = $('body').attr('article-id') || 0, chapterid = $('body').attr('chapter-id') || 0;
|
||
if (chapterid > 0) {
|
||
var book = {name:$('body').attr('article-name'),author:$('body').attr('article-author'),dataid:$('body').attr('data-id')||0,readid:chapterid,readname:$('h1').text(),readtime:$.now()};
|
||
window.localStorage.setItem('book_'+articleid, JSON.stringify(book));
|
||
var theme = function(v){
|
||
if (typeof v === 'undefined') v = window.localStorage.getItem('theme') || 'day';
|
||
$('body').attr('class', v);
|
||
$('li.theme a.'+v).addClass('on').siblings().removeClass('on');
|
||
window.localStorage.setItem('theme', v);
|
||
};
|
||
var size = function(v){
|
||
if (typeof v === 'undefined') v = parseInt(window.localStorage.getItem('size')) || 24;
|
||
$('li.size a.num').text(v);
|
||
$('#content').css('font-size', v);
|
||
$('li.size a').removeClass('disabled');
|
||
if (v<=10) $('li.size a.dec').addClass('disabled');
|
||
if (v>=50) $('li.size a.inc').addClass('disabled');
|
||
$('#fontsize').text(v);
|
||
window.localStorage.setItem('size', v);
|
||
};
|
||
$('li.theme a').click(function(){
|
||
theme($(this).attr('class'));
|
||
});
|
||
$('li.size a').click(function(){
|
||
if ($(this).hasClass('disabled')) return;
|
||
size(parseInt($('#fontsize').text()) + ($(this).hasClass('dec') ? -2 : 2));
|
||
});
|
||
$('li.reset').click(function(){
|
||
theme('day');
|
||
size(24);
|
||
});
|
||
theme();
|
||
size();
|
||
$(document).keydown(function(e){
|
||
switch (e.which) {
|
||
case 37:
|
||
$(window).attr('location', $('#pager_prev').attr('href'));
|
||
break;
|
||
case 39:
|
||
$(window).attr('location', $('#pager_next').attr('href'));
|
||
break;
|
||
case 13:
|
||
$(window).attr('location', $('#pager_current').attr('href'));
|
||
break;
|
||
}
|
||
});
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
function showone(n){
|
||
$('.commend').hide();
|
||
$('#ft'+n).show();
|
||
}
|
||
|
||
function addbookcase(aid,name,cid,cname){
|
||
if($.cookie('ss_userid') && $.cookie('PHPSESSID') != -1) {
|
||
rico_data = {
|
||
articleid: aid,
|
||
articlename: name,
|
||
chapterid: cid,
|
||
chaptername: cname
|
||
}
|
||
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/addbookcase/",
|
||
data: rico_data,
|
||
success: function(data){
|
||
alert(data);
|
||
}
|
||
})
|
||
|
||
}else{
|
||
if (window.confirm("\n永久书架需要登录才能使用,转到登录页面吗?")) {
|
||
window.location.href = "/login/";
|
||
}else{
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
function delbookcase(aid){
|
||
if (window.confirm("\n确定要删除吗?")) {
|
||
if($.cookie('ss_userid') && $.cookie('PHPSESSID') != -1) {
|
||
rico_data = {
|
||
articleid: aid,
|
||
},
|
||
|
||
$.ajax({
|
||
type: "post",
|
||
url: "/delbookcase/",
|
||
data: rico_data,
|
||
success: function(data){
|
||
alert(data);
|
||
window.location.reload();
|
||
}
|
||
})
|
||
}
|
||
}else{
|
||
return;
|
||
}
|
||
}
|
||
|
||
function register_check() {
|
||
|
||
if ($('#regname').val() == '' || $('#regpass').val() == '' || $('#repass').val() == '' || $('#email').val() == '') {
|
||
alert('每项都必须填写');
|
||
return false;
|
||
};
|
||
|
||
if($('#regpass').val() !== $('#repass').val()){
|
||
alert('两次输入的密码不一致');
|
||
return false;
|
||
}
|
||
return true;
|
||
|
||
}
|
||
|
||
function gotop(){$('body,html').animate({scrollTop:0},100);}
|
||
|
||
let bookmax = 50;
|
||
function LastRead(){this.bookList="bookList"} LastRead.prototype={ set:function(bid,uri,bookname,chaptername,author,img_url){ if(!(bid&&uri&&bookname&&chaptername&&author&&img_url))return; var v=bid+'#'+uri+'#'+bookname+'#'+chaptername+'#'+author+'#'+img_url; var aBooks = lastread.getBook(); var aBid = new Array(); for (i=0; i<aBooks.length;i++){aBid.push(aBooks[i][0]);} if($.inArray(bid, aBid) != -1){ lastread.remove(bid); }else{ while (aBooks.length >= 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;i<v.length;i++){ var tem=this.getItem(v[i]).split('#'); if (tem.length>3)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{ 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 removebook(k){lastread.remove(k);showtempbooks();}function removeall(){lastread.removeAll();showtempbooks();}
|
||
function showtempbooks(){
|
||
var books=lastread.getBook().reverse(); //倒序
|
||
bookhtml = '';
|
||
if (books.length){
|
||
for(var i=0 ;i<books.length;i++){
|
||
if (i < bookmax) {
|
||
/*
|
||
bookhtml += '<div class="bookcase-book">';
|
||
bookhtml += '<div class="book-img"><a href="'+books[i][0]+'"><img src="'+books[i][5]+'"></a></div>';
|
||
bookhtml += '<div class="book-info"><h4><a href="'+books[i][0]+'">'+books[i][2]+'</a></h4><p class="author">作者:'+books[i][4]+'</p>';
|
||
bookhtml += '<p class="read"><span>已读到:</span><a href="'+books[i][1]+'">'+books[i][3]+'</a></p></div>';
|
||
bookhtml += '<div class="del-btn"><a class="border-btn" href="javascript:removebook(\''+books[i][0]+'\')">删除</a></div>';
|
||
bookhtml += '</div>';
|
||
*/
|
||
bookhtml += '<li><span class="s1">'+books[i][5]+'</span><span class="s2"><a href="'+books[i][0]+'" target="_blank">'+books[i][2]+'</a></span><span class="s3"><a href="'+books[i][1]+'">'+books[i][3]+'</a></span><span class="s4">'+books[i][4]+'</span><span class="s5"><a href="javascript:removebook(\''+books[i][0]+'\')">删除</a></span></li>';
|
||
|
||
|
||
}
|
||
}
|
||
}else{
|
||
bookhtml += '<b style="display:flex;color:red;padding:20px;">还没有阅读记录哦 ( ˙﹏˙ )( ˙﹏˙ ),去找找书看吧。</b>';
|
||
}
|
||
$("#tempBookcase").html(bookhtml);
|
||
}
|
||
|
||
|
||
|
||
|
||
window.lastread = new LastRead();
|
||
|
||
|