修复退出登录问题
detailed: 1.更新了readme文件和主题配置文件 2.修复了退出登录无法退出的问题
This commit is contained in:
parent
19df302749
commit
d197c0e95c
55
README.md
55
README.md
@ -1,3 +1,54 @@
|
||||
# halo-theme-hao
|
||||
<div align="center">
|
||||
<!-- 主题Logo -->
|
||||
<img width="100px" src="https://api.minio.yyds.pink/moony/files/2024/04/halo-theme-hao-sbxqdmuv.png">
|
||||
<!-- 主题名称 -->
|
||||
<h1>Halo-Theme-Hao</h1>
|
||||
|
||||
基于halo-theme-hao的1.4.9-beta2版本进行修改。
|
||||
## 🔥 预览
|
||||
|
||||
| 站点名称 | 站点地址 |
|
||||
|:----------:|:----------------------:|
|
||||
| 小小笔记大大用处 | https://blog.uptoz.cn |
|
||||
|
||||
|
||||
## 👋 简介
|
||||
|
||||
[Halo-Theme-Hao](https://gitea.uptoz.cn/UPToZ/halo-theme-hao)
|
||||
是一款适用于 [Halo2.x](https://github.com/halo-dev/halo) 的博客主题。
|
||||
|
||||
移植自 [Hexo](https://hexo.io/zh-cn/index.html) 社区中 [张洪 Heo](https://blog.zhheo.com/)
|
||||
对 [Hexo-Theme-hao](https://github.com/chengzhongxue/halo-theme-hao)主题1.4.9-beta2的魔改版本。
|
||||
|
||||
|
||||
## 🚨 注意事项(看我看我)
|
||||
|
||||
1. **建站时间必填**
|
||||
2. 如果安装主题后报错,请仔细查阅[主题说明](https://gitea.uptoz.cn/UPToZ/halo-theme-hao)
|
||||
与[更新说明](https://gitea.uptoz.cn/UPToZ/halo-theme-hao/releases)!!!
|
||||
3. 如果还未解决,可以加群求助!!!
|
||||
4. 如果群友也解决不了,再考虑提ISSUE!!!
|
||||
5. `1.3.1`及以上版本需要`Halo`版本>=`2.8.0`
|
||||
6. **若安装主题后出现500错误,请到主题设置页面,将每个设置项都保存一下!!!**
|
||||
7. **`beta`版本主题必须使用`本地资源`,正式版本才会存在`在线资源`**
|
||||
|
||||
### 🔌 插件依赖
|
||||
|
||||
> 所有插件均为可选,不安装则不会出现对应功能。
|
||||
> 部分插件可能已经预设在 Halo 内。
|
||||
> 部分插件主题尚未适配。
|
||||
|
||||
- 评论功能 [plugin-comment-widget](https://github.com/halo-sigs/plugin-comment-widget/releases)
|
||||
- 搜索功能 [plugin-search-widget](https://github.com/halo-sigs/plugin-search-widget/releases)
|
||||
- 友链页面 [plugin-links](https://github.com/halo-sigs/plugin-links)
|
||||
- 瞬间页面 [plugin-moments](https://github.com/halo-sigs/plugin-moments)
|
||||
- 追番插件 [plugin-bilibili-bangumi](https://github.com/Roozenlz/plugin-bilibili-bangumi)
|
||||
- 图库插件 [plugin-photos](https://github.com/halo-sigs/plugin-photos)
|
||||
- katex插件 [plugin-katex](https://github.com/chengzhongxue/plugin-katex/releases/)
|
||||
- 我的装备 [plugin-equipments](https://github.com/chengzhongxue/plugin-equipments)
|
||||
- Markdown / HTML 内容块插件 [plugin-hybrid-edit-block](https://www.halo.run/store/apps/app-NgHnY)
|
||||
|
||||
> 更多插件请参见:https://github.com/halo-sigs/awesome-halo
|
||||
|
||||
## 📝 使用
|
||||
|
||||
[点我查看](https://www.yuque.com/liuzhihangs/halo-theme-hao)
|
File diff suppressed because it is too large
Load Diff
@ -2,352 +2,358 @@ var btf = {
|
||||
|
||||
|
||||
|
||||
// 修改时间显示"最近"
|
||||
diffDateExact: function (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;
|
||||
// 修改时间显示"最近"
|
||||
diffDateExact: function(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;
|
||||
|
||||
let result;
|
||||
if (more) {
|
||||
const monthCount = dateDiff / month;
|
||||
const dayCount = dateDiff / day;
|
||||
const hourCount = dateDiff / hour;
|
||||
const minuteCount = dateDiff / minute;
|
||||
let result;
|
||||
if (more) {
|
||||
const monthCount = dateDiff / month;
|
||||
const dayCount = dateDiff / day;
|
||||
const hourCount = dateDiff / hour;
|
||||
const minuteCount = dateDiff / minute;
|
||||
|
||||
if (monthCount >= 1) {
|
||||
result = datePost.toLocaleDateString().replace(/\//g, "-");
|
||||
} else if (dayCount >= 1) {
|
||||
result = parseInt(dayCount) + " " + GLOBAL_CONFIG.date_suffix.day;
|
||||
} else if (hourCount >= 1) {
|
||||
result = parseInt(hourCount) + " " + GLOBAL_CONFIG.date_suffix.hour;
|
||||
} else if (minuteCount >= 1) {
|
||||
result = parseInt(minuteCount) + " " + GLOBAL_CONFIG.date_suffix.min;
|
||||
} else {
|
||||
result = GLOBAL_CONFIG.date_suffix.just;
|
||||
}
|
||||
} else {
|
||||
result = parseInt(dateDiff / day);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
if (monthCount >= 1) {
|
||||
result = datePost.toLocaleDateString().replace(/\//g, "-");
|
||||
} else if (dayCount >= 1) {
|
||||
result = parseInt(dayCount) + " " + GLOBAL_CONFIG.date_suffix.day;
|
||||
} else if (hourCount >= 1) {
|
||||
result = parseInt(hourCount) + " " + GLOBAL_CONFIG.date_suffix.hour;
|
||||
} else if (minuteCount >= 1) {
|
||||
result = parseInt(minuteCount) + " " + GLOBAL_CONFIG.date_suffix.min;
|
||||
} else {
|
||||
result = GLOBAL_CONFIG.date_suffix.just;
|
||||
}
|
||||
} else {
|
||||
result = parseInt(dateDiff / day);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
loadLightbox: ele => {
|
||||
loadLightbox: ele => {
|
||||
|
||||
const jqLoadAndRun = () => {
|
||||
const $fancyboxEle = GLOBAL_CONFIG.lightbox === 'fancybox'
|
||||
? ele
|
||||
: []
|
||||
const fbLengthNoZero = $fancyboxEle.length > 0
|
||||
const jqLoadAndRun = () => {
|
||||
const $fancyboxEle = GLOBAL_CONFIG.lightbox === 'fancybox' ?
|
||||
ele :
|
||||
[]
|
||||
const fbLengthNoZero = $fancyboxEle.length > 0
|
||||
|
||||
if (fbLengthNoZero) {
|
||||
btf.isJqueryLoad(() => {
|
||||
fbLengthNoZero && addFancybox($fancyboxEle)
|
||||
})
|
||||
}
|
||||
}
|
||||
if (fbLengthNoZero) {
|
||||
btf.isJqueryLoad(() => {
|
||||
fbLengthNoZero && addFancybox($fancyboxEle)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fancybox
|
||||
*/
|
||||
const addFancybox = function (ele) {
|
||||
const runFancybox = (ele) => {
|
||||
ele.each(function (i, o) {
|
||||
const $this = $(o)
|
||||
const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
|
||||
const dataCaption = $this.attr('alt') || ''
|
||||
$this.wrap(`<a href="${lazyloadSrc}" data-fancybox="images" data-caption="${dataCaption}" class="fancybox" data-srcset="${lazyloadSrc}"></a>`)
|
||||
})
|
||||
/**
|
||||
* fancybox
|
||||
*/
|
||||
const addFancybox = function(ele) {
|
||||
const runFancybox = (ele) => {
|
||||
ele.each(function(i, o) {
|
||||
const $this = $(o)
|
||||
const lazyloadSrc = $this.attr('data-lazy-src') || $this.attr('src')
|
||||
const dataCaption = $this.attr('alt') || ''
|
||||
$this.wrap(
|
||||
`<a href="${lazyloadSrc}" data-fancybox="images" data-caption="${dataCaption}" class="fancybox" data-srcset="${lazyloadSrc}"></a>`
|
||||
)
|
||||
})
|
||||
|
||||
$().fancybox({
|
||||
selector: '[data-fancybox]',
|
||||
loop: true,
|
||||
transitionEffect: 'slide',
|
||||
protect: true,
|
||||
buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
|
||||
hash: false
|
||||
})
|
||||
}
|
||||
$().fancybox({
|
||||
selector: '[data-fancybox]',
|
||||
loop: true,
|
||||
transitionEffect: 'slide',
|
||||
protect: true,
|
||||
buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
|
||||
hash: false
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof $.fancybox === 'undefined') {
|
||||
// $('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`)
|
||||
$.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function () {
|
||||
runFancybox($(ele))
|
||||
})
|
||||
} else {
|
||||
runFancybox($(ele))
|
||||
}
|
||||
}
|
||||
if (typeof $.fancybox === 'undefined') {
|
||||
// $('head').append(`<link rel="stylesheet" type="text/css" href="${GLOBAL_CONFIG.source.fancybox.css}">`)
|
||||
$.getScript(`${GLOBAL_CONFIG.source.fancybox.js}`, function() {
|
||||
runFancybox($(ele))
|
||||
})
|
||||
} else {
|
||||
runFancybox($(ele))
|
||||
}
|
||||
}
|
||||
|
||||
jqLoadAndRun()
|
||||
jqLoadAndRun()
|
||||
|
||||
},
|
||||
debounce: function (func, wait, immediate) {
|
||||
let timeout
|
||||
return function () {
|
||||
const context = this
|
||||
const args = arguments
|
||||
const later = function () {
|
||||
timeout = null
|
||||
if (!immediate) func.apply(context, args)
|
||||
}
|
||||
const callNow = immediate && !timeout
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(later, wait)
|
||||
if (callNow) func.apply(context, args)
|
||||
}
|
||||
},
|
||||
},
|
||||
debounce: function(func, wait, immediate) {
|
||||
let timeout
|
||||
return function() {
|
||||
const context = this
|
||||
const args = arguments
|
||||
const later = function() {
|
||||
timeout = null
|
||||
if (!immediate) func.apply(context, args)
|
||||
}
|
||||
const callNow = immediate && !timeout
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(later, wait)
|
||||
if (callNow) func.apply(context, args)
|
||||
}
|
||||
},
|
||||
|
||||
throttle: function (func, wait, options) {
|
||||
let timeout, context, args
|
||||
let previous = 0
|
||||
if (!options) options = {}
|
||||
throttle: function(func, wait, options) {
|
||||
let timeout, context, args
|
||||
let previous = 0
|
||||
if (!options) options = {}
|
||||
|
||||
const later = function () {
|
||||
previous = options.leading === false ? 0 : new Date().getTime()
|
||||
timeout = null
|
||||
func.apply(context, args)
|
||||
if (!timeout) context = args = null
|
||||
}
|
||||
const later = function() {
|
||||
previous = options.leading === false ? 0 : new Date().getTime()
|
||||
timeout = null
|
||||
func.apply(context, args)
|
||||
if (!timeout) context = args = null
|
||||
}
|
||||
|
||||
const throttled = function () {
|
||||
const now = new Date().getTime()
|
||||
if (!previous && options.leading === false) previous = now
|
||||
const remaining = wait - (now - previous)
|
||||
context = this
|
||||
args = arguments
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout)
|
||||
timeout = null
|
||||
}
|
||||
previous = now
|
||||
func.apply(context, args)
|
||||
if (!timeout) context = args = null
|
||||
} else if (!timeout && options.trailing !== false) {
|
||||
timeout = setTimeout(later, remaining)
|
||||
}
|
||||
}
|
||||
const throttled = function() {
|
||||
const now = new Date().getTime()
|
||||
if (!previous && options.leading === false) previous = now
|
||||
const remaining = wait - (now - previous)
|
||||
context = this
|
||||
args = arguments
|
||||
if (remaining <= 0 || remaining > wait) {
|
||||
if (timeout) {
|
||||
clearTimeout(timeout)
|
||||
timeout = null
|
||||
}
|
||||
previous = now
|
||||
func.apply(context, args)
|
||||
if (!timeout) context = args = null
|
||||
} else if (!timeout && options.trailing !== false) {
|
||||
timeout = setTimeout(later, remaining)
|
||||
}
|
||||
}
|
||||
|
||||
return throttled
|
||||
},
|
||||
return throttled
|
||||
},
|
||||
|
||||
sidebarPaddingR: () => {
|
||||
const innerWidth = window.innerWidth
|
||||
const clientWidth = document.body.clientWidth
|
||||
const paddingRight = innerWidth - clientWidth
|
||||
if (innerWidth !== clientWidth) {
|
||||
document.body.style.paddingRight = paddingRight + 'px'
|
||||
}
|
||||
},
|
||||
sidebarPaddingR: () => {
|
||||
const innerWidth = window.innerWidth
|
||||
const clientWidth = document.body.clientWidth
|
||||
const paddingRight = innerWidth - clientWidth
|
||||
if (innerWidth !== clientWidth) {
|
||||
document.body.style.paddingRight = paddingRight + 'px'
|
||||
}
|
||||
},
|
||||
|
||||
snackbarShow: (text, showActionFunction = false, duration = 2000, actionText = false) => {
|
||||
const { position, bgLight, bgDark } = GLOBAL_CONFIG.Snackbar;
|
||||
const bg = document.documentElement.getAttribute("data-theme") === "light" ? bgLight : bgDark;
|
||||
const root = document.querySelector(":root");
|
||||
root.style.setProperty("--heo-snackbar-time", duration + "ms");
|
||||
snackbarShow: (text, showActionFunction = false, duration = 2000, actionText = false) => {
|
||||
const {
|
||||
position,
|
||||
bgLight,
|
||||
bgDark
|
||||
} = GLOBAL_CONFIG.Snackbar;
|
||||
const bg = document.documentElement.getAttribute("data-theme") === "light" ? bgLight : bgDark;
|
||||
const root = document.querySelector(":root");
|
||||
root.style.setProperty("--heo-snackbar-time", duration + "ms");
|
||||
|
||||
Snackbar.show({
|
||||
text: text,
|
||||
backgroundColor: bg,
|
||||
onActionClick: showActionFunction,
|
||||
actionText: actionText,
|
||||
showAction: actionText,
|
||||
duration: duration,
|
||||
pos: position,
|
||||
customClass: "snackbar-css",
|
||||
});
|
||||
},
|
||||
Snackbar.show({
|
||||
text: text,
|
||||
backgroundColor: bg,
|
||||
onActionClick: showActionFunction,
|
||||
actionText: actionText,
|
||||
showAction: actionText,
|
||||
duration: duration,
|
||||
pos: position,
|
||||
customClass: "snackbar-css",
|
||||
});
|
||||
},
|
||||
|
||||
initJustifiedGallerys: function (selector) {
|
||||
selector.forEach((function(t) {
|
||||
btf.isHidden(t) || fjGallery(t, {
|
||||
itemSelector: ".fj-gallery-item",
|
||||
rowHeight: 240,
|
||||
gutter: 4,
|
||||
onJustify: function() {
|
||||
this.$container.style.opacity = "1"
|
||||
}
|
||||
})
|
||||
}
|
||||
))
|
||||
document.querySelectorAll('#article-container .loadings')[0]?.classList.remove("loadings");
|
||||
},
|
||||
initJustifiedGallerys: function(selector) {
|
||||
selector.forEach((function(t) {
|
||||
btf.isHidden(t) || fjGallery(t, {
|
||||
itemSelector: ".fj-gallery-item",
|
||||
rowHeight: 240,
|
||||
gutter: 4,
|
||||
onJustify: function() {
|
||||
this.$container.style.opacity = "1"
|
||||
}
|
||||
})
|
||||
}))
|
||||
document.querySelectorAll('#article-container .loadings')[0]?.classList.remove("loadings");
|
||||
},
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
let result
|
||||
if (more) {
|
||||
const monthCount = dateDiff / month
|
||||
const dayCount = dateDiff / day
|
||||
const hourCount = dateDiff / hour
|
||||
const minuteCount = dateDiff / minute
|
||||
let result
|
||||
if (more) {
|
||||
const monthCount = dateDiff / month
|
||||
const dayCount = dateDiff / day
|
||||
const hourCount = dateDiff / hour
|
||||
const minuteCount = dateDiff / minute
|
||||
|
||||
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
|
||||
},
|
||||
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()
|
||||
}
|
||||
},
|
||||
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: (e,t)=>{
|
||||
if (e < 0 || t < 0)
|
||||
return;
|
||||
const n = window.scrollY || window.screenTop;
|
||||
if (e -= 70,
|
||||
"CSS"in window && CSS.supports("scroll-behavior", "smooth"))
|
||||
return void window.scrollTo({
|
||||
top: e,
|
||||
behavior: "smooth"
|
||||
});
|
||||
let o = null;
|
||||
t = t || 500,
|
||||
window.requestAnimationFrame((function i(s) {
|
||||
if (o = o || s,
|
||||
n < e) {
|
||||
const r = s - o;
|
||||
window.scrollTo(0, (e - n) * r / t + n),
|
||||
r < t ? window.requestAnimationFrame(i) : window.scrollTo(0, e)
|
||||
} else {
|
||||
const r = s - o;
|
||||
window.scrollTo(0, n - (n - e) * r / t),
|
||||
r < t ? window.requestAnimationFrame(i) : window.scrollTo(0, e)
|
||||
}
|
||||
}
|
||||
))
|
||||
},
|
||||
scrollToDest: (e, t) => {
|
||||
if (e < 0 || t < 0)
|
||||
return;
|
||||
const n = window.scrollY || window.screenTop;
|
||||
if (e -= 70,
|
||||
"CSS" in window && CSS.supports("scroll-behavior", "smooth"))
|
||||
return void window.scrollTo({
|
||||
top: e,
|
||||
behavior: "smooth"
|
||||
});
|
||||
let o = null;
|
||||
t = t || 500,
|
||||
window.requestAnimationFrame((function i(s) {
|
||||
if (o = o || s,
|
||||
n < e) {
|
||||
const r = s - o;
|
||||
window.scrollTo(0, (e - n) * r / t + n),
|
||||
r < t ? window.requestAnimationFrame(i) : window.scrollTo(0, e)
|
||||
} else {
|
||||
const r = s - o;
|
||||
window.scrollTo(0, n - (n - e) * r / t),
|
||||
r < t ? window.requestAnimationFrame(i) : window.scrollTo(0, e)
|
||||
}
|
||||
}))
|
||||
},
|
||||
|
||||
fadeIn: (ele, time) => {
|
||||
ele.style.cssText = `display:block;animation: to_show ${time}s`
|
||||
},
|
||||
fadeIn: (ele, time) => {
|
||||
ele.style.cssText = `display:block;animation: to_show ${time}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`
|
||||
},
|
||||
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) => {
|
||||
for (; elem && elem !== document; elem = elem.parentNode) {
|
||||
if (elem.matches(selector)) return elem
|
||||
}
|
||||
return null
|
||||
},
|
||||
getParents: (elem, selector) => {
|
||||
for (; elem && elem !== document; elem = elem.parentNode) {
|
||||
if (elem.matches(selector)) return elem
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
siblings: (ele, selector) => {
|
||||
return [...ele.parentNode.children].filter((child) => {
|
||||
if (selector) {
|
||||
return child !== ele && child.matches(selector)
|
||||
}
|
||||
return child !== ele
|
||||
})
|
||||
},
|
||||
siblings: (ele, selector) => {
|
||||
return [...ele.parentNode.children].filter((child) => {
|
||||
if (selector) {
|
||||
return child !== ele && child.matches(selector)
|
||||
}
|
||||
return child !== ele
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} selector
|
||||
* @param {*} eleType the type of create element
|
||||
* @param {*} id id
|
||||
* @param {*} cn class name
|
||||
*/
|
||||
wrap: function (selector, eleType, id = '', cn = '') {
|
||||
const creatEle = document.createElement(eleType)
|
||||
if (id) creatEle.id = id
|
||||
if (cn) creatEle.className = cn
|
||||
selector.parentNode.insertBefore(creatEle, selector)
|
||||
creatEle.appendChild(selector)
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @param {*} selector
|
||||
* @param {*} eleType the type of create element
|
||||
* @param {*} id id
|
||||
* @param {*} cn class name
|
||||
*/
|
||||
wrap: function(selector, eleType, id = '', cn = '') {
|
||||
const creatEle = document.createElement(eleType)
|
||||
if (id) creatEle.id = id
|
||||
if (cn) creatEle.className = cn
|
||||
selector.parentNode.insertBefore(creatEle, selector)
|
||||
creatEle.appendChild(selector)
|
||||
},
|
||||
|
||||
unwrap: function (el) {
|
||||
const elParentNode = el.parentNode
|
||||
if (elParentNode !== document.body) {
|
||||
elParentNode.parentNode.insertBefore(el, elParentNode)
|
||||
elParentNode.parentNode.removeChild(elParentNode)
|
||||
}
|
||||
},
|
||||
unwrap: function(el) {
|
||||
const elParentNode = el.parentNode
|
||||
if (elParentNode !== document.body) {
|
||||
elParentNode.parentNode.insertBefore(el, elParentNode)
|
||||
elParentNode.parentNode.removeChild(elParentNode)
|
||||
}
|
||||
},
|
||||
|
||||
isJqueryLoad: (fn) => {
|
||||
if (typeof jQuery === 'undefined') {
|
||||
getScript(GLOBAL_CONFIG.source.jQuery).then(fn)
|
||||
} else {
|
||||
fn()
|
||||
}
|
||||
},
|
||||
isJqueryLoad: (fn) => {
|
||||
if (typeof jQuery === 'undefined') {
|
||||
getScript(GLOBAL_CONFIG.source.jQuery).then(fn)
|
||||
} else {
|
||||
fn()
|
||||
}
|
||||
},
|
||||
|
||||
isHidden: (ele) => ele.offsetHeight === 0 && ele.offsetWidth === 0,
|
||||
isHidden: (ele) => ele.offsetHeight === 0 && ele.offsetWidth === 0,
|
||||
|
||||
getEleTop: (ele) => {
|
||||
let actualTop = ele.offsetTop
|
||||
let current = ele.offsetParent
|
||||
getEleTop: (ele) => {
|
||||
let actualTop = ele.offsetTop
|
||||
let current = ele.offsetParent
|
||||
|
||||
while (current !== null) {
|
||||
actualTop += current.offsetTop
|
||||
current = current.offsetParent
|
||||
}
|
||||
while (current !== null) {
|
||||
actualTop += current.offsetTop
|
||||
current = current.offsetParent
|
||||
}
|
||||
|
||||
return actualTop
|
||||
},
|
||||
//过滤标签
|
||||
changeContent: (content,length = null)=>{
|
||||
if (content === '') return content
|
||||
return actualTop
|
||||
},
|
||||
//过滤标签
|
||||
changeContent: (content, length = null) => {
|
||||
if (content === '') return content
|
||||
|
||||
content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[图片]') // replace image link
|
||||
content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
|
||||
content = content.replace(/<pre><code>.*?<\/pre>/gi, '[代码]') // replace code
|
||||
content = content.replace(/<[^>]+>/g, "") // remove html tag
|
||||
content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[图片]') // replace image link
|
||||
content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
|
||||
content = content.replace(/<pre><code>.*?<\/pre>/gi, '[代码]') // replace code
|
||||
content = content.replace(/<[^>]+>/g, "") // remove html tag
|
||||
|
||||
if (length!=null){
|
||||
if (content.length > length) {
|
||||
content = content.substring(0, length) + '...'
|
||||
}
|
||||
}
|
||||
if (length != null) {
|
||||
if (content.length > length) {
|
||||
content = content.substring(0, length) + '...'
|
||||
}
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -3,26 +3,26 @@ let rm = {};
|
||||
|
||||
//禁止图片拖拽
|
||||
rm.stopdragimg = $("img");
|
||||
rm.stopdragimg.on("dragstart", function () {
|
||||
return false;
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// 隐藏菜单
|
||||
rm.hideRightMenu = function () {
|
||||
rm.showRightMenu(false);
|
||||
$('#rightmenu-mask').attr('style', 'display: none');
|
||||
rm.hideRightMenu = function() {
|
||||
rm.showRightMenu(false);
|
||||
$('#rightmenu-mask').attr('style', 'display: none');
|
||||
}
|
||||
|
||||
// 尺寸
|
||||
@ -30,9 +30,9 @@ let rmWidth = $('#rightMenu').width();
|
||||
let rmHeight = $('#rightMenu').height();
|
||||
|
||||
// 重新定义尺寸
|
||||
rm.reloadrmSize = function () {
|
||||
rmWidth = $('#rightMenu').width();
|
||||
rmHeight = $('#rightMenu').height();
|
||||
rm.reloadrmSize = function() {
|
||||
rmWidth = $('#rightMenu').width();
|
||||
rmHeight = $('#rightMenu').height();
|
||||
}
|
||||
|
||||
// 获取点击的href
|
||||
@ -41,225 +41,227 @@ 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);
|
||||
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 $rightMenuNewWindowImg = $('#menu-newwindowimg');
|
||||
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 $rightMenuOther = $('.rightMenuOther');
|
||||
let $rightMenuPlugin = $('.rightMenuPlugin');
|
||||
let $rightMenuCopyText = $('#menu-copytext');
|
||||
let $rightMenuPasteText = $('#menu-pastetext');
|
||||
let $rightMenuCommentText = $('#menu-commenttext');
|
||||
let $rightMenuNewWindow = $('#menu-newwindow');
|
||||
let $rightMenuNewWindowImg = $('#menu-newwindowimg');
|
||||
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;
|
||||
// 判断模式 扩展模式为有事件
|
||||
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();
|
||||
}
|
||||
// 检查是否需要复制 是否有选中文本
|
||||
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();
|
||||
}
|
||||
//检查是否右键点击了链接a标签
|
||||
if (href) {
|
||||
pluginMode = true;
|
||||
$rightMenuNewWindow.show();
|
||||
$rightMenuCopyLink.show();
|
||||
domhref = href;
|
||||
} else {
|
||||
$rightMenuNewWindow.hide();
|
||||
$rightMenuCopyLink.hide();
|
||||
}
|
||||
|
||||
//检查是否需要复制图片
|
||||
if (imgsrc) {
|
||||
pluginMode = true;
|
||||
$rightMenuCopyImg.show();
|
||||
$rightMenuDownloadImg.show();
|
||||
$rightMenuNewWindowImg.show();
|
||||
domImgSrc = imgsrc;
|
||||
} else {
|
||||
$rightMenuCopyImg.hide();
|
||||
$rightMenuDownloadImg.hide();
|
||||
$rightMenuNewWindowImg.hide();
|
||||
}
|
||||
//检查是否需要复制图片
|
||||
if (imgsrc) {
|
||||
pluginMode = true;
|
||||
$rightMenuCopyImg.show();
|
||||
$rightMenuDownloadImg.show();
|
||||
$rightMenuNewWindowImg.show();
|
||||
domImgSrc = imgsrc;
|
||||
} else {
|
||||
$rightMenuCopyImg.hide();
|
||||
$rightMenuDownloadImg.hide();
|
||||
$rightMenuNewWindowImg.hide();
|
||||
}
|
||||
|
||||
// 判断是否为输入框
|
||||
if (event.target.tagName.toLowerCase() === 'input' || event.target.tagName.toLowerCase() === 'textarea') {
|
||||
console.log('这是一个输入框')
|
||||
pluginMode = true;
|
||||
$rightMenuPasteText.show();
|
||||
} else {
|
||||
$rightMenuPasteText.hide();
|
||||
}
|
||||
// 判断是否为输入框
|
||||
if (event.target.tagName.toLowerCase() === 'input' || event.target.tagName.toLowerCase() === 'textarea') {
|
||||
console.log('这是一个输入框')
|
||||
pluginMode = true;
|
||||
$rightMenuPasteText.show();
|
||||
} else {
|
||||
$rightMenuPasteText.hide();
|
||||
}
|
||||
|
||||
//判断是否是音乐
|
||||
const navMusicEl = document.querySelector("#nav-music");
|
||||
if (navMusicEl && navMusicEl.contains(event.target)) {
|
||||
pluginMode = true;
|
||||
$rightMenuMusicToggle.show();
|
||||
$rightMenuMusicBack.show();
|
||||
$rightMenuMusicForward.show();
|
||||
$rightMenuMusicPlaylist.show();
|
||||
$rightMenuMusicCopyMusicName.show();
|
||||
} else {
|
||||
$rightMenuMusicToggle.hide();
|
||||
$rightMenuMusicBack.hide();
|
||||
$rightMenuMusicForward.hide();
|
||||
$rightMenuMusicPlaylist.hide();
|
||||
$rightMenuMusicCopyMusicName.hide()
|
||||
}
|
||||
//判断是否是音乐
|
||||
const navMusicEl = document.querySelector("#nav-music");
|
||||
if (navMusicEl && navMusicEl.contains(event.target)) {
|
||||
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()
|
||||
}
|
||||
// 如果不是扩展模式则隐藏扩展模块
|
||||
if (pluginMode) {
|
||||
$rightMenuOther.hide();
|
||||
$rightMenuPlugin.show();
|
||||
} else {
|
||||
$rightMenuPlugin.hide()
|
||||
}
|
||||
|
||||
rm.reloadrmSize()
|
||||
rm.reloadrmSize()
|
||||
|
||||
// 鼠标默认显示在鼠标右下方,当鼠标靠右或考下时,将菜单显示在鼠标左方\上方
|
||||
if (pageX + rmWidth > window.innerWidth) {
|
||||
pageX -= rmWidth + 10;
|
||||
}
|
||||
if (pageY + rmHeight > window.innerHeight) {
|
||||
pageY -= pageY + rmHeight - window.innerHeight;
|
||||
}
|
||||
// 鼠标默认显示在鼠标右下方,当鼠标靠右或考下时,将菜单显示在鼠标左方\上方
|
||||
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;
|
||||
}
|
||||
rm.showRightMenu(true, pageY, pageX);
|
||||
$('#rightmenu-mask').attr('style', 'display: flex');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 下载图片状态
|
||||
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")
|
||||
}
|
||||
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 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);
|
||||
};
|
||||
})
|
||||
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);
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
async function copyImage(imageURL) {
|
||||
const blob = await imageToBlob(imageURL)
|
||||
const item = new ClipboardItem({"image/png": blob});
|
||||
navigator.clipboard.write([item]);
|
||||
const blob = await imageToBlob(imageURL)
|
||||
const item = new ClipboardItem({
|
||||
"image/png": blob
|
||||
});
|
||||
navigator.clipboard.write([item]);
|
||||
}
|
||||
|
||||
rm.switchDarkMode = function () {
|
||||
navFn.switchDarkMode();
|
||||
rm.hideRightMenu();
|
||||
rm.switchDarkMode = function() {
|
||||
navFn.switchDarkMode();
|
||||
rm.hideRightMenu();
|
||||
|
||||
//halo.darkComment();
|
||||
//halo.darkComment();
|
||||
}
|
||||
|
||||
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();
|
||||
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() {
|
||||
if (document.getElementById("rightmenu-mask")) {
|
||||
let xscroll = document.getElementById("rightmenu-mask");
|
||||
xscroll.addEventListener("mousewheel", function (e) {
|
||||
//阻止浏览器默认方法
|
||||
rm.hideRightMenu();
|
||||
// e.preventDefault();
|
||||
}, false);
|
||||
}
|
||||
if (document.getElementById("rightMenu")) {
|
||||
let xscroll = document.getElementById("rightMenu");
|
||||
xscroll.addEventListener("mousewheel", function (e) {
|
||||
//阻止浏览器默认方法
|
||||
rm.hideRightMenu();
|
||||
// e.preventDefault();
|
||||
}, false);
|
||||
}
|
||||
if (document.getElementById("rightmenu-mask")) {
|
||||
let xscroll = document.getElementById("rightmenu-mask");
|
||||
xscroll.addEventListener("mousewheel", function(e) {
|
||||
//阻止浏览器默认方法
|
||||
rm.hideRightMenu();
|
||||
// e.preventDefault();
|
||||
}, false);
|
||||
}
|
||||
if (document.getElementById("rightMenu")) {
|
||||
let xscroll = document.getElementById("rightMenu");
|
||||
xscroll.addEventListener("mousewheel", function(e) {
|
||||
//阻止浏览器默认方法
|
||||
rm.hideRightMenu();
|
||||
// e.preventDefault();
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
|
||||
rm.rightmenuCopyText = function (txt) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(txt);
|
||||
}
|
||||
rm.hideRightMenu();
|
||||
rm.rightmenuCopyText = function(txt) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(txt);
|
||||
}
|
||||
rm.hideRightMenu();
|
||||
}
|
||||
|
||||
rm.copyPageUrl = function () {
|
||||
var url = window.location.href;
|
||||
rm.copyUrl(url);
|
||||
btf.snackbarShow('复制本页链接地址成功', false, 2000);
|
||||
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();
|
||||
rm.sharePage = function() {
|
||||
var content = window.location.href;
|
||||
rm.copyUrl(url);
|
||||
btf.snackbarShow('复制本页链接地址成功', false, 2000);
|
||||
rm.hideRightMenu();
|
||||
}
|
||||
|
||||
// 复制当前选中文本
|
||||
@ -267,160 +269,161 @@ var selectTextNow = '';
|
||||
document.onmouseup = document.ondbclick = selceText;
|
||||
|
||||
function selceText() {
|
||||
var txt;
|
||||
if (document.selection) {
|
||||
txt = document.selection.createRange().text;
|
||||
} else {
|
||||
txt = window.getSelection() + '';
|
||||
}
|
||||
if (txt) {
|
||||
selectTextNow = txt;
|
||||
// console.log(selectTextNow);
|
||||
} else {
|
||||
selectTextNow = '';
|
||||
}
|
||||
var txt;
|
||||
if (document.selection) {
|
||||
txt = document.selection.createRange().text;
|
||||
} else {
|
||||
txt = window.getSelection() + '';
|
||||
}
|
||||
if (txt) {
|
||||
selectTextNow = txt;
|
||||
// console.log(selectTextNow);
|
||||
} else {
|
||||
selectTextNow = '';
|
||||
}
|
||||
}
|
||||
|
||||
// 读取剪切板
|
||||
rm.readClipboard = function () {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.readText().then(clipText => rm.insertAtCaret(globalEvent.target, clipText));
|
||||
}
|
||||
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.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.pasteText = function() {
|
||||
const result = rm.readClipboard() || '';
|
||||
rm.hideRightMenu();
|
||||
}
|
||||
|
||||
//引用到评论
|
||||
rm.rightMenuCommentText = function (txt) {
|
||||
rm.hideRightMenu();
|
||||
var input = document.getElementsByClassName(GLOBAL_CONFIG.source.comments.textarea)[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");
|
||||
}
|
||||
rm.rightMenuCommentText = function(txt) {
|
||||
rm.hideRightMenu();
|
||||
var input = document.getElementsByClassName(GLOBAL_CONFIG.source.comments.textarea)[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);
|
||||
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.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('已复制链接地址');
|
||||
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 () {
|
||||
rm.hideRightMenu();
|
||||
return false;
|
||||
});
|
||||
$('#menu-translate').on('click', function () {
|
||||
rm.hideRightMenu();
|
||||
});
|
||||
$('#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, 'hao');
|
||||
});
|
||||
$('#menu-newwindowimg').on('click', function () {
|
||||
window.open(domImgSrc, "_blank");
|
||||
rm.hideRightMenu();
|
||||
});
|
||||
$('#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);
|
||||
});
|
||||
}
|
||||
// 添加点击事件
|
||||
$('#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() {
|
||||
rm.hideRightMenu();
|
||||
return false;
|
||||
});
|
||||
$('#menu-translate').on('click', function() {
|
||||
rm.hideRightMenu();
|
||||
});
|
||||
$('#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, 'hao');
|
||||
});
|
||||
$('#menu-newwindowimg').on('click', function() {
|
||||
window.open(domImgSrc, "_blank");
|
||||
rm.hideRightMenu();
|
||||
});
|
||||
$('#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);
|
||||
});
|
||||
}
|
@ -1,81 +1,81 @@
|
||||
<!-- 导航栏菜单栏 -->
|
||||
<div id="nav-right">
|
||||
|
||||
<!-- 功能都需要添加开关 -->
|
||||
<!-- 功能都需要添加开关 -->
|
||||
|
||||
<!-- 随机前往一个开往项目网站 -->
|
||||
<div class="nav-button only-home" id="travellings_button" title="随机前往一个开往项目网站" th:if="${theme.config.nav.right.travelling}">
|
||||
<a class="site-page" href="https://www.travellings.cn/go.html" rel="external nofollow"
|
||||
title="随机前往一个开往项目网站">
|
||||
<i class="haofont hao-icon-eicon_train-line"></i>
|
||||
</a>
|
||||
</div>
|
||||
<!-- 随机前往一个开往项目网站 -->
|
||||
<div class="nav-button only-home" id="travellings_button" title="随机前往一个开往项目网站"
|
||||
th:if="${theme.config.nav.right.travelling}">
|
||||
<a class="site-page" href="https://www.travellings.cn/go.html" rel="external nofollow" title="随机前往一个开往项目网站">
|
||||
<i class="haofont hao-icon-eicon_train-line"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="nav-button" id="randomPost_button" th:if="${theme.config.nav.right.article}">
|
||||
<a class="site-page" href="javascript:void(0);" onclick="toRandomPost()" title="随机文章">
|
||||
<i class="haofont hao-icon-signal-tower-fill"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-button" id="randomPost_button" th:if="${theme.config.nav.right.article}">
|
||||
<a class="site-page" href="javascript:void(0);" onclick="toRandomPost()" title="随机文章">
|
||||
<i class="haofont hao-icon-signal-tower-fill"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 切换模式 -->
|
||||
<div class="nav-button" id="darkmode_button" th:if="${theme.config.nav.right.darkMode}">
|
||||
<a class="console_switchbutton" href="javascript:void(0);" onclick="navFn.switchDarkMode();" rel="external nofollow"
|
||||
title="切换模式 - 日夜交替,黑白互换。">
|
||||
<i class="haofont hao-icon-moon-clear-fill" style="font-size: 1rem;"></i>
|
||||
</a>
|
||||
</div>
|
||||
<!-- 切换模式 -->
|
||||
<div class="nav-button" id="darkmode_button" th:if="${theme.config.nav.right.darkMode}">
|
||||
<a class="console_switchbutton" href="javascript:void(0);" onclick="navFn.switchDarkMode();"
|
||||
rel="external nofollow" title="切换模式 - 日夜交替,黑白互换。">
|
||||
<i class="haofont hao-icon-moon-clear-fill" style="font-size: 1rem;"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 搜索使用搜索插件 -->
|
||||
<div class="nav-button" id="search-button" th:if="${pluginFinder.available('PluginSearchWidget')}">
|
||||
<a class="site-page social-icon search" href="javascript:SearchWidget.open();" rel="external nofollow"
|
||||
title="站内搜索">
|
||||
<i class="haofont hao-icon-search--line"></i>
|
||||
</a>
|
||||
</div>
|
||||
<!-- 搜索使用搜索插件 -->
|
||||
<div class="nav-button" id="search-button" th:if="${pluginFinder.available('PluginSearchWidget')}">
|
||||
<a class="site-page social-icon search" href="javascript:SearchWidget.open();" rel="external nofollow"
|
||||
title="站内搜索">
|
||||
<i class="haofont hao-icon-search--line"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div th:if="${theme.config.nav.right.navLogin}" class="console-button" tabindex="-1"
|
||||
th:with="currentUser = ${contributorFinder.getContributor(#authentication.name)}">
|
||||
<span class="site-page nav-login">
|
||||
<i sec:authorize="isAnonymous()" class="haofont hao-icon-zhanghao1 " style="font-size: 19.5px;"></i>
|
||||
<img sec:authorize="isAuthenticated()" th:src="${currentUser.avatar}"
|
||||
th:alt="${currentUser.displayName}"
|
||||
style=" width: 24px; height: 24px; border-radius: 9999px" />
|
||||
</span>
|
||||
<div class="back-menu-list-groups">
|
||||
<div class="back-menu-list-group" style="margin: -4px -9px -4px -18px">
|
||||
<div class="back-menu-list">
|
||||
<th:block sec:authorize="isAuthenticated()">
|
||||
<a class="back-menu-item" rel="external nofollow" target="_blank" href="/console">
|
||||
<span class="back-menu-item-text">控制台</span>
|
||||
</a>
|
||||
<a class="back-menu-item" rel="external nofollow"
|
||||
href="javascript:$.ajax({type: 'post',url:'/logout'});window.location.reload()">
|
||||
<span class="back-menu-item-text">退出登录</span>
|
||||
</a>
|
||||
</th:block>
|
||||
<a sec:authorize="isAnonymous()" class="back-menu-item" rel="external nofollow" target="_blank" href="/console/login">
|
||||
<span class="back-menu-item-text">登录</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div th:if="${theme.config.nav.right.console.consoleEnable}" class="nav-button" id="nav-console">
|
||||
<a class="console_switchbutton" href="javascript:void(0);" onclick="heo.showConsole()" rel="external nofollow"
|
||||
title="显示中控台">
|
||||
<i class="haofont hao-icon-dashboard"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div th:if="${theme.config.nav.right.navLogin}" class="console-button" tabindex="-1"
|
||||
th:with="currentUser = ${contributorFinder.getContributor(#authentication.name)}">
|
||||
<span class="site-page nav-login">
|
||||
<i sec:authorize="isAnonymous()" class="haofont hao-icon-zhanghao1 " style="font-size: 19.5px;"></i>
|
||||
<img sec:authorize="isAuthenticated()" th:src="${currentUser.avatar}" th:alt="${currentUser.displayName}"
|
||||
style=" width: 24px; height: 24px; border-radius: 9999px" />
|
||||
</span>
|
||||
<div class="back-menu-list-groups">
|
||||
<div class="back-menu-list-group" style="margin: -4px -9px -4px -18px">
|
||||
<div class="back-menu-list">
|
||||
<th:block sec:authorize="isAuthenticated()">
|
||||
<a class="back-menu-item" rel="external nofollow" target="_blank" href="/console">
|
||||
<span class="back-menu-item-text">控制台</span>
|
||||
</a>
|
||||
<a class="back-menu-item" rel="external nofollow"
|
||||
href="javascript:$.ajax({type: 'post',url:'/logout',headers:{'X-Xsrf-Token':document.cookie.split('; ').find((row) => row.startsWith('XSRF-TOKEN'))?.split('=')[1] || ''},success: function() {window.location.reload();},error: function(xhr, status, error) {console.error('退出登录时发生错误:', error);}});">
|
||||
<span class="back-menu-item-text">退出登录</span>
|
||||
</a>
|
||||
</th:block>
|
||||
<a sec:authorize="isAnonymous()" class="back-menu-item" rel="external nofollow" target="_blank"
|
||||
href="/console/login">
|
||||
<span class="back-menu-item-text">登录</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div th:if="${theme.config.nav.right.console.consoleEnable}" class="nav-button" id="nav-console">
|
||||
<a class="console_switchbutton" href="javascript:void(0);" onclick="heo.showConsole()" rel="external nofollow"
|
||||
title="显示中控台">
|
||||
<i class="haofont hao-icon-dashboard"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="nav-button" id="nav-totop" onclick="btf.scrollToDest(0,500)">
|
||||
<a class="totopbtn">
|
||||
<i class="haofont hao-icon-arrow-up" style="font-size: 1rem;"></i><span id="percent">0</span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="nav-button" id="nav-totop" onclick="btf.scrollToDest(0,500)">
|
||||
<a class="totopbtn">
|
||||
<i class="haofont hao-icon-arrow-up" style="font-size: 1rem;"></i><span id="percent">0</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div id="toggle-menu">
|
||||
<a class="site-page">
|
||||
<i class="haofont hao-icon-bars"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="toggle-menu">
|
||||
<a class="site-page">
|
||||
<i class="haofont hao-icon-bars"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
@ -48,8 +48,8 @@ spec:
|
||||
description: Halo 2.x Theme base on Thymeleaf, Referring to Butterfly and Heo
|
||||
logo: /themes/theme-hao/assets/images/hao-logo.jpg
|
||||
website: https://blog.uptoz.cn
|
||||
repo: https://githubfast.com/liuzhihang/halo-theme-hao
|
||||
repo: https://gitea.uptoz.cn/UPToZ/halo-theme-hao
|
||||
settingName: "theme-hao-setting"
|
||||
configMapName: "theme-hao-configMap"
|
||||
version: "1.4.9-CommemorativeEdition"
|
||||
version: "1.0.1-ce"
|
||||
require: ">=2.10.0"
|
||||
|
Loading…
Reference in New Issue
Block a user