This commit is contained in:
杜恒
2021-01-26 21:41:01 +08:00
parent bf1450eb2e
commit f2ed0ae7e1
27 changed files with 1509 additions and 515 deletions

View File

@@ -1,10 +1,9 @@
console.time('Global.js执行时长');
document.addEventListener('DOMContentLoaded', () => {
/* 昼夜模式 */
/* 初始化昼夜模式 */
{
if (localStorage.getItem('data-night')) {
$('html').attr('data-night', 'night');
$('.joe_action_item.mode .icon-1').addClass('active');
$('.joe_action_item.mode .icon-2').removeClass('active');
} else {
@@ -226,15 +225,33 @@ document.addEventListener('DOMContentLoaded', () => {
/* 激活画图功能 */
{
if ($('#joe_comment_draw').length !== 0) {
window.sketchpad = new Sketchpad({
element: '#joe_comment_draw',
height: 300,
penSize: 5,
color: '303133'
/* 激活画板 */
window.sketchpad = new Sketchpad({ element: '#joe_comment_draw', height: 300, penSize: 5, color: '303133' });
/* 撤销上一步 */
$('.joe_comment__respond-form .body .draw .icon-undo').on('click', () => window.sketchpad.undo());
/* 动画预览 */
$('.joe_comment__respond-form .body .draw .icon-animate').on('click', () => window.sketchpad.animate(10));
/* 更改画板的线宽 */
$('.joe_comment__respond-form .body .draw .line li').on('click', function () {
window.sketchpad.penSize = $(this).attr('data-line');
$(this).addClass('active').siblings().removeClass('active');
});
/* 更改画板的颜色 */
$('.joe_comment__respond-form .body .draw .color li').on('click', function () {
window.sketchpad.color = $(this).attr('data-color');
$(this).addClass('active').siblings().removeClass('active');
});
}
}
/* 激活点击回复可见的回复按钮,页面滚动到评论区 */
{
$('.joe_detail__article-hide i').on('click', function () {
const top = $('.joe_comment').offset().top - $('.joe_header').height() - 15;
window.scrollTo({ top, behavior: 'smooth' });
});
}
/* 懒加载 */
new LazyLoad('.lazyload');

145
assets/js/joe.owo.js Normal file
View File

@@ -0,0 +1,145 @@
(() => {
class OwO {
constructor(option) {
const defaultOption = {
container: document.getElementsByClassName('OwO')[0],
target: document.getElementsByTagName('textarea')[0],
position: 'down',
width: '100%',
maxHeight: '250px',
api: 'https://api.anotherhome.net/OwO/OwO.json'
};
for (let defaultKey in defaultOption) {
if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
option[defaultKey] = defaultOption[defaultKey];
}
}
this.container = option.container;
this.target = option.target;
if (option.position === 'up') {
this.container.classList.add('OwO-up');
}
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
this.odata = JSON.parse(xhr.responseText);
this.init(option);
} else {
console.log('OwO data request was unsuccessful: ' + xhr.status);
}
}
};
xhr.open('get', option.api, true);
xhr.send(null);
}
init(option) {
this.area = option.target;
this.packages = Object.keys(this.odata);
// fill in HTML
let html = `
<div class="OwO-logo"><span><svg viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round" class="css-i6dzq1"><circle cx="12" cy="12" r="10"></circle><path d="M8 14s1.5 2 4 2 4-2 4-2"></path><line x1="9" y1="9" x2="9.01" y2="9"></line><line x1="15" y1="9" x2="15.01" y2="9"></line></svg>表情</span></div>
<div class="OwO-body" style="width: ${option.width}"><div class="OwO-jio"></div>`;
for (let i = 0; i < this.packages.length; i++) {
html += `
<ul class="OwO-items OwO-items-${this.odata[this.packages[i]].type}" style="max-height: ${parseInt(option.maxHeight) - 53 + 'px'};">`;
var type = this.odata[this.packages[i]].type;
let opackage = this.odata[this.packages[i]].container;
for (let i = 0; i < opackage.length; i++) {
if (type == 'image') {
html += `
<li class="OwO-item" data-id="${opackage[i].data}" title="${opackage[i].text}">${opackage[i].icon}</li>`;
} else {
html += `
<li class="OwO-item" data-id="not-given" title="${opackage[i].text}">${opackage[i].icon}</li>`;
}
}
html += `
</ul>`;
}
html += `
<div class="OwO-bar">
<ul class="OwO-packages">`;
for (let i = 0; i < this.packages.length; i++) {
html += `
<li><span>${this.packages[i]}</span></li>`;
}
html += `
</ul>
</div>
</div>
`;
this.container.innerHTML = html;
// bind event
this.logo = document.getElementsByClassName('OwO-logo')[0];
this.logo.addEventListener('click', e => {
e.stopPropagation();
this.toggle();
});
this.container.getElementsByClassName('OwO-body')[0].addEventListener('click', e => {
let target = null;
if (e.target.classList.contains('OwO-item')) {
target = e.target;
} else if (e.target.parentNode.classList.contains('OwO-item')) {
target = e.target.parentNode;
}
if (target) {
const cursorPos = this.area.selectionEnd;
let areaValue = this.area.value;
//this.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos);
if (target.dataset.id == 'not-given') {
this.area.value = areaValue.slice(0, cursorPos) + target.innerHTML + areaValue.slice(cursorPos);
} else {
this.area.value = areaValue.slice(0, cursorPos) + target.dataset.id + areaValue.slice(cursorPos);
}
this.area.focus();
this.toggle();
}
});
this.packagesEle = this.container.getElementsByClassName('OwO-packages')[0];
for (let i = 0; i < this.packagesEle.children.length; i++) {
(index => {
this.packagesEle.children[i].addEventListener('click', e => {
e.stopPropagation();
this.tab(index);
});
})(i);
}
this.tab(0);
}
toggle() {
if (this.container.classList.contains('OwO-open')) {
this.container.classList.remove('OwO-open');
} else {
this.container.classList.add('OwO-open');
}
}
tab(index) {
const itemsShow = this.container.getElementsByClassName('OwO-items-show')[0];
if (itemsShow) {
itemsShow.classList.remove('OwO-items-show');
}
this.container.getElementsByClassName('OwO-items')[index].classList.add('OwO-items-show');
const packageActive = this.container.getElementsByClassName('OwO-package-active')[0];
if (packageActive) {
packageActive.classList.remove('OwO-package-active');
}
this.packagesEle.getElementsByTagName('li')[index].classList.add('OwO-package-active');
}
}
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = OwO;
} else {
window.OwO = OwO;
}
})();

View File

@@ -12,8 +12,32 @@ document.addEventListener('DOMContentLoaded', () => {
$('#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>`);
/* 如果填写了Token则自动推送给百度 */
if (Joe.BAIDU_PUSH) {
$('#Joe_Baidu_Record').html('<span style="color: #E6A23C">未收录,推送中...</span>');
const _timer = setTimeout(function () {
$.ajax({
url: Joe.BASE_API,
type: 'POST',
data: {
routeType: 'baidu_push',
domain: encodeURI(window.location.hostname),
url: encodeURI(window.location.href)
},
success(res) {
if (res.error) {
$('#Joe_Baidu_Record').html('<span style="color: #F56C6C">推送失败,请检查!</span>');
} else {
$('#Joe_Baidu_Record').html('<span style="color: #67C23A">推送成功!</span>');
}
}
});
clearTimeout(_timer);
}, 1000);
} 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>`);
}
}
}
});