// ==UserScript==
// @name NGA优化摸鱼体验
// @namespace http://tampermonkey.net/
// @version 1.2
// @require https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js
// @description NGA论坛隐藏切换显示头像,表情,图片等,防止突然蹦出一对??而导致的突然性的社会死亡
// @author HLD
// @match *bbs.nga.cn/*
// @match *ngabbs.com/*
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
let setting = {
hideAvatar: true,
hideSmile: true,
hideImage: false,
hideSign: true,
linkTargetBlank: true,
imgResize: true,
}
//同步配置
if(window.localStorage.getItem('hld__NGA_setting')){
let local_setting = JSON.parse(window.localStorage.getItem('hld__NGA_setting'))
for(let k in setting) {
!local_setting.hasOwnProperty(k) && (local_setting[k] = setting[k])
}
for(let k in local_setting) {
!setting.hasOwnProperty(k) && delete local_setting[k]
}
setting = local_setting
console.log(setting)
}
//注册按键
$('body').keyup(function(event){
if (/textarea|select|input/i.test(event.target.nodeName)
|| /text|password|number|email|url|range|date|month/i.test(event.target.type)) {
return;
}
//切换显示头像
if(event.keyCode == 81){
$('.avatar').toggle()
}
//切换显示表情
if(event.keyCode == 87){
$('img').each(function(){
const classs = $(this).attr('class');
if(classs && classs.indexOf('smile') > -1) $(this).toggle()
})
$('.smile_alt_text').toggle()
}
//切换显示图片
if(event.keyCode == 69){
$('.postcontent img').each(function(){
const classs = $(this).attr('class');
if(!classs && $(this).width() > 24) {
if($(this).is(":hidden")) {
$(this).show()
$('.switch-img').hide()
}else {
$('.switch-img').css('display', 'inline')
$(this).hide()
}
}
})
}
})
//动态检测
setInterval(()=>{
$('.forumbox.postbox[hld-render!=ok]').length > 0 && runDom()
$('#hld__setting').length == 0 && $('#startmenu > tbody > tr > td.last').append('
')
}, 100)
//大图
const resizeImg = (el) => {
if($('#hld__img_full').length > 0) return
let url_list = []
let current_index = el.parent().find('[hld__imglist=ready]').index(el)
el.parent().find('[hld__imglist=ready]').each(function(){
url_list.push($(this).data('srcorg') || $(this).data('srclazy') || $(this).attr('src'))
})
let $imgBox = $('')
$imgBox.click(function(){
$(this).remove()
})
$imgBox.append('')
$imgBox.on('click', '.change', function(){
if($(this).hasClass('prev-img') && current_index - 1 >= 0)
$img.attr('src', url_list[--current_index])
if($(this).hasClass('next-img') && current_index + 1 < url_list.length)
$img.attr('src', url_list[++current_index])
return false;
})
$imgBox.on("mousewheel DOMMouseScroll", function (e) {
const delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1))||
(e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));
if(delta > 0 && current_index - 1 >= 0) {
$img.attr('src', url_list[--current_index])
}
if(delta < 0 && current_index + 1 < url_list.length) {
$img.attr('src', url_list[++current_index])
}
e.stopPropagation()
return false
})
let $img = $('
')
$img.css('max-height', $(window).height() * 0.95 + 'px')
$img.attr('src', url_list[current_index])
$img.click(()=>{
window.open($img.attr('src'))
return false
})
$imgBox.find('.prev-img').after($img)
$('body').append($imgBox)
}
//新页面打开连接
setting.linkTargetBlank && $('.topic').attr('target', '_blank')
const runDom = () => {
$('.forumbox.postbox[hld-render!=ok]').each(function(){
//隐藏头像
setting.hideAvatar && $(this).find('.avatar').css('display', 'none')
//隐藏表情
$(this).find('img').each(function(){
const classs = $(this).attr('class');
if(classs && classs.indexOf('smile') > -1) {
const alt = $(this).attr('alt')
const $alt = $('[' + alt + ']')
setting.hideSmile ? $(this).hide() : $alt.hide()
$(this).after($alt)
}else if(!classs && $(this).attr('onload')) {
if(setting.imgResize) {
$(this).width() > 200 && $(this).css({'outline': '', 'outline-offset': '', 'cursor': 'pointer', 'min-width': '200px', 'min-height': 'auto', 'width': '200px', 'height': 'auto', 'margin:': '5px'}).attr('hld__imglist', 'ready')
}
let $imgB = $('')
$imgB.on('click', function(){
$(this).prev('img').toggle()
$(this).text($(this).prev('img').is(':hidden') ? '图' : '隐藏')
})
$(this).removeAttr('onload')
if(setting.hideImage) {
$(this).hide();
$imgB.show()
}
$(this).after($imgB)
}
})
//隐藏签名
setting.hideSign && $(this).find('.sign, .sigline').css('display', 'none')
//添加标志位
$(this).attr('hld-render', 'ok')
})
}
if(setting.imgResize) {
$('#m_posts').on('click', '.postcontent img', function(){
resizeImg($(this))
})
}
//设置面板
let $panel_dom = $(``)
let $panel_save_btn = $('')
$panel_save_btn.click(()=>{
for(let k in setting) {
$('#hld__cb_' + k).length > 0 && (setting[k] = $('#hld__cb_' + k)[0].checked)
}
window.localStorage.setItem('hld__NGA_setting', JSON.stringify(setting))
$panel_dom.hide()
popMsg('保存成功,刷新页面生效')
})
$panel_dom.append($panel_save_btn)
$('body').append($panel_dom)
//读取设置
for(let k in setting) {
$('#hld__cb_' + k).length > 0 && ($('#hld__cb_' + k)[0].checked = setting[k])
}
//消息
const popMsg = (msg) => {
alert(msg)
}
//样式
let style = document.createElement("style")
style.type = "text/css"
style.appendChild(document.createTextNode(`
.postcontent img {
margin: 0 5px 5px 0;
}
#hld__img_full{
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.6);
z-index: 99999;
display: flex;
align-items: center;
justify-content: center;
}
#hld__img_full img{
display:block;
width:auto;
max-width:auto;
cursor: pointer;
}
#hld__img_full .change {
margin: 0 30px;
width: 50px;
height: 100px;
background :url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACvUlEQVRoQ9XabagNQQDG8f9IkiQJiZAkRRKSJJEkSd7iXkKS5CVJkiSJJEmSJDdJEpKbJEmSSJIkSfFBEhJJkiRJerT1qJNPd3Znd8/dT6fOzs7/V3M6ZzoTaIJL0jxgfAhhT2xOiB2Q+n5Ju4G9fu75EMKKmDlqBUjaBexrCG4LIWzoFABJO4H9DbHPgZYQwoumB0jaARwoGp+Nr3wJSdoOHEwRXzlA0jbgUKr4SgGStgKHU8ZXBpC0BTiSOr4SgKTNwNEy4ksHSNoEHCsrvlSApI3A8TLjSwNIWg+cKDu+FICkdUBbFfHJAZLWAierik8KkLQGOFVlfDKApNXA6arjkwAkrQLO1BFfGCBpJXC2rvhCAEnLgXN1xucGSFoGXKg7PhdAUitwsRniowGSlgCXmiU+D+An0N2AV8D82D1sAz7Jy6gtpaS3wBDP/BpYGEJ4lqQk50NiAaOBO0A/z/cSaA0hPM05f+FhUYBsNkljgHZgZMNSyhBPCtfkeEA0wIixRoxoWE4Z4nGOhkJDcgGMGGfEcBe88XJ6VKgocnBugBETjBjmed8Z8TCyI/fthQBGTDRiqCveG/Egd1XEwMIAIyYZMdhzfzDifkRLrluTAIyYbMQgl3wEloYQ7uUq6+CgZAAjpvinxkDP/8mIux3sib4tKcCIqUYMcM1nL6fsCzD5lRxgxDQj+rv4ixG3UwtKARgx3Z+Jvo7+asStlIjSAEbMMKKPo78ZcTMVolSAETON6O3o70bcSIEoHWDELCN6OfqHEdeLIioBGDHbiJ6OzjZH2Q/Aa0UQlQGMmGNED0f/MuJqXkSlACPmGvFva/rbiCt5EJUDjMiOFmSbom6O/mPE5VhELQAjFhjR1dEyIoN1+KoNYMQiI7q4uD2E0NLh+jr+6P4/TtJiI7K3Os9ZiUaIpFE+JxF93OYvIZsYQATdHI8AAAAASUVORK5CYII=) center no-repeat;
transition: all .2s ease;
cursor:pointer;
}
#hld__img_full .next-img {
transform: rotate(180deg);
}
#hld__img_full .prev-img:hover {
transform: scale(1.2);
}
#hld__img_full .next-img:hover {
transform: scale(1.2) rotate(180deg);
}
#hld__setting {
color:#6666CC;
}
#hld__setting_panel {
display:none;
position:fixed;
top:70px;
left:50%;
margin-left:-120px;
background:#FFF;
width:240px;
padding: 15px 20px;
border-radius: 10px;
box-shadow: 0 0 10px #666;
}
#hld__setting_panel p{
margin-bottom:10px;
}
#hld__setting_panel .hld__sp-title {
font-size: 15px;
font-weight: bold;
text-align: center;
}
#hld__setting_panel .hld__sp-section{
font-weight: bold;
margin-top: 20px;
}
#hld__setting_panel a{
position: absolute;
top: 5px;
right: 5px;
padding: 3px 6px;
background: #efefef;
transition: all .2s ease;
cursor:pointer;
border-radius: 4px;
text-decoration: none;
}
#hld__setting_panel a:hover{
background: #1a3959;
color: #FFF;
}
#hld__setting_panel button {
margin-left: 85px;
background: #FFF;
border: 1px solid #10273f;
color: #10273f;
padding: 3px 8px;
transition: all .2s ease;
cursor:pointer;
}
#hld__setting_panel button:hover {
background: #10273f;
color: #FFF;
}
`))
document.getElementsByTagName("head")[0].appendChild(style)
})();