osc动弹图片预览

再也不用打开新页面看图片啦

目前为 2016-11-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         osc动弹图片预览
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  再也不用打开新页面看图片啦
// @author       Hjj
// @match        https://www.oschina.net/tweets
// @require      http://cdn.staticfile.org/jquery/1.8.2/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    var _scale = 1;
    var previewBox = $('<div></div>');
    previewBox.css({
        'position': 'fixed',
        'top': '15px',
        'left': '15px',
        'display': 'none',
        'transform-origin':'0 0'
    }).on('mousewheel',scale);
    $('body').append(previewBox);
    $('#tiles,#HotTweets').on('click','.tweet>.img>a',function(e){
        e.preventDefault();
        previewBox.css('transform','scale(1)');
        var thumbSrc = $(e.target).attr('src');
        var trueSrc = thumbSrc.replace(/_thumb/,'');
        previewBox.empty().append(
            $('<img>').attr('src',trueSrc)
            .css({
                'max-width': '100%',
                'max-height': '100%'
            }).on('click',deleteSelf)
        ).show();
    });
    
    function deleteSelf(e){
        $(e.target).parent().hide().end().remove();
        _scale = 1;
    }
    function scale(e){
        e.preventDefault();
        var delta = e.originalEvent.wheelDelta / 120;
        _scale += -delta/10;
        previewBox.css('transform','scale('+_scale+')');
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址