{{message_page}}
{{message_auto_skip}}
{{message_skip}}
{{message_switch}}
{{collection_status_emoji}}{{message_count}}
{{time_str}}
`;
let $info = $(info);
$("body").append($info);
let info_style = `
#info {
bottom: 2%;
right: 2%;
padding: 5px 5px;
background: rgba(48,48,48,.7) !important;
position: fixed;
color: rgba(255,255,255,.7);
border-radius: 3px;
}
.collection_status_emoji{
margin-right: 20px;
margin-left: -5px;
}
.time_class{
color: #06dfebd9;
}
.info_item{
padding:5px 0px;
width:120px;
}
.goodman{
-webkit-mask-image: linear-gradient(to right, red, orange, yellow, green, cyan, blue, purple);
background-image: linear-gradient(to right, red, orange, yellow, green, yellow, orange, red, orange, yellow, green, yellow, orange, red);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-webkit-background-size: 200% 100%;
animation: bgp 5s infinite linear;
}
.hide {
display: none;
}
@-webkit-keyframes bgp {
0% { background-position: 0 0;}
100% { background-position: -100% 0;}
}`;
GM_addStyle(info_style);
//vue绑定右下角菜单
info_app = new Vue({
el: '#info',
data: {
dark: dark_mode,
page: page_double,
show: 0,
img_id: img_id,
auto_skip: auto_skip,
skip: 0,
insert_image_id: '',
pic_count: 0,
prev_html_string_data: null,
collection_status: null,
time_str: "",
time_div_hide: true,
collection_emoji_div_hide: true,
flash_good_css: false,
http_token: null,
},
computed: {
message_switch: function () {
return this.dark ? '☀️日间模式' : '🌙夜间模式'
},
message_page: function () {
return this.page ? '1️⃣单页排布' : '2️⃣双页排布'
},
message_auto_skip: function () {
return this.auto_skip ? '☣️关闭自动跨页' : '☣️开启自动跨页';
},
message_skip: function () {
return '📖更改跨页'
},
message_count: function () {
return this.img_id + '/' + this.pic_count
},
collection_status_emoji: function () {
if (this.collection_status === null) {
return '';
}
return this.collection_status ? "🌟" : "☆"
},
},
methods: {
switch_night: function () {
this.dark = !this.dark
$.cookie('dark_mode', this.dark, {expires: 999999, path: '/'});
if (this.dark) {
$('html').addClass('dark_mode');
} else {
$('html').removeClass('dark_mode');
}
},
switch_auto_skip: function () {
if (this.auto_skip) {
msgTips('关闭☣️自动更改跨页', 'success');
} else {
msgTips('开启☣️自动更改跨页', 'success');
}
this.auto_skip = !this.auto_skip;
$.cookie('auto_skip', this.auto_skip, {expires: 999999, path: '/'});
},
switch_skip: function () {
skip();
msgTips('📖更改跨页', 'success');
},
switch_hide_time: function () {
this.time_div_hide = !this.time_div_hide;
$.cookie('right_bottom_time_switch', this.time_div_hide, {expires: 999999, path: '/'});
},
switch_flash_good_css: function () {
this.flash_good_css = !this.flash_good_css;
$.cookie('flash_good_css', this.flash_good_css, {expires: 999999, path: '/'});
},
switch_page: function () {
this.page = !this.page
$.cookie('page_double', this.page, {expires: 999999, path: '/'});
if (this.page) {
$('html').addClass('page_double');
} else {
$('html').removeClass('page_double');
}
$("html").animate({scrollTop: $("#img_" + img_id).offset().top}, 0);
},
request: function (opt) {
var url = opt.url;
var type = opt.type;
var data = opt.data;
var success = opt.success;
var error = opt.error;
var headers = opt.headers;
var request = new XMLHttpRequest();
request.open(type, url, true);
var headerName = [];
var headerText = [];
for (var i in headers) {
headerName.push(i);
headerText.push(headers[i]);
}
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
request.withCredentials = true; //加入这个携带cookie
for (var _i = 0; _i < headerText.length; _i++) {
request.setRequestHeader(headerName[_i], headerText[_i]);
}
var fromStr = '';
for (var _i2 in data) {
fromStr += _i2 + '=' + data[_i2] + "&";
}
fromStr = fromStr.substr(0, fromStr.length - 1);
if (type === 'POST') {
if (data) {
request.send(fromStr);
} else {
request.send(null);
}
} else if (type === 'GET') {
request.send(null);
}
request.onreadystatechange = function (ev) {
if (request.readyState == 4) {
if (request.status == 200) {
var res = JSON.parse(request.response);
success(res);
} else {
var json = JSON.parse(request.response);
error(json);
msgTips(json.message, "error");
}
}
};
},
getPrev: function (func) {
if (info_app.prev_html_string_data === null) {
var href_url = $('.comicContent-prev.list a[href]').attr('href');
if (href_url !== undefined && href_url !== '') {
$.get(href_url, function (res) {
info_app.prev_html_string_data = res;
func(info_app.prev_html_string_data);
})
return;
}
msgTips('当前漫画目录页面地址解析失败', 'error');
return;
}
func(info_app.prev_html_string_data);
},
collect: function () {
this.getPrev(function (prev_string_data) {
if (info_app.collection_status === null) {
info_app.collection_status = (/加入書架/.exec(prev_string_data) === null);
}
var checkResult = !(info_app.collection_status);
var execResult = /collect\(\'([\S]+)\'\)/.exec(prev_string_data);
if (execResult !== null && execResult.length > 1) {
var cartoonId = execResult[1];
var token = info_app.getToken();
var wantToCollect = checkResult ? "1" : "0";
if (token) {
info_app.request({
type: "POST",
url: API_URL + "/api/v2/web/collect",
headers: {
"Authorization": "Token " + token + ""
},
data: {
comic_id: cartoonId,
is_collect: wantToCollect
},
success: function success(res) {
if (checkResult) {
info_app.collection_status = true;
msgTips('加入书架成功', 'success');
} else {
info_app.collection_status = false;
msgTips('取消收藏成功', 'success');
}
},
error: function error(res) {
}
});
} else {
info_app.collection_emoji_div_hide = true;
// msgTips('请在登录之后进行操作', 'error');
}
} else {
msgTips('提取漫画ID失败', 'error');
}
});
},
getToken: function () {
if (this.http_token === null) {
var strCookie = document.cookie; //将多cookie切割为多个名/值对
var arrCookie = strCookie.split("; ");
for (var i = 0; i < arrCookie.length; i++) {
var arr = arrCookie[i].split("=");
if ("token" == arr[0]) {
this.http_token = arr[1];
return this.http_token;
}
}
this.http_token = false;
}
return this.http_token;
},
},
mounted () {
setTimeout(function () {
getImgId();
if (info_app.getToken()) {
info_app.collection_emoji_div_hide = false;
}
var right_bottom_time_switch = $.cookie('right_bottom_time_switch');
var flash_good_css = $.cookie('flash_good_css');
if (right_bottom_time_switch !== undefined) {
info_app.time_div_hide = right_bottom_time_switch === 'true';
}
if (flash_good_css !== undefined) {
info_app.flash_good_css = flash_good_css === 'true';
}
info_app.getPrev(function (prev_string_data) {
info_app.collection_status = (/加入書架/.exec(prev_string_data) === null);
msgTips('获取到当前漫画的收藏状态', 'success');
});
}, 1000);
setInterval(function () {
var now = new Date();
var hh = now.getHours();
var mm = now.getMinutes();
var ss = now.getSeconds();
info_app.time_str = (hh<10?"0"+hh:hh)+ " : "+ (mm<10?"0"+mm:mm)+ " : "+ (ss<10?"0"+ ss: ss);
}, 1000);
},
})
//添加侧边目录栏
let sidebar = `
`
let $sidebar = $(sidebar);
$("body").append($sidebar);
//vue绑定侧边目录栏
var sidebar_app = new Vue({
el: '#sidebar',
data: {
drawer: false,
size: '100%',
modal: false,
direction: 'ltr',
items: [],
},
methods: {
handleSelect(key) {
location.href = this.items[key].href;
},
handleOpen() {
setTimeout(function () {
if ($('.el-menu>li:nth-child(' + (ch_id - 1) + ')').offset()) {
$('.el-drawer__body').animate({scrollTop: 0}, 0);
$('.el-drawer__body').animate({scrollTop: $('.el-menu>li:nth-child(' + (ch_id - 1) + ')').offset().top - $('.el-drawer__body').offset().top}, 0);
}
}, 0)
},
}
})
//加载目录
function menu() {
let $border = $('#default全部 ul:first-child a', el.contents());
if ($border.length == 0) {
setTimeout(menu, 100);
return;
}
$.each($border, function (index) {
if (location.href.indexOf(this.href) >= 0) {
ch_id = index;
GM_addStyle('.el-menu>li:nth-child(' + (ch_id + 1) + '){background:rgba(255,165,0,.5) !important}')
}
sidebar_app.items.push({
title: this.text,
href: this.href,
})
})
}
menu();
})
}
})();