优化调整 js css (未调整完)

This commit is contained in:
liuzhihang 2022-11-05 00:43:20 +08:00
parent f3e06b8fcb
commit fb2653ecc8
9 changed files with 6566 additions and 2192 deletions

View File

@ -1,126 +1,460 @@
"use strict";
var heo_keyboard = !0, heo = {
let heo_cookiesTime = null;
let heo_musicPlaying = false;
let heo_keyboard = false;
let heo_intype = false;
// 私有函数
var heo = {
// 检测显示模式
darkModeStatus: function () {
"light" == ("dark" === document.documentElement.getAttribute("data-theme") ? "dark" : "light") ? $(".menu-darkmode-text").text("深色模式") : $(".menu-darkmode-text").text("浅色模式")
let theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
if (theme == 'light') {
$(".menu-darkmode-text").text("深色模式");
} else {
$(".menu-darkmode-text").text("浅色模式");
}
},
//bb添加时间
changeTimeInEssay: function () {
const relativeDate = function (selector) {
selector.forEach(item => {
const $this = item
const timeVal = $this.getAttribute('datetime')
$this.innerText = btf.diffDate(timeVal, true)
$this.style.display = 'inline'
})
}
if (document.querySelector('#bber')) {
relativeDate(document.querySelectorAll('#bber time'))
}
},
// 首页bb
initIndexEssay: function () {
if (document.querySelector('#bber-talk')) {
var swiper = new Swiper('.swiper-container', {
direction: 'vertical', // 垂直切换选项
loop: true,
autoplay: {
delay: 3000,
pauseOnMouseEnter: true
},
});
}
},
// 只在首页显示
onlyHome: function () {
var e = window.location.pathname;
"/" == (e = decodeURIComponent(e)) ? $(".only-home").attr("style", "display: flex") : $(".only-home").attr("style", "display: none")
var urlinfo = window.location.pathname;
urlinfo = decodeURIComponent(urlinfo);
if (urlinfo == '/') {
$('.only-home').attr('style', 'display: flex');
} else {
$('.only-home').attr('style', 'display: none');
}
},
//是否在首页
is_Post: function () {
return 0 <= window.location.href.indexOf("/p/")
var url = window.location.href; //获取url
if (url.indexOf("/p/") >= 0) { //判断url地址中是否包含code字符串
return true;
} else {
return false;
}
},
//监测是否在页面开头
addNavBackgroundInit: function () {
var e, t = 0, o = 0;
document.body && (t = document.body.scrollTop), document.documentElement && (o = document.documentElement.scrollTop), e = 0 < t - o ? t : o, 0 != e && (document.getElementById("page-header").classList.add("nav-fixed"), document.getElementById("page-header").classList.add("nav-visible"), $("#cookies-window").hide(), console.log("已添加class"))
var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
if (document.body) {
bodyScrollTop = document.body.scrollTop;
}
if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
// console.log("滚动高度"+ scrollTop)
if (scrollTop != 0) {
document.getElementById("page-header").classList.add("nav-fixed");
document.getElementById("page-header").classList.add("nav-visible");
$('#cookies-window').hide()
console.log("已添加class")
}
},
// 标签页面
//分类条
tagPageActive: function () {
var e = window.location.pathname, e = decodeURIComponent(e);
console.log(e);
var t, o, n = /\/tags\/.*?\//.test(e);
console.log(n), n && (t = e.split("/"), console.log(t[2]), o = t[2], document.querySelector("#tag-page-tags") && document.getElementById(o).classList.add("select"))
var urlinfo = window.location.pathname;
urlinfo = decodeURIComponent(urlinfo)
// console.log(urlinfo);
// 验证是否是分类链接
var pattern = /\/tags\/.*?\//;
var patbool = pattern.test(urlinfo);
// console.log(patbool);
// 获取当前的分类
if (patbool) {
var valuegroup = urlinfo.split("/");
// console.log(valuegroup[2]);
// 获取当前分类
var nowCategorie = valuegroup[2];
if (document.querySelector('#tag-page-tags')) {
$('a').removeClass('select')
document.getElementById(nowCategorie).classList.add("select");
}
}
},
//分类条
categoriesBarActive: function () {
document.querySelector("#category-bar") && $(".category-bar-item").removeClass("select");
var e, t = window.location.pathname, t = decodeURIComponent(t);
"/" == t ? document.querySelector("#category-bar") && document.getElementById("category-bar-home").classList.add("select") : /\/categories\/.*?\//.test(t) && (e = t.split("/")[2], document.querySelector("#category-bar") && document.getElementById(e).classList.add("select"))
if (document.querySelector('#category-bar')) {
$(".category-bar-item").removeClass("select")
}
var urlinfo = window.location.pathname;
urlinfo = decodeURIComponent(urlinfo);
// console.log(urlinfo);
//判断是否是首页
if (urlinfo == '/') {
if (document.querySelector('#category-bar')) {
document.getElementById('category-bar-home').classList.add("select");
}
} else {
// 验证是否是分类链接
var pattern = /\/categories\/.*?\//;
var patbool = pattern.test(urlinfo);
// console.log(patbool);
// 获取当前的分类
if (patbool) {
var valuegroup = urlinfo.split("/");
// console.log(valuegroup[2]);
// 获取当前分类
var nowCategorie = valuegroup[2];
if (document.querySelector('#category-bar')) {
document.getElementById(nowCategorie).classList.add("select");
}
}
}
},
// 页脚友链
addFriendLinksInFooter: function () {
var fetchUrl = "https://moments.zhheo.com/randomfriend?num=3"
fetch(fetchUrl)
.then(res => res.json())
.then(json => {
var randomFriendLinks = getArrayItems(json, 3);
var htmlText = '';
for (let i = 0; i < randomFriendLinks.length; ++i) {
var item = randomFriendLinks[i]
htmlText += `<a class='footer-item' href='${item.link}' target="_blank" rel="noopener nofollow">${item.name}</a>`;
}
htmlText += `<a class='footer-item' href='/link/'>更多</a>`
document.getElementById("friend-links-in-footer").innerHTML = htmlText;
})
},
//禁止图片右键单击
stopImgRightDrag: function () {
$("img").on("dragstart", function () {
return !1
})
var img = $("img");
img.on("dragstart", function () {
return false;
});
},
//置顶文章横向滚动
topPostScroll: function () {
var o;
document.getElementById("recent-post-top") && (o = document.getElementById("recent-post-top")).addEventListener("mousewheel", function (e) {
var t = -e.wheelDelta / 2;
o.scrollLeft += t, document.body.clientWidth < 1300 && e.preventDefault()
}, !1)
if (document.getElementById("recent-post-top")) {
let xscroll = document.getElementById("recent-post-top");
xscroll.addEventListener("mousewheel", function (e) {
//计算鼠标滚轮滚动的距离
let v = -e.wheelDelta / 2;
xscroll.scrollLeft += v;
//阻止浏览器默认方法
if (document.body.clientWidth < 1300) {
e.preventDefault();
}
}, false);
}
},
topCategoriesBarScroll: function () {
var o;
document.getElementById("category-bar-items") && (o = document.getElementById("category-bar-items")).addEventListener("mousewheel", function (e) {
var t = -e.wheelDelta / 2;
o.scrollLeft += t, e.preventDefault()
}, !1)
if (document.getElementById("category-bar-items")) {
let xscroll = document.getElementById("category-bar-items");
xscroll.addEventListener("mousewheel", function (e) {
//计算鼠标滚轮滚动的距离
let v = -e.wheelDelta / 2;
xscroll.scrollLeft += v;
//阻止浏览器默认方法
e.preventDefault();
}, false);
}
},
//作者卡片问好
sayhi: function () {
document.querySelector("#author-info__sayhi") && (document.getElementById("author-info__sayhi").innerHTML = getTimeState() + "!我是")
if (document.querySelector('#author-info__sayhi')) {
document.getElementById("author-info__sayhi").innerHTML = getTimeState() + "!我是";
}
},
// 添加标签
addTag: function () {
document.querySelector(".heo-tag-new") && $(".heo-tag-new").append('<sup class="heo-tag heo-tag-new-view">N</sup>'), document.querySelector(".heo-tag-hot") && $(".heo-tag-hot").append('<sup class="heo-tag heo-tag-hot-view">H</sup>')
//添加new标签
if (document.querySelector('.heo-tag-new')) {
$(".heo-tag-new").append(`<sup class="heo-tag heo-tag-new-view">N</sup>`)
}
//添加hot标签
if (document.querySelector('.heo-tag-hot')) {
$(".heo-tag-hot").append(`<sup class="heo-tag heo-tag-hot-view">H</sup>`)
}
},
// 二维码
qrcodeCreate: function () {
document.getElementById("qrcode") && new QRCode(document.getElementById("qrcode"), {
text: window.location.href,
width: 250,
height: 250,
colorDark: "#000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
})
if (document.getElementById('qrcode')) {
document.getElementById("qrcode").innerHTML = "";
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: window.location.href,
width: 250,
height: 250,
colorDark: "#000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
});
}
},
// 刷新即刻短文瀑布流
reflashEssayWaterFall: function () {
document.querySelector("#waterfall") && setTimeout(function () {
waterfall("#waterfall"), document.getElementById("waterfall").classList.add("show")
}, 500)
if (document.querySelector('#waterfall')) {
setTimeout(function () {
waterfall('#waterfall');
document.getElementById("waterfall").classList.add('show');
}, 500);
}
},
// 即刻短文添加灯箱
addMediumInEssay: function () {
document.querySelector("#waterfall") && mediumZoom(document.querySelectorAll("[data-zoomable]"))
if (document.querySelector('#waterfall')) {
mediumZoom(document.querySelectorAll('[data-zoomable]'))
}
},
downloadImage: function (e, c) {
rm.hideRightMenu(), 0 == rm.downloadimging ? (rm.downloadimging = !0, btf.snackbarShow("正在下载中,请稍后", !1, 1e4), setTimeout(function () {
var a = new Image;
a.setAttribute("crossOrigin", "anonymous"), a.onload = function () {
var e = document.createElement("canvas");
e.width = a.width, e.height = a.height, e.getContext("2d").drawImage(a, 0, 0, a.width, a.height);
var t = e.toDataURL("image/png"), o = document.createElement("a"), n = new MouseEvent("click");
o.download = c || "photo", o.href = t, o.dispatchEvent(n)
}, a.src = e, btf.snackbarShow("图片已添加盲水印,请遵守版权协议"), rm.downloadimging = !1
}, "10000")) : btf.snackbarShow("有正在进行中的下载,请稍后再试")
// 下载图片
downloadImage: function (imgsrc, name) { //下载图片地址和图片名
rm.hideRightMenu();
if (rm.downloadimging == false) {
rm.downloadimging = true;
btf.snackbarShow('正在下载中,请稍后', false, 10000)
setTimeout(function () {
let image = new Image();
// 解决跨域 Canvas 污染问题
image.setAttribute("crossOrigin", "anonymous");
image.onload = function () {
let canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;
let context = canvas.getContext("2d");
context.drawImage(image, 0, 0, image.width, image.height);
let url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
let a = document.createElement("a"); // 生成一个a元素
let event = new MouseEvent("click"); // 创建一个单击事件
a.download = name || "photo"; // 设置图片名称
a.href = url; // 将生成的URL设置为a.href属性
a.dispatchEvent(event); // 触发a的单击事件
};
image.src = imgsrc;
btf.snackbarShow('图片已添加盲水印,请遵守版权协议');
rm.downloadimging = false;
}, "10000");
} else {
btf.snackbarShow('有正在进行中的下载,请稍后再试');
}
},
changeThemeColor: function (e) {
null !== document.querySelector('meta[name="theme-color"]') && document.querySelector('meta[name="theme-color"]').setAttribute("content", e)
//控制评论弹幕
switchCommentBarrage: function () {
let commentBarrage = document.querySelector('.comment-barrage');
if (commentBarrage) {
if ($(".comment-barrage").is(":visible")) {
$(".comment-barrage").hide();
$(".menu-commentBarrage-text").text("显示热评");
document.querySelector("#consoleCommentBarrage").classList.remove("on");
localStorage.setItem('commentBarrageSwitch', 'false');
} else if ($(".comment-barrage").is(":hidden")) {
$(".comment-barrage").show();
$(".menu-commentBarrage-text").text("关闭热评");
document.querySelector("#consoleCommentBarrage").classList.add("on");
localStorage.removeItem('commentBarrageSwitch');
}
}
rm.hideRightMenu();
},
//隐藏cookie窗口
hidecookie: function () {
heo_cookiesTime = setTimeout(() => {
document.getElementById("cookies-window").classList.add('cw-hide');
setTimeout(() => {
$('#cookies-window').hide()
}, 1000)
}, 3000)
},
//隐藏今日推荐
hideTodayCard: function () {
if (document.getElementById("todayCard")) {
document.getElementById("todayCard").classList.add('hide');
}
},
//更改主题色
changeThemeColor: function (color) {
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', color)
}
},
//自适应主题色
initThemeColor: function () {
var e, t, o;
heo.is_Post() ? 0 === (window.scrollY || document.documentElement.scrollTop) ? (e = getComputedStyle(document.documentElement).getPropertyValue("--heo-main"), heo.changeThemeColor(e)) : (t = getComputedStyle(document.documentElement).getPropertyValue("--heo-background"), heo.changeThemeColor(t)) : (o = getComputedStyle(document.documentElement).getPropertyValue("--heo-background"), heo.changeThemeColor(o))
if (heo.is_Post()) {
const currentTop = window.scrollY || document.documentElement.scrollTop
if (currentTop === 0) {
let themeColor = getComputedStyle(document.documentElement).getPropertyValue('--heo-main');
heo.changeThemeColor(themeColor);
} else {
let themeColor = getComputedStyle(document.documentElement).getPropertyValue('--heo-background');
heo.changeThemeColor(themeColor);
}
} else {
let themeColor = getComputedStyle(document.documentElement).getPropertyValue('--heo-background');
heo.changeThemeColor(themeColor);
}
},
//跳转到指定位置
jumpTo: function (dom) {
$(document).ready(function () {
$("html,body").animate({
scrollTop: $(dom).eq(i).offset().top
}, 500 /*scroll实现定位滚动*/); /*让整个页面可以滚动*/
});
},
//显示加载动画
showLoading: function () {
document.querySelector("#loading-box").classList.remove("loaded")
document.querySelector("#loading-box").classList.remove("loaded");
let cardColor = getComputedStyle(document.documentElement).getPropertyValue('--heo-card-bg');
heo.changeThemeColor(cardColor);
},
//隐藏加载动画
hideLoading: function () {
document.querySelector("#loading-box").classList.add("loaded")
document.querySelector("#loading-box").classList.add("loaded");
},
//切换音乐播放状态
musicToggle: function () {
let msgPlay = '<i class="fa-solid fa-play"></i><span>播放音乐</span>' // 此處可以更改為你想要顯示的文字
let msgPause = '<i class="fa-solid fa-pause"></i><span>暂停音乐</span>' // 同上,但兩處均不建議更改
if (heo_musicPlaying) {
document.querySelector("#nav-music").classList.remove("playing");
document.getElementById("menu-music-toggle").innerHTML = msgPlay;
document.getElementById("nav-music-hoverTips").innerHTML = "音乐已暂停";
document.querySelector("#consoleMusic").classList.remove("on");
heo_musicPlaying = false;
} else {
document.querySelector("#nav-music").classList.add("playing");
document.getElementById("menu-music-toggle").innerHTML = msgPause;
document.querySelector("#consoleMusic").classList.add("on");
heo_musicPlaying = true;
}
document.querySelector('meting-js').aplayer.toggle();
rm.hideRightMenu();
},
//音乐上一曲
musicSkipBack: function () {
document.querySelector('meting-js').aplayer.skipBack();
rm.hideRightMenu();
},
//音乐下一曲
musicSkipForward: function () {
document.querySelector('meting-js').aplayer.skipForward();
rm.hideRightMenu();
},
//获取音乐中的名称
musicGetName: function () {
var x = $('.aplayer-title')
// var x = document.getElementsByClassName('txt');
// for (var i = x.length - 1; i >= 0; i--) {
// console.log(x[i].innerText)
// }
var arr = []
for (var i = x.length - 1; i >= 0; i--) {
arr[i] = x[i].innerText
// console.log(x[i].innerText)
}
return arr[0]
},
//显示中控台
showConsole: function () {
document.querySelector("#console").classList.add("show")
document.querySelector("#console").classList.add("show");
heo.initConsoleState();
},
//隐藏中控台
hideConsole: function () {
document.querySelector("#console").classList.remove("show")
document.querySelector("#console").classList.remove("show");
},
//快捷键功能开关
keyboardToggle: function () {
heo_keyboard ? (heo_keyboard = !1, document.querySelector("#consoleKeyboard").classList.remove("on"), localStorage.setItem("keyboardToggle", "false")) : (heo_keyboard = !0, document.querySelector("#consoleKeyboard").classList.add("on"), localStorage.setItem("keyboardToggle", "true"))
if (heo_keyboard) {
heo_keyboard = false;
document.querySelector("#consoleKeyboard").classList.remove("on");
localStorage.setItem('keyboardToggle', 'false');
} else {
heo_keyboard = true;
document.querySelector("#consoleKeyboard").classList.add("on");
localStorage.setItem('keyboardToggle', 'true');
}
},
//滚动到指定id
scrollTo: function (id) {
var domTop = document.querySelector(id).offsetTop;
window.scrollTo(0, domTop - 80);
},
//隐藏侧边栏
hideAsideBtn: () => { // Hide aside
const $htmlDom = document.documentElement.classList
$htmlDom.contains('hide-aside')
? saveToLocal.set('aside-status', 'show', 2)
: saveToLocal.set('aside-status', 'hide', 2)
$htmlDom.toggle('hide-aside')
$htmlDom.contains('hide-aside')
? document.querySelector("#consoleHideAside").classList.add("on")
: document.querySelector("#consoleHideAside").classList.remove("on")
},
//初始化console图标
initConsoleState: function () {
//初始化隐藏边栏
const $htmlDom = document.documentElement.classList
$htmlDom.contains('hide-aside')
? document.querySelector("#consoleHideAside").classList.add("on")
: document.querySelector("#consoleHideAside").classList.remove("on")
}
};
}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,4 @@
"use strict";
const btf = {
var btf = {
debounce: function (func, wait, immediate) {
let timeout
return function () {
@ -60,40 +58,99 @@ const btf = {
}
},
snackbarShow: (text, showAction = false, duration = 2000) => {
const { position, bgLight, bgDark } = GLOBAL_CONFIG.Snackbar
const bg = document.documentElement.getAttribute('data-theme') === 'light' ? bgLight : bgDark
snackbarShow: (text, showAction, duration) => {
const sa = (typeof showAction !== 'undefined') ? showAction : false
const dur = (typeof duration !== 'undefined') ? duration : 5000
const position = GLOBAL_CONFIG.Snackbar.position
const bg = document.documentElement.getAttribute('data-theme') === 'light' ? GLOBAL_CONFIG.Snackbar.bgLight : GLOBAL_CONFIG.Snackbar.bgDark
document.styleSheets[0].addRule(':root', '--heo-snackbar-time:' + dur + 'ms!important')
Snackbar.show({
text: text,
backgroundColor: bg,
showAction: showAction,
duration: duration,
pos: position,
customClass: 'snackbar-css'
showAction: sa,
duration: dur,
pos: position
})
},
initJustifiedGallery: function (selector) {
if (!(selector instanceof jQuery)) {
selector = $(selector)
}
selector.each(function (i, o) {
if ($(this).is(':visible')) {
$(this).justifiedGallery({
rowHeight: 220,
margins: 4
})
}
})
},
// 图库排版
// initJustifiedGallery: function (selector) {
// selector.forEach(function (i) {
// if (!btf.isHidden(i)) {
// fjGallery(i, {
// itemSelector: '.fj-gallery-item',
// rowHeight: 220,
// gutter: 4,
// onJustify: function () {
// this.$container.style.opacity = '1'
// }
// })
// }
// })
// },
diffDate: (d, more = false) => {
const dateNow = new Date()
const datePost = new Date(d)
const dateDiff = dateNow.getTime() - datePost.getTime()
const minute = 1000 * 60
const hour = minute * 60
const day = hour * 24
const month = day * 30
scrollToDest: (pos, time = 500) => {
const currentPos = window.pageYOffset
if (currentPos > pos) pos = pos - 70
let result
if (more) {
const monthCount = dateDiff / month
const dayCount = dateDiff / day
const hourCount = dateDiff / hour
const minuteCount = dateDiff / minute
if ('scrollBehavior' in document.documentElement.style) {
if (monthCount > 12) {
// result = datePost.toLocaleDateString().replace(/\//g, '-')
result = datePost.toLocaleDateString()
} else if (dayCount >= 7) {
// } else if (monthCount >= 1) {
result = datePost.toLocaleDateString().substr(5)
// result = parseInt(monthCount) + ' ' + GLOBAL_CONFIG.date_suffix.month
} else if (dayCount >= 1) {
result = parseInt(dayCount) + '' + GLOBAL_CONFIG.date_suffix.day
} else if (hourCount >= 1) {
result = '最近'
// result = parseInt(hourCount) + ' ' + GLOBAL_CONFIG.date_suffix.hour
} else if (minuteCount >= 1) {
result = '最近'
// result = parseInt(minuteCount) + ' ' + GLOBAL_CONFIG.date_suffix.min
} else {
result = GLOBAL_CONFIG.date_suffix.just
}
} else {
result = parseInt(dateDiff / day)
}
return result
},
loadComment: (dom, callback) => {
if ('IntersectionObserver' in window) {
const observerItem = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
callback()
observerItem.disconnect()
}
}, {threshold: [0]})
observerItem.observe(dom)
} else {
callback()
}
},
scrollToDest: (pos, time) => {
if (pos < 0 || time < 0) {
return
}
const currentPos = window.scrollY || window.screenTop
pos = pos - 70
if ('CSS' in window && CSS.supports('scroll-behavior', 'smooth')) {
window.scrollTo({
top: pos,
behavior: 'smooth'
@ -102,31 +159,39 @@ const btf = {
}
let start = null
pos = +pos
window.requestAnimationFrame(function step (currentTime) {
time = time || 500
window.requestAnimationFrame(function step(currentTime) {
start = !start ? currentTime : start
const progress = currentTime - start
if (currentPos < pos) {
const progress = currentTime - start
window.scrollTo(0, ((pos - currentPos) * progress / time) + currentPos)
if (progress < time) {
window.requestAnimationFrame(step)
} else {
window.scrollTo(0, pos)
}
} else {
const progress = currentTime - start
window.scrollTo(0, currentPos - ((currentPos - pos) * progress / time))
}
if (progress < time) {
window.requestAnimationFrame(step)
} else {
window.scrollTo(0, pos)
if (progress < time) {
window.requestAnimationFrame(step)
} else {
window.scrollTo(0, pos)
}
}
})
},
fadeIn: function (e, t) {
e.style.cssText = "display:block;animation: to_show ".concat(t, "s")
fadeIn: (ele, time) => {
ele.style.cssText = `display:block;animation: to_show ${time}s`
},
fadeOut: function (t, e) {
t.addEventListener("animationend", function e() {
t.style.cssText = "display: none; animation: '' ", t.removeEventListener("animationend", e)
}), t.style.animation = "to_hide ".concat(e, "s")
fadeOut: (ele, time) => {
ele.addEventListener('animationend', function f() {
ele.style.cssText = "display: none; animation: '' "
ele.removeEventListener('animationend', f)
})
ele.style.animation = `to_hide ${time}s`
},
getParents: (elem, selector) => {
@ -146,20 +211,21 @@ const btf = {
},
/**
*
* @param {*} selector
* @param {*} eleType the type of create element
* @param {*} options object key: value
* @param {*} id id
* @param {*} cn class name
*/
wrap: (selector, eleType, options) => {
wrap: function (selector, eleType, id = '', cn = '') {
const creatEle = document.createElement(eleType)
for (const [key, value] of Object.entries(options)) {
creatEle.setAttribute(key, value)
}
if (id) creatEle.id = id
if (cn) creatEle.className = cn
selector.parentNode.insertBefore(creatEle, selector)
creatEle.appendChild(selector)
},
unwrap: el => {
unwrap: function (el) {
const elParentNode = el.parentNode
if (elParentNode !== document.body) {
elParentNode.parentNode.insertBefore(el, elParentNode)
@ -167,9 +233,17 @@ const btf = {
}
},
isHidden: ele => ele.offsetHeight === 0 && ele.offsetWidth === 0,
isJqueryLoad: (fn) => {
if (typeof jQuery === 'undefined') {
getScript(GLOBAL_CONFIG.source.jQuery).then(fn)
} else {
fn()
}
},
getEleTop: ele => {
isHidden: (ele) => ele.offsetHeight === 0 && ele.offsetWidth === 0,
getEleTop: (ele) => {
let actualTop = ele.offsetTop
let current = ele.offsetParent
@ -179,6 +253,6 @@ const btf = {
}
return actualTop
},
}
};
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,165 @@
.comment-barrage {
position: fixed;
bottom: 0;
right: 20px;
padding: 0 0 20px 10px;
z-index: 100;
display: flex;
flex-direction: column;
justify-content: end;
align-items: flex-end;
z-index: 999;
transition: 0.3s;
}
@media screen and (max-width: 768px) {
.comment-barrage {
display: none !important;
}
}
.comment-barrage-item {
min-width: 300px;
max-width: 300px;
width: fit-content;
min-height: 80px;
max-height: 150px;
margin: 4px;
padding: 8px 14px;
background: var(--heo-maskbgdeep);
border-radius: 8px;
color: var(--heo-fontcolor);
animation: barrageIn 0.6s cubic-bezier(0.42, 0, 0.3, 1.11);
transition: 0.3s;
display: flex;
flex-direction: column;
border: var(--style-border);
backdrop-filter: saturate(180%) blur(20px);
-webkit-backdrop-filter: blur(20px);
position: fixed;
box-shadow: var(--heo-shadow-border);
overflow: hidden;
}
.comment-barrage-item:hover {
border: var(--style-border-hover);
box-shadow: var(--heo-shadow-main);
}
.comment-barrage-item.out {
opacity: 0;
animation: barrageOut 0.6s cubic-bezier(0.42, 0, 0.3, 1.11);
}
.comment-barrage-item.hovered {
opacity: 0;
}
.comment-barrage-item .comment-barrage-close {
color: var(--heo-secondtext);
cursor: pointer;
line-height: 1;
padding: 4px;
}
.comment-barrage-item .comment-barrage-close:hover {
color: var(--heo-main);
}
.comment-barrage-item pre {
display: none;
}
.comment-barrage-item p img:not(.tk-owo-emotion) {
display: none;
}
.comment-barrage-item p img.tk-owo-emotion {
width: 16px;
padding: 0;
margin: 0;
transform: translateY(2px);
}
.comment-barrage-item blockquote {
display: none;
}
.comment-barrage-item br {
display: none;
}
.comment-barrage-item .barrageHead {
height: 30px;
padding: 0;
line-height: 30px;
font-size: 12px;
border-bottom: var(--style-border);
display: flex;
justify-content: space-between;
align-items: center;
font-weight: bold;
padding-bottom: 6px;
}
.comment-barrage-item .barrageHead .barrageTitle {
color: var(--heo-card-bg);
margin-right: 8px;
background: var(--heo-fontcolor);
line-height: 1;
padding: 4px;
border-radius: 4px;
}
.comment-barrage-item .barrageHead .barrageTitle:hover {
background: var(--heo-main);
color: var(--heo-white);
}
.comment-barrage-item .barrageAvatar {
width: 16px;
height: 16px;
margin: 0;
margin-left: auto;
margin-right: 8px;
border-radius: 50%;
background: var(--heo-secondbg);
}
.comment-barrage-item .barrageContent {
font-size: 14px !important;
font-weight: normal !important;
height: calc(100% - 30px);
overflow: hidden;
width: fit-content;
}
.comment-barrage-item .barrageContent a {
pointer-events: none;
}
.comment-barrage-item .barrageContent::-webkit-scrollbar {
height: 0;
width: 4px;
}
.comment-barrage-item .barrageContent::-webkit-scrollbar-button {
display: none;
}
.comment-barrage-item p {
margin: 8px 0;
line-height: 1.3;
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 2;
display: -webkit-box;
-webkit-box-orient: vertical;
font-size: 14;
}
.comment-barrage-item .barrageContent h1, .comment-barrage-item .barrageContent h2, .comment-barrage-item .barrageContent h3, .comment-barrage-item .barrageContent h4 {
font-size: 14px !important;
font-weight: normal !important;
margin: 8px 0 !important;
}

View File

@ -0,0 +1,150 @@
var commentBarrageConfig = {
//同时最多显示弹幕数
maxBarrage: 1,
//弹幕显示间隔时间ms
barrageTime: 4000,
//twikoo部署地址腾讯云的为环境ID
twikooUrl: "xxxx",
//token获取见上方
accessToken: "xxxx",
pageUrl: window.location.pathname,
barrageTimer: [],
barrageList: [],
barrageIndex: 0,
dom: document.querySelector('.comment-barrage'),
}
var commentInterval = null;
var hoverOnCommentBarrage = false;
$(".comment-barrage").hover(function () {
hoverOnCommentBarrage = true;
console.log("热评悬浮");
}, function () {
hoverOnCommentBarrage = false;
console.log("停止悬浮");
});
function initCommentBarrage() {
// console.log("开始创建热评")
var data = JSON.stringify({
"event": "COMMENT_GET",
"commentBarrageConfig.accessToken": commentBarrageConfig.accessToken,
"url": commentBarrageConfig.pageUrl
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
commentBarrageConfig.barrageList = commentLinkFilter(JSON.parse(this.responseText).data);
commentBarrageConfig.dom.innerHTML = '';
}
});
xhr.open("POST", commentBarrageConfig.twikooUrl);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
clearInterval(commentInterval);
commentInterval = null;
commentInterval = setInterval(() => {
if (commentBarrageConfig.barrageList.length && !hoverOnCommentBarrage) {
popCommentBarrage(commentBarrageConfig.barrageList[commentBarrageConfig.barrageIndex]);
commentBarrageConfig.barrageIndex += 1;
commentBarrageConfig.barrageIndex %= commentBarrageConfig.barrageList.length;
}
if ((commentBarrageConfig.barrageTimer.length > (commentBarrageConfig.barrageList.length > commentBarrageConfig.maxBarrage ? commentBarrageConfig.maxBarrage : commentBarrageConfig.barrageList.length)) && !hoverOnCommentBarrage) {
removeCommentBarrage(commentBarrageConfig.barrageTimer.shift())
}
}, commentBarrageConfig.barrageTime)
}
function commentLinkFilter(data) {
data.sort((a, b) => {
return a.created - b.created;
})
let newData = [];
data.forEach(item => {
newData.push(...getCommentReplies(item));
});
return newData;
}
function getCommentReplies(item) {
if (item.replies) {
let replies = [item];
item.replies.forEach(item => {
replies.push(...getCommentReplies(item));
})
return replies;
} else {
return [];
}
}
function popCommentBarrage(data) {
let barrage = document.createElement('div');
let width = commentBarrageConfig.dom.clientWidth;
let height = commentBarrageConfig.dom.clientHeight;
barrage.className = 'comment-barrage-item'
barrage.innerHTML = `
<div class="barrageHead">
<a class="barrageTitle" href="javascript:heo.scrollTo('#post-comment')"">热评</a>
<div class="barrageNick">${data.nick}</div>
<img class="barrageAvatar" src="https://cravatar.cn/avatar/${data.mailMd5}"/>
<a class="comment-barrage-close" href="javascript:heo.switchCommentBarrage()"><i class="fa-solid fa-xmark"></i></a>
</div>
<a class="barrageContent" href="#${data.id}">${data.comment}</a>
`
commentBarrageConfig.barrageTimer.push(barrage);
commentBarrageConfig.dom.append(barrage);
}
function removeCommentBarrage(barrage) {
barrage.className = 'comment-barrage-item out';
setTimeout(() => {
commentBarrageConfig.dom.removeChild(barrage);
}, 1000)
}
// 自动隐藏
document.addEventListener('scroll', btf.throttle(function () {
//滚动条高度+视窗高度 = 可见区域底部高度
var visibleBottom = window.scrollY + document.documentElement.clientHeight;
//可见区域顶部高度
var visibleTop = window.scrollY;
// 获取翻页按钮容器
var pagination = document.querySelector('.comment-barrage');
// 获取位置监测容器,此处采用评论区
var eventlistner = document.getElementById('post-tools');
if (eventlistner && pagination) {
var centerY = eventlistner.offsetTop + (eventlistner.offsetHeight / 2);
if (document.body.clientWidth > 768) {
if (centerY > visibleBottom) {
pagination.style.bottom = '0';
} else {
pagination.style.bottom = '-200px';
}
}
}
}, 200))
initCommentBarrage();
if (localStorage.getItem('commentBarrageSwitch') !== 'false') {
$(".comment-barrage").show();
$(".menu-commentBarrage-text").text("关闭热评");
document.querySelector("#consoleCommentBarrage").classList.add("on");
} else {
$(".comment-barrage").hide();
$(".menu-commentBarrage-text").text("显示热评");
document.querySelector("#consoleCommentBarrage").classList.remove("on");
}
document.addEventListener('pjax:send', function () {
clearInterval(commentInterval);
});

View File

@ -1,342 +1,419 @@
"use strict";
// 初始化函数
let rm = {};
function asyncGeneratorStep(e, n, t, o, i, r, c) {
try {
var m = e[r](c),
a = m.value;
} catch (e) {
return void t(e);
//禁止图片拖拽
rm.stopdragimg = $("img");
rm.stopdragimg.on("dragstart", function () {
return false;
});
// 显示菜单
rm.showRightMenu = function (isTrue, x = 0, y = 0) {
let $rightMenu = $('#rightMenu');
$rightMenu.css('top', x + 'px').css('left', y + 'px');
if (isTrue) {
$rightMenu.show();
stopMaskScroll()
} else {
$rightMenu.hide();
}
m.done ? n(a) : Promise.resolve(a).then(o, i);
}
function _asyncToGenerator(m) {
return function () {
var e = this,
c = arguments;
return new Promise(function (n, t) {
var o = m.apply(e, c);
function i(e) {
asyncGeneratorStep(o, n, t, i, r, "next", e);
}
function r(e) {
asyncGeneratorStep(o, n, t, i, r, "throw", e);
}
i(void 0);
});
};
// 隐藏菜单
rm.hideRightMenu = function () {
rm.showRightMenu(false);
$('#rightmenu-mask').attr('style', 'display: none');
}
var rm = {};
(rm.stopdragimg = $("img")),
rm.stopdragimg.on("dragstart", function () {
return !1;
}),
(rm.showRightMenu = function (e) {
var n = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : 0,
t = 2 < arguments.length && void 0 !== arguments[2] ? arguments[2] : 0,
o = $("#rightMenu");
o.css("top", n + "px").css("left", t + "px"),
e ? (o.show(), stopMaskScroll()) : o.hide();
}),
(rm.hideRightMenu = function () {
rm.showRightMenu(!1), $("#rightmenu-mask").attr("style", "display: none");
});
var rmWidth = $("#rightMenu").width(),
rmHeight = $("#rightMenu").height();
// 尺寸
let rmWidth = $('#rightMenu').width();
let rmHeight = $('#rightMenu').height();
// 重新定义尺寸
rm.reloadrmSize = function () {
(rmWidth = $("#rightMenu").width()), (rmHeight = $("#rightMenu").height());
rmWidth = $('#rightMenu').width();
rmHeight = $('#rightMenu').height();
}
// 获取点击的href
let domhref = '';
let domImgSrc = '';
let globalEvent = null;
// 监听右键初始化
window.oncontextmenu = function (event) {
if (document.body.clientWidth > 768) {
let pageX = event.clientX + 10; //加10是为了防止显示时鼠标遮在菜单上
let pageY = event.clientY;
// console.log(event);
//其他额外菜单
let $rightMenuOther = $('.rightMenuOther');
let $rightMenuPlugin = $('.rightMenuPlugin');
let $rightMenuCopyText = $('#menu-copytext');
let $rightMenuPasteText = $('#menu-pastetext');
let $rightMenuCommentText = $('#menu-commenttext');
let $rightMenuNewWindow = $('#menu-newwindow');
let $rightMenuCopyLink = $('#menu-copylink');
let $rightMenuCopyImg = $('#menu-copyimg');
let $rightMenuDownloadImg = $('#menu-downloadimg');
let $rightMenuSearch = $('#menu-search');
let $rightMenuSearchBaidu = $('#menu-searchBaidu');
let $rightMenuMusicToggle = $('#menu-music-toggle');
let $rightMenuMusicBack = $('#menu-music-back');
let $rightMenuMusicForward = $('#menu-music-forward');
let $rightMenuMusicPlaylist = $('#menu-music-playlist');
let $rightMenuMusicCopyMusicName = $('#menu-music-copyMusicName');
let href = event.target.href;
let imgsrc = event.target.currentSrc;
// 判断模式 扩展模式为有事件
let pluginMode = false;
$rightMenuOther.show();
globalEvent = event;
// 检查是否需要复制 是否有选中文本
if (selectTextNow && window.getSelection()) {
pluginMode = true;
$rightMenuCopyText.show();
$rightMenuCommentText.show();
$rightMenuSearch.show();
$rightMenuSearchBaidu.show();
} else {
$rightMenuCopyText.hide();
$rightMenuCommentText.hide();
$rightMenuSearchBaidu.hide();
$rightMenuSearch.hide();
}
//检查是否右键点击了链接a标签
if (href) {
pluginMode = true;
$rightMenuNewWindow.show();
$rightMenuCopyLink.show();
domhref = href;
} else {
$rightMenuNewWindow.hide();
$rightMenuCopyLink.hide();
}
//检查是否需要复制图片
if (imgsrc) {
pluginMode = true;
$rightMenuCopyImg.show();
$rightMenuDownloadImg.show();
domImgSrc = imgsrc;
} else {
$rightMenuCopyImg.hide();
$rightMenuDownloadImg.hide();
}
// 判断是否为输入框
if (event.target.tagName.toLowerCase() === 'input' || event.target.tagName.toLowerCase() === 'textarea') {
console.log('这是一个输入框')
pluginMode = true;
$rightMenuPasteText.show();
} else {
$rightMenuPasteText.hide();
}
//判断是否是音乐
if (event.target.nodeName == "METING-JS") {
console.log('这是一个音乐');
pluginMode = true;
$rightMenuMusicToggle.show();
$rightMenuMusicBack.show();
$rightMenuMusicForward.show();
$rightMenuMusicPlaylist.show();
$rightMenuMusicCopyMusicName.show();
} else {
$rightMenuMusicToggle.hide();
$rightMenuMusicBack.hide();
$rightMenuMusicForward.hide();
$rightMenuMusicPlaylist.hide();
$rightMenuMusicCopyMusicName.hide()
}
// 如果不是扩展模式则隐藏扩展模块
if (pluginMode) {
$rightMenuOther.hide();
$rightMenuPlugin.show();
} else {
$rightMenuPlugin.hide()
}
rm.reloadrmSize()
// 鼠标默认显示在鼠标右下方,当鼠标靠右或考下时,将菜单显示在鼠标左方\上方
if (pageX + rmWidth > window.innerWidth) {
pageX -= rmWidth + 10;
}
if (pageY + rmHeight > window.innerHeight) {
pageY -= pageY + rmHeight - window.innerHeight;
}
rm.showRightMenu(true, pageY, pageX);
$('#rightmenu-mask').attr('style', 'display: flex');
return false;
}
};
var domhref = "",
domImgSrc = "",
globalEvent = null;
function imageToBlob(e) {
var t = new Image(),
o = document.createElement("canvas"),
i = o.getContext("2d");
return (
(t.crossOrigin = ""),
(t.src = e),
new Promise(function (n) {
t.onload = function () {
(o.width = this.naturalWidth),
(o.height = this.naturalHeight),
i.drawImage(this, 0, 0),
o.toBlob(
function (e) {
n(e);
},
"image/png",
0.75
);
};
})
);
// 下载图片状态
rm.downloadimging = false;
// 复制图片到剪贴板
rm.writeClipImg = function (imgsrc) {
console.log('按下复制');
rm.hideRightMenu();
btf.snackbarShow('正在下载中,请稍后', false, 10000)
if (rm.downloadimging == false) {
rm.downloadimging = true;
setTimeout(function () {
copyImage(imgsrc);
btf.snackbarShow('复制成功!图片已添加盲水印,请遵守版权协议');
rm.downloadimging = false;
}, "10000")
}
}
function copyImage(e) {
return _copyImage.apply(this, arguments);
function imageToBlob(imageURL) {
const img = new Image;
const c = document.createElement("canvas");
const ctx = c.getContext("2d");
img.crossOrigin = "";
img.src = imageURL;
return new Promise(resolve => {
img.onload = function () {
c.width = this.naturalWidth;
c.height = this.naturalHeight;
ctx.drawImage(this, 0, 0);
c.toBlob((blob) => {
// here the image is a blob
resolve(blob)
}, "image/png", 0.75);
};
})
}
function _copyImage() {
return (_copyImage = _asyncToGenerator(
regeneratorRuntime.mark(function e(n) {
var t, o;
return regeneratorRuntime.wrap(function (e) {
for (; ;)
switch ((e.prev = e.next)) {
case 0:
return (e.next = 2), imageToBlob(n);
case 2:
(t = e.sent),
(o = new ClipboardItem({"image/png": t})),
navigator.clipboard.write([o]);
case 5:
case "end":
return e.stop();
}
}, e);
})
)).apply(this, arguments);
async function copyImage(imageURL) {
const blob = await imageToBlob(imageURL)
const item = new ClipboardItem({"image/png": blob});
navigator.clipboard.write([item]);
}
rm.switchDarkMode = function () {
navFn.switchDarkMode();
rm.hideRightMenu();
heo.darkModeStatus();
}
rm.copyUrl = function (id) {
$("body").after("<input id='copyVal'></input>");
var text = id;
var input = document.getElementById("copyVal");
input.value = text;
input.select();
input.setSelectionRange(0, input.value.length);
document.execCommand("copy");
$("#copyVal").remove();
}
function stopMaskScroll() {
document.getElementById("rightmenu-mask") &&
document.getElementById("rightmenu-mask").addEventListener(
"mousewheel",
function (e) {
if (document.getElementById("rightmenu-mask")) {
let xscroll = document.getElementById("rightmenu-mask");
xscroll.addEventListener("mousewheel", function (e) {
//阻止浏览器默认方法
rm.hideRightMenu();
},
!1
),
document.getElementById("rightMenu") &&
document.getElementById("rightMenu").addEventListener(
"mousewheel",
function (e) {
// e.preventDefault();
}, false);
}
if (document.getElementById("rightMenu")) {
let xscroll = document.getElementById("rightMenu");
xscroll.addEventListener("mousewheel", function (e) {
//阻止浏览器默认方法
rm.hideRightMenu();
},
!1
);
// e.preventDefault();
}, false);
}
}
(window.oncontextmenu = function (e) {
if (768 < document.body.clientWidth) {
var n = e.clientX + 10,
t = e.clientY,
o = $(".rightMenuOther"),
i = $(".rightMenuPlugin"),
r = $("#menu-copytext"),
c = $("#menu-pastetext"),
m = $("#menu-commenttext"),
a = $("#menu-newwindow"),
u = $("#menu-copylink"),
h = $("#menu-copyimg"),
d = $("#menu-downloadimg"),
s = $("#menu-search"),
l = $("#menu-searchBaidu"),
g = $("#menu-music-toggle"),
w = $("#menu-music-back"),
f = $("#menu-music-forward"),
p = $("#menu-music-playlist"),
k = $("#menu-music-copyMusicName"),
y = e.target.href,
v = e.target.currentSrc,
M = !1;
return (
o.show(),
(globalEvent = e),
selectTextNow && window.getSelection()
? ((M = !0), r.show(), m.show(), s.show(), l.show())
: (r.hide(), m.hide(), l.hide(), s.hide()),
y ? ((M = !0), a.show(), u.show(), (domhref = y)) : (a.hide(), u.hide()),
v
? ((M = !0), h.show(), d.show(), (domImgSrc = v))
: (h.hide(), d.hide()),
"input" === e.target.tagName.toLowerCase() ||
"textarea" === e.target.tagName.toLowerCase()
? (console.log("这是一个输入框"), (M = !0), c.show())
: c.hide(),
"METING-JS" == e.target.nodeName
? (console.log("这是一个音乐"),
(M = !0),
g.show(),
w.show(),
f.show(),
p.show(),
k.show())
: (g.hide(), w.hide(), f.hide(), p.hide(), k.hide()),
M ? (o.hide(), i.show()) : i.hide(),
rm.reloadrmSize(),
n + rmWidth > window.innerWidth && (n -= rmWidth + 10),
t + rmHeight > window.innerHeight &&
(t -= t + rmHeight - window.innerHeight),
rm.showRightMenu(!0, t, n),
$("#rightmenu-mask").attr("style", "display: flex"),
!1
);
rm.rightmenuCopyText = function (txt) {
if (navigator.clipboard) {
navigator.clipboard.writeText(txt);
}
}),
(rm.downloadimging = !1),
(rm.writeClipImg = function (e) {
console.log("按下复制"),
rm.hideRightMenu(),
btf.snackbarShow("正在下载中,请稍后", !1, 1e4),
0 == rm.downloadimging &&
((rm.downloadimging = !0),
setTimeout(function () {
copyImage(e),
btf.snackbarShow("复制成功!图片已添加盲水印,请遵守版权协议"),
(rm.downloadimging = !1);
}, "10000"));
}),
(rm.switchDarkMode = function () {
navFn.switchDarkMode(), rm.hideRightMenu(), heo.darkModeStatus();
}),
(rm.copyUrl = function (e) {
$("body").after("<input id='copyVal'></input>");
var n = e,
t = document.getElementById("copyVal");
(t.value = n),
t.select(),
t.setSelectionRange(0, t.value.length),
document.execCommand("copy"),
$("#copyVal").remove();
}),
(rm.rightmenuCopyText = function (e) {
navigator.clipboard && navigator.clipboard.writeText(e), rm.hideRightMenu();
}),
(rm.copyPageUrl = function () {
var e = window.location.href;
rm.copyUrl(e),
btf.snackbarShow("复制本页链接地址成功", !1, 2e3),
rm.hideRightMenu();
}),
(rm.sharePage = function () {
window.location.href;
rm.copyUrl(url),
btf.snackbarShow("复制本页链接地址成功", !1, 2e3),
rm.hideRightMenu();
});
var selectTextNow = "";
rm.hideRightMenu();
}
rm.copyPageUrl = function () {
var url = window.location.href;
rm.copyUrl(url);
btf.snackbarShow('复制本页链接地址成功', false, 2000);
rm.hideRightMenu();
}
rm.sharePage = function () {
var content = window.location.href;
rm.copyUrl(url);
btf.snackbarShow('复制本页链接地址成功', false, 2000);
rm.hideRightMenu();
}
// 复制当前选中文本
var selectTextNow = '';
document.onmouseup = document.ondbclick = selceText;
function selceText() {
var e = document.selection
? document.selection.createRange().text
: window.getSelection() + "";
selectTextNow = e || "";
var txt;
if (document.selection) {
txt = document.selection.createRange().text;
} else {
txt = window.getSelection() + '';
}
if (txt) {
selectTextNow = txt;
// console.log(selectTextNow);
} else {
selectTextNow = '';
}
}
function replaceAll(e, n, t) {
return e.split(n).join(t);
// 读取剪切板
rm.readClipboard = function () {
if (navigator.clipboard) {
navigator.clipboard.readText().then(clipText => rm.insertAtCaret(globalEvent.target, clipText));
}
}
// 粘贴文本到焦点
rm.insertAtCaret = function (elemt, value) {
const startPos = elemt.selectionStart,
endPos = elemt.selectionEnd;
if (document.selection) {
elemt.focus();
var sel = document.selection.createRange();
sel.text = value;
elemt.focus();
} else {
if (startPos || startPos == '0') {
var scrollTop = elemt.scrollTop;
elemt.value = elemt.value.substring(0, startPos) + value + elemt.value.substring(endPos, elemt.value.length);
elemt.focus();
elemt.selectionStart = startPos + value.length;
elemt.selectionEnd = startPos + value.length;
elemt.scrollTop = scrollTop;
} else {
elemt.value += value;
elemt.focus();
}
}
}
//粘贴文本
rm.pasteText = function () {
const result = rm.readClipboard() || '';
rm.hideRightMenu();
}
//引用到评论
rm.rightMenuCommentText = function (txt) {
rm.hideRightMenu();
var input = document.getElementsByClassName('el-textarea__inner')[0];
let evt = document.createEvent('HTMLEvents');
evt.initEvent('input', true, true);
let inputValue = replaceAll(txt, '\n', '\n> ')
input.value = '> ' + inputValue + '\n\n';
input.dispatchEvent(evt);
var domTop = document.querySelector("#post-comment").offsetTop;
window.scrollTo(0, domTop - 80);
input.focus();
input.setSelectionRange(-1, -1);
if (document.getElementById("comment-tips")) {
document.getElementById("comment-tips").classList.add("show");
}
}
//替换所有内容
function replaceAll(string, search, replace) {
return string.split(search).join(replace);
}
// 百度搜索
rm.searchBaidu = function () {
btf.snackbarShow('即将跳转到百度搜索', false, 2000);
setTimeout(function () {
window.open('https://www.baidu.com/s?wd=' + selectTextNow);
}, "2000");
rm.hideRightMenu();
}
//分享链接
rm.copyLink = function () {
rm.rightmenuCopyText(domhref);
btf.snackbarShow('已复制链接地址');
}
function addRightMenuClickEvent() {
$("#menu-backward").on("click", function () {
window.history.back(), rm.hideRightMenu();
}),
$("#menu-forward").on("click", function () {
window.history.forward(), rm.hideRightMenu();
}),
$("#menu-refresh").on("click", function () {
window.location.reload();
}),
$("#menu-top").on("click", function () {
btf.scrollToDest(0, 500), rm.hideRightMenu();
}),
$(".menu-link").on("click", rm.hideRightMenu),
$("#menu-darkmode").on("click", rm.switchDarkMode),
$("#menu-home").on("click", function () {
window.location.href = window.location.origin;
}),
// $("#menu-randomPost").on("click", function () {
// toRandomPost();
// }),
$("#menu-commentBarrage").on("click", heo.switchCommentBarrage),
$("#rightmenu-mask").on("click", rm.hideRightMenu),
$("#rightmenu-mask").contextmenu(function () {
return rm.hideRightMenu(), !1;
}),
$("#menu-copy").on("click", rm.copyPageUrl),
$("#menu-pastetext").on("click", rm.pasteText),
$("#menu-copytext").on("click", function () {
rm.rightmenuCopyText(selectTextNow),
btf.snackbarShow("复制成功,复制和转载请标注本文地址");
}),
$("#menu-commenttext").on("click", function () {
rm.rightMenuCommentText(selectTextNow);
}),
$("#menu-newwindow").on("click", function () {
window.open(domhref), rm.hideRightMenu();
}),
$("#menu-copylink").on("click", rm.copyLink),
$("#menu-downloadimg").on("click", function () {
heo.downloadImage(domImgSrc, "zhheo");
}),
$("#menu-copyimg").on("click", function () {
rm.writeClipImg(domImgSrc);
}),
$("#menu-searchBaidu").on("click", rm.searchBaidu),
$("#menu-music-toggle").on("click", heo.musicToggle),
$("#menu-music-back").on("click", heo.musicSkipBack),
$("#menu-music-forward").on("click", heo.musicSkipForward),
$("#menu-music-copyMusicName").on("click", function () {
rm.rightmenuCopyText(heo.musicGetName()),
btf.snackbarShow("复制歌曲名称成功", !1, 3e3);
});
}
(document.onmouseup = document.ondbclick = selceText),
(rm.readClipboard = function () {
navigator.clipboard &&
navigator.clipboard.readText().then(function (e) {
return rm.insertAtCaret(globalEvent.target, e);
});
}),
(rm.insertAtCaret = function (e, n) {
var t,
o = e.selectionStart,
i = e.selectionEnd;
document.selection
? (e.focus(), (document.selection.createRange().text = n), e.focus())
: o || "0" == o
? ((t = e.scrollTop),
(e.value =
e.value.substring(0, o) + n + e.value.substring(i, e.value.length)),
e.focus(),
(e.selectionStart = o + n.length),
(e.selectionEnd = o + n.length),
(e.scrollTop = t))
: ((e.value += n), e.focus());
}),
(rm.pasteText = function () {
rm.readClipboard();
// 添加点击事件
$('#menu-backward').on('click', function () {
window.history.back();
rm.hideRightMenu();
}),
(rm.rightMenuCommentText = function (e) {
rm.hideRightMenu();
var n = document.getElementsByClassName("el-textarea__inner")[0],
t = document.createEvent("HTMLEvents");
t.initEvent("input", !0, !0);
var o = replaceAll(e, "\n", "\n> ");
(n.value = "> " + o + "\n\n"), n.dispatchEvent(t);
var i = document.querySelector("#post-comment").offsetTop;
window.scrollTo(0, i - 80),
n.focus(),
n.setSelectionRange(-1, -1),
document.getElementById("comment-tips") &&
document.getElementById("comment-tips").classList.add("show");
}),
(rm.searchBaidu = function () {
btf.snackbarShow("即将跳转到百度搜索", !1, 2e3),
setTimeout(function () {
window.open("https://www.baidu.com/s?wd=" + selectTextNow);
}, "2000"),
rm.hideRightMenu();
}),
(rm.copyLink = function () {
rm.rightmenuCopyText(domhref), btf.snackbarShow("已复制链接地址");
});
$('#menu-forward').on('click', function () {
window.history.forward();
rm.hideRightMenu();
});
$('#menu-refresh').on('click', function () {
window.location.reload();
});
$('#menu-top').on('click', function () {
btf.scrollToDest(0, 500);
rm.hideRightMenu();
});
$('.menu-link').on('click', rm.hideRightMenu);
$('#menu-darkmode').on('click', rm.switchDarkMode);
$('#menu-home').on('click', function () {
window.location.href = window.location.origin;
});
$('#menu-randomPost').on('click', function () {
toRandomPost()
});
$('#menu-commentBarrage').on('click', heo.switchCommentBarrage);
$('#rightmenu-mask').on('click', rm.hideRightMenu);
$('#rightmenu-mask').contextmenu(function () {
rm.hideRightMenu();
return false;
});
$('#menu-translate').on('click', function () {
rm.hideRightMenu();
translateInitialization();
});
$('#menu-copy').on('click', rm.copyPageUrl);
$('#menu-pastetext').on('click', rm.pasteText);
$('#menu-copytext').on('click', function () {
rm.rightmenuCopyText(selectTextNow);
btf.snackbarShow('复制成功,复制和转载请标注本文地址');
});
$('#menu-commenttext').on('click', function () {
rm.rightMenuCommentText(selectTextNow);
});
$('#menu-newwindow').on('click', function () {
window.open(domhref);
rm.hideRightMenu();
});
$('#menu-copylink').on('click', rm.copyLink);
$('#menu-downloadimg').on('click', function () {
heo.downloadImage(domImgSrc, 'zhheo');
});
$('#menu-copyimg').on('click', function () {
rm.writeClipImg(domImgSrc);
});
$('#menu-searchBaidu').on('click', rm.searchBaidu);
//音乐
$('#menu-music-toggle').on('click', heo.musicToggle);
$('#menu-music-back').on('click', heo.musicSkipBack);
$('#menu-music-forward').on('click', heo.musicSkipForward);
$('#menu-music-copyMusicName').on('click', function () {
rm.rightmenuCopyText(heo.musicGetName());
btf.snackbarShow('复制歌曲名称成功', false, 3000);
});
}

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,12 @@
// 页面类型 index,page,post,tag,category
htmlType: [[${htmlType}]],
postTitle: [[${htmlType == 'post' ? post.spec.title : ''}]],
isanchor: true,
isPost: [[${htmlType == 'post'}]],
isHome: [[${htmlType == 'index'}]],
isHighlightShrink: false,
isToc: [[${htmlType == 'post'}]] && document.getElementById("card-toc"),
postUpdate: '2022-11-04 20:08:15',
Snackbar: {
chs_to_cht: "你已切换为繁体",
cht_to_chs: "你已切换为简体",