mirror of
https://dl.bcrjl.com/ghg/HaoOuBa/Joe.git
synced 2026-02-18 01:20:04 +08:00
更新
This commit is contained in:
9
assets/js/joe.archive.js
Normal file
9
assets/js/joe.archive.js
Normal file
@@ -0,0 +1,9 @@
|
||||
console.time('Archive.js执行时长');
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
/* 激活列表特效 */
|
||||
{
|
||||
const wow = $('.joe_archive__list').attr('data-wow');
|
||||
if (wow !== 'off' && wow) new WOW({ boxClass: 'wow', animateClass: `animated ${wow}`, offset: 0, mobile: true, live: true, scrollContainer: null }).init();
|
||||
}
|
||||
console.timeEnd('Archive.js执行时长');
|
||||
});
|
||||
@@ -34,6 +34,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
|
||||
/* 搜索框弹窗 */
|
||||
{
|
||||
$('.joe_header__above-search .input').on('click', e => {
|
||||
e.stopPropagation();
|
||||
$('.joe_header__above-search .result').addClass('active');
|
||||
});
|
||||
$(document).on('click', function () {
|
||||
$('.joe_header__above-search .result').removeClass('active');
|
||||
});
|
||||
$(document).on('scroll', function () {
|
||||
$('.joe_header__above-search .result').removeClass('active');
|
||||
});
|
||||
}
|
||||
|
||||
/* 激活全局下拉框功能 */
|
||||
{
|
||||
$('.joe_dropdown').each(function (index, item) {
|
||||
@@ -180,6 +194,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* 计算页面滚动多少 */
|
||||
{
|
||||
const calcProgress = () => {
|
||||
let scrollTop = $(window).scrollTop();
|
||||
let documentHeight = $(document).height();
|
||||
let windowHeight = $(window).height();
|
||||
let progress = parseInt((scrollTop / (documentHeight - windowHeight)) * 100);
|
||||
if (progress <= 0) progress = 0;
|
||||
if (progress >= 100) progress = 100;
|
||||
$('.joe_header__below-progress').css('width', progress + '%');
|
||||
};
|
||||
calcProgress();
|
||||
$(window).on('scroll', () => calcProgress());
|
||||
}
|
||||
|
||||
/* 懒加载 */
|
||||
new LazyLoad('.lazyload');
|
||||
|
||||
|
||||
@@ -1,105 +1,104 @@
|
||||
console.time('Post&Page.js执行时长')
|
||||
console.time('Post&Page.js执行时长');
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
/* 获取本篇文章百度收录情况 */
|
||||
{
|
||||
$.ajax({
|
||||
url: Joe.BASE_API,
|
||||
type: 'POST',
|
||||
data: { routeType: 'baidu_record', site: window.location.href },
|
||||
success(res) {
|
||||
if (res.data && res.data === '已收录') {
|
||||
$('#Joe_Baidu_Record').css('color', '#67C23A')
|
||||
$('#Joe_Baidu_Record').html('已收录')
|
||||
} else {
|
||||
const url = `https://ziyuan.baidu.com/linksubmit/url?sitename=${encodeURI(window.location.href)}`
|
||||
$('#Joe_Baidu_Record').html(`<a target="_blank" href="${url}" rel="noopener noreferrer nofollow" style="color: #F56C6C">未收录,提交收录</a>`)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
/* 获取本篇文章百度收录情况 */
|
||||
{
|
||||
$.ajax({
|
||||
url: Joe.BASE_API,
|
||||
type: 'POST',
|
||||
data: { routeType: 'baidu_record', site: window.location.href },
|
||||
success(res) {
|
||||
if (res.data && res.data === '已收录') {
|
||||
$('#Joe_Baidu_Record').css('color', '#67C23A');
|
||||
$('#Joe_Baidu_Record').html('已收录');
|
||||
} else {
|
||||
const url = `https://ziyuan.baidu.com/linksubmit/url?sitename=${encodeURI(window.location.href)}`;
|
||||
$('#Joe_Baidu_Record').html(`<a target="_blank" href="${url}" rel="noopener noreferrer nofollow" style="color: #F56C6C">未收录,提交收录</a>`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* 激活代码高亮 */
|
||||
{
|
||||
Prism.highlightAll()
|
||||
}
|
||||
/* 激活代码高亮 */
|
||||
{
|
||||
Prism.highlightAll();
|
||||
}
|
||||
|
||||
/* 激活图片预览功能 */
|
||||
{
|
||||
$('.joe_detail__article img:not(img.owo_image)').each(function () {
|
||||
$(this).wrap($(`<div data-fancybox="Joe" href="${$(this).attr('src')}"></div>`))
|
||||
})
|
||||
}
|
||||
/* 激活图片预览功能 */
|
||||
{
|
||||
$('.joe_detail__article img:not(img.owo_image)').each(function () {
|
||||
$(this).wrap($(`<div data-fancybox="Joe" href="${$(this).attr('src')}"></div>`));
|
||||
});
|
||||
}
|
||||
|
||||
/* 设置文章内的链接为新窗口打开 */
|
||||
{
|
||||
$('.joe_detail__article a').each(() => $(this).attr({ target: '_blank', rel: 'noopener noreferrer nofollow' }))
|
||||
}
|
||||
/* 设置文章内的链接为新窗口打开 */
|
||||
{
|
||||
$('.joe_detail__article a').each(() => $(this).attr({ target: '_blank', rel: 'noopener noreferrer nofollow' }));
|
||||
}
|
||||
|
||||
/* 当前页的CID */
|
||||
const cid = $('.joe_detail').attr('data-cid')
|
||||
/* 当前页的CID */
|
||||
const cid = $('.joe_detail').attr('data-cid');
|
||||
|
||||
/* 激活浏览功能 */
|
||||
{
|
||||
let viewsArr = localStorage.getItem(Joe.encryption('views')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('views')))) : []
|
||||
const flag = viewsArr.includes(cid)
|
||||
if (!flag) {
|
||||
$.ajax({
|
||||
url: Joe.BASE_API,
|
||||
type: 'POST',
|
||||
data: { routeType: 'handle_views', cid },
|
||||
success(res) {
|
||||
if (res.code !== 1) return
|
||||
$('#Joe_Article_Views').html(`${res.data.views} 阅读`)
|
||||
viewsArr.push(cid)
|
||||
const name = Joe.encryption('views')
|
||||
const val = Joe.encryption(JSON.stringify(viewsArr))
|
||||
localStorage.setItem(name, val)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
/* 激活浏览功能 */
|
||||
{
|
||||
let viewsArr = localStorage.getItem(Joe.encryption('views')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('views')))) : [];
|
||||
const flag = viewsArr.includes(cid);
|
||||
if (!flag) {
|
||||
$.ajax({
|
||||
url: Joe.BASE_API,
|
||||
type: 'POST',
|
||||
data: { routeType: 'handle_views', cid },
|
||||
success(res) {
|
||||
if (res.code !== 1) return;
|
||||
$('#Joe_Article_Views').html(`${res.data.views} 阅读`);
|
||||
viewsArr.push(cid);
|
||||
const name = Joe.encryption('views');
|
||||
const val = Joe.encryption(JSON.stringify(viewsArr));
|
||||
localStorage.setItem(name, val);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* 激活文章点赞功能 */
|
||||
{
|
||||
let agreeArr = localStorage.getItem(Joe.encryption('agree')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('agree')))) : []
|
||||
if (agreeArr.includes(cid)) $('.joe_detail__agree .icon-1').addClass('active')
|
||||
else $('.joe_detail__agree .icon-2').addClass('active')
|
||||
let _loading = false
|
||||
$('.joe_detail__agree .icon').on('click', function () {
|
||||
if (_loading) return
|
||||
_loading = true
|
||||
agreeArr = localStorage.getItem(Joe.encryption('agree')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('agree')))) : []
|
||||
let flag = agreeArr.includes(cid)
|
||||
$.ajax({
|
||||
url: Joe.BASE_API,
|
||||
type: 'POST',
|
||||
data: { routeType: 'handle_agree', cid, type: flag ? 'disagree' : 'agree' },
|
||||
success(res) {
|
||||
if (res.code !== 1) return
|
||||
$('.joe_detail__agree .text').html(res.data.agree)
|
||||
if (flag) {
|
||||
const index = agreeArr.findIndex(_ => _ === cid)
|
||||
agreeArr.splice(index, 1)
|
||||
$('.joe_detail__agree .icon-1').removeClass('active')
|
||||
$('.joe_detail__agree .icon-2').addClass('active')
|
||||
$('.joe_detail__agree .icon').removeClass('active')
|
||||
} else {
|
||||
agreeArr.push(cid)
|
||||
$('.joe_detail__agree .icon-2').removeClass('active')
|
||||
$('.joe_detail__agree .icon-1').addClass('active')
|
||||
$('.joe_detail__agree .icon').addClass('active')
|
||||
}
|
||||
const name = Joe.encryption('agree')
|
||||
const val = Joe.encryption(JSON.stringify(agreeArr))
|
||||
localStorage.setItem(name, val)
|
||||
},
|
||||
complete() {
|
||||
_loading = false
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
console.timeEnd('Post&Page.js执行时长')
|
||||
})
|
||||
/* 激活文章点赞功能 */
|
||||
{
|
||||
let agreeArr = localStorage.getItem(Joe.encryption('agree')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('agree')))) : [];
|
||||
if (agreeArr.includes(cid)) $('.joe_detail__agree .icon-1').addClass('active');
|
||||
else $('.joe_detail__agree .icon-2').addClass('active');
|
||||
let _loading = false;
|
||||
$('.joe_detail__agree .icon').on('click', function () {
|
||||
if (_loading) return;
|
||||
_loading = true;
|
||||
agreeArr = localStorage.getItem(Joe.encryption('agree')) ? JSON.parse(Joe.decrypt(localStorage.getItem(Joe.encryption('agree')))) : [];
|
||||
let flag = agreeArr.includes(cid);
|
||||
$.ajax({
|
||||
url: Joe.BASE_API,
|
||||
type: 'POST',
|
||||
data: { routeType: 'handle_agree', cid, type: flag ? 'disagree' : 'agree' },
|
||||
success(res) {
|
||||
if (res.code !== 1) return;
|
||||
$('.joe_detail__agree .text').html(res.data.agree);
|
||||
if (flag) {
|
||||
const index = agreeArr.findIndex(_ => _ === cid);
|
||||
agreeArr.splice(index, 1);
|
||||
$('.joe_detail__agree .icon-1').removeClass('active');
|
||||
$('.joe_detail__agree .icon-2').addClass('active');
|
||||
$('.joe_detail__agree .icon').removeClass('active');
|
||||
} else {
|
||||
agreeArr.push(cid);
|
||||
$('.joe_detail__agree .icon-2').removeClass('active');
|
||||
$('.joe_detail__agree .icon-1').addClass('active');
|
||||
$('.joe_detail__agree .icon').addClass('active');
|
||||
}
|
||||
const name = Joe.encryption('agree');
|
||||
const val = Joe.encryption(JSON.stringify(agreeArr));
|
||||
localStorage.setItem(name, val);
|
||||
},
|
||||
complete() {
|
||||
_loading = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
console.timeEnd('Post&Page.js执行时长');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user