Greasy Fork

Greasy Fork is available in English.

NGA优化摸鱼体验

NGA论坛隐藏切换显示头像,表情,图片等,防止突然蹦出一对??而导致的突然性的社会死亡

目前为 2019-12-26 提交的版本,查看 最新版本

// ==UserScript==
// @name         NGA优化摸鱼体验
// @namespace    http://tampermonkey.net/
// @version      1.1
// @require https://cdn.staticfile.org/jquery/3.4.0/jquery.min.js
// @description  NGA论坛隐藏切换显示头像,表情,图片等,防止突然蹦出一对??而导致的突然性的社会死亡
// @author       HLD
// @match        *bbs.nga.cn/*
// @match        *ngabbs.com/*
// ==/UserScript==

(function() {
    'use strict';
    ///////////////////////////////////////////////////////
    /*
        显示设置
          ON: 显示
          OFF: 隐藏
        [  ]内的为切换按键
    */
    //头像[Q]
    const AVATAR = 'OFF'
    //表情[W]
    const SMILE = 'OFF'
    //图片[E]
    const IMAGE = 'ON'
    ///////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////
    //注册按键
    $('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()
    }, 100)
    const resizeImg = (url) => {
        if($('#img_full').length > 0) return
        let $imgBox = $('<div id="img_full"></div>')
        $imgBox.click(function(){
            $(this).remove()
        })
        $imgBox.css({
            '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'
        })
        let $img = $('<img style="display:block;width:auto;max-width:auto">')
        $img.css('max-height', $(window).height() + 'px')
        $img.attr('src', url)
        $imgBox.append($img)
        $('body').append($imgBox)
    }
    //新页面打开连接
    $('.topic').attr('target', '_blank')


    const runDom = () => {
        $('.forumbox.postbox[hld-render!=ok]').each(function(){
            //隐藏头像
            AVATAR == 'OFF' && $(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 = $('<span class="smile_alt_text">[' + alt + ']</span>')
                     SMILE == 'OFF' ? $(this).hide() : $alt.hide()
                    $(this).after($alt)
                }else if(!classs && $(this).attr('onload')) {
                    $(this).width() > 200 && $(this).css({'min-width': '200px', 'min-height': 'auto', 'width': '200px', 'height': 'auto'})
                    let $imgB = $('<button class="switch-img" style="display:none">图</button>')
                    $imgB.on('click', function(){
                        $(this).prev('img').toggle()
                        $(this).text($(this).prev('img').is(':hidden') ? '图' : '隐藏')
                    })
                    $(this).removeAttr('onload')
                    if(IMAGE == 'OFF') {
                        $(this).hide();
                        $imgB.show()
                    }
                    $(this).after($imgB)
                }
            })
            //隐藏签名
            $(this).find('.sign, .sigline').css('display', 'none')
            //添加标志位
            $(this).attr('hld-render', 'ok')
        })
    }
    $('#m_posts').on('click', '.postcontent img', function(){
        resizeImg($(this).data('srcorg') || $(this).attr('src'))
    })
})();