Greasy Fork

Greasy Fork is available in English.

百度贴吧图片放大

点击图片放大,再次点击还原

当前为 2014-07-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        百度贴吧图片放大
// @namespace   http://blog.sbw.so/
// @description 点击图片放大,再次点击还原
// @include     http://tieba.baidu.com/p/*
// @include     http://tieba.baidu.com/f?*
// @grant       unsafeWindow
// @require     http://code.jquery.com/jquery-2.1.1.min.js
// @author      o丨Reborn <[email protected]>
// @icon        http://tb.himg.baidu.com/sys/portrait/item/d92f6fd8ad5265626f726ee90f
// @version     14.07.11.0
// ==/UserScript==

//14-07-11.0    支持GreaseMonkey 2.0
//14-07-01.0    簡化代碼,增加兼容性
//14-03-19.1    为了实现拖拽图片,将鼠标按下放大改为点击放大
//14-03-18.1    修复右键点击时关闭图片
//14-03-17.2	  解决百度异步加载时图片无效
//13-01-29.1	  解决楼中视频无法播放的bug
//13-01-25.1    防止图片缩过小无法关闭,解决个别图片脚本不生效,保留收藏图片功能,去除百度小图不能收藏的bug
//13-01-23.2    修复在看大图时不能右键下载,新增鼠标滚动调整大小功能:w
//13-01-23.1    应网友建议,将双击移除图片改为单击移除.
//13-01-22.1    去掉了一个ajax查询,应该能快点,图片显示从左上角改为居中
//13-01-21.4    一些小改动
//13-01-21.3    支持同时点开多个图片
//13-01-21.2    解决拖动卡
//13-01-21.1    解决图片位置错乱

(function(){    
    var _clock = null;
    
    function addPicture(img){
        if (img.width < 50)
            return ;
        
        $(img).css({
            'position':'fixed',
            'z-index':'999999',
            'box-shadow':'0 0 50px #333',
            'border':'1px dashed hsl(40, 50%, 30%)',
            'top':'50%',
            'left':'50%',
            'margin-top':parseInt(img.height) / -2 + 'px',
            'margin-left':parseInt(img.width) / -2 + 'px'
        });

        document.body.appendChild(img);

        clearInterval(_clock);
    }
    
    function pictureScroll(e) {
        var width = $(this)[0].width - e.detail * 15;
    //    $(this)[0].width = width < 100 ? 100 : width;
        $(this).attr({
            'width' : width < 100 ? 100 : width,
            'height' : ''
        });

        $(this).css({
            'margin-top':parseInt($(this)[0].height) / -2 + 'px',
            'margin-left':parseInt($(this)[0].width) / -2 + 'px'
        });

        e.preventDefault();
        return false;
    }
    
    function picMouseDown(e){
        var mouseX = e.pageX;
        var mouseY = e.pageY;
        var oldX = parseInt($(this).css('left'));
        var oldY = parseInt($(this).css('top'));
        var close = true;
        
        $(document).bind('mousemove',function(e){
            $(this).css({
                'top':e.pageY - mouseY + oldY + 'px',
                'left':e.pageX - mouseX + oldX + 'px'
            });
            close = false;
        });
        
        $(document).mouseup(function(e){
            if (close)
                $(this).remove();
            $(document).unbind('mousemove');
        });
        
        e.preventDefault();
        return false;
    }

    function pictureView(e){
        if (e.button != 0)
            return true;
       
//        $(this).unbind('click');
       
        var reg=/\/[a-z0-9]{20,}\.[a-zA-Z]{3,}/;
        var match=$(this).attr("src").match(reg);
        
        if(!match)
           return ;
        
        var img = document.createElement('img');
        img.src="http://imgsrc.baidu.com/forum/pic/item" + match[0];

//        $(img).one('load', function() {
//            $(img).css({
//                'margin-top':parseInt(this.height) / -2 + 'px',
//                'margin-left':parseInt(this.width) / -2 + 'px'
//            });
//        }).each(function() {
//              if(this.complete) 
//                  $(this).load();
//        });
        
        img.addEventListener('DOMMouseScroll', pictureScroll);
        $(img).mousedown(function(e){
            if (e.button != 0)
                return ;

            var mouseX=e.pageX;
            var mouseY=e.pageY;
            var oldX=parseInt($(this).css('left'));
            var oldY=parseInt($(this).css('top'));
            var remove = true;
            $(document).bind('mousemove',function(e){
                $(img).css({
                    'top':e.pageY - mouseY + oldY,
                    'left':e.pageX - mouseX + oldX
                });
                remove = false;
            });
            $(document).mouseup(function(e){
                if (remove)
                    $(img).remove();
                $(document).unbind('mousemove');
            });
    //		e.preventDefault();
            return false;
        });

        // 添加图片
        _clock = setInterval(function(){
            addPicture(img);
        }, 50);

        e.preventDefault();
        return false;
    }
           
    unsafeWindow.$('.BDE_Image').unbind('click');
    //window.addEventListener('DOMContentLoaded', function(){
        $(document).on('mousedown', '.BDE_Image', function(e){
            // 兼容其它腳本
            if (e.ctrlKey || e.altKey || e.shiftKey)
               return ;
            
            //$(this).unbind('click');
            this.onclick = pictureView;
        });
    //}, false);
})();