// ==UserScript== // @name MiniblogImgPop - 微博浮图 // @namespace http://userscripts.org/users/83994 // @icon https://addons.cdn.mozilla.net/img/uploads/addon_icons/337/337281-64.png?modified=1361080128 // @description 微博浮图控件,鼠标移过小图弹出浮动大图的脚本 // @version 3.4.2 // @include http://*qing.weibo.com/* // @include http://*weibo.com/* // @include https://*weibo.com/* // @include http://*t.163.com/* // @include http://*t.sohu.com/* // @include http://*t.qq.com/* // @include http://*t.ifeng.com/* // @include http://*t.titan24.com/* // @include http://*t.people.com.cn/* // @include http://*tianya.cn/* // @include http://*diandian.com/* // @include http://*.digu.com/* // @include http://i.taobao.com/* // @include http://*t.cntv.cn* // @include http://*tieba.baidu.com/f* // @include http://*tieba.baidu.com/i* // @include http://*xueqiu.com/* // @include https://*douban.com/* // @include https://*work.alibaba-inc.com/* // @grant none // @downloadURL none // ==/UserScript== // @author afc163 // @weibo http://weibo.com/afc163 // @code https://github.com/afc163/MiniblogImgPop // @blog http://pianyou.me // @date 2010.8.12 (function() { // 各微博站点的feed配置 var MIPConfig = { 'qing.weibo.com':{ feedSelector:'.imgZoomIn', sFrag :'', bFrag :'' }, 'q.weibo.com':{ feedSelector:'.bigcursor', sFrag :'thumbnail', bFrag :'large' }, 'weibo.com':{ feedSelector:'.bigcursor, .feed_img, .media_list img', sFrag :['thumb180', 'thumb150', 'orj480', 'orj360', 'thumbnail', 'square'], bFrag :['mw690', 'mw690', 'mw690', 'mw690', 'bmiddle', 'bmiddle'] }, 't.sohu.com':{ feedSelector:'.pic', sFrag :['/f_','_1.jpg'], bFrag :['/m_','_0.jpg'] }, 't.163.com':{ feedSelector:'.tweet-preview-pic', sFrag :['w=140&h=140', '&gif=1'], bFrag :['w=440', '&gif=0'] }, 't.qq.com':{ feedSelector:'.pic img:not(.large)', sFrag :['/160', '/120'], bFrag :['/460', '/460'] }, 't.titan24.com':{ feedSelector:'.imgBig', sFrag :'_thumbnail', bFrag :'_middle' }, 't.people.com.cn':{ feedSelector:'.list_s_pic img', sFrag:'/s_', bFrag:'/b_' }, 't.ifeng.com':{ feedSelector:'.zoom_in_image img', sFrag :'/128x160_', bFrag :'/520x0_' }, 'www.tianya.cn':{ feedSelector:'.pic-zoomin', bigSrc :'_middlepic', sFrag :'small', bFrag :'middle' }, 'diandian.com':{ feedSelector:'.feed-img', bigSrc :'imgsrc' }, 'digu.com':{ feedSelector:'.picture', sFrag :'_100x75', bFrag :'_640x480' }, 't.cntv.cn':{ feedSelector:'.zoom-move', sFrag :'/thumbnail', bFrag :'/bmiddle' }, 'i.taobao.com':{ feedSelector:'.thumb-image', sFrag :'_160x160', bFrag :'_450x10000' }, 'tieba.baidu.com/f':{ feedSelector:'.threadlist_media li', bigSrc: 'bpic' }, 'tieba.baidu.com/i':{ feedSelector:'.feat_img', bigSrc: 'data-field' }, 'xueqiu.com':{ feedSelector:'.expandable > img', sFrag :'!thumb', bFrag :'!custom' }, 'douban.com':{ feedSelector:'img', sFrag :'median', bFrag :'raw' }, 'work.alibaba-inc.com':{ feedSelector:'.uxcore-nw-message-wall-item-album-thumb li', sFrag :['240x240', '120x120'], bFrag :['620x10000', '620x10000'] } }; // 居中显示的图片对象 var PopImg = { show: function(e) { this.allowMove = false; // fix firefox 22 beta 1 this._hideTimer && window.clearTimeout(this._hideTimer); var that = this; var smallImg = MiniblogImgPop.smallImg; var src = this.getBigImgsrc(smallImg); this.img.src = src; this.imgWidth = 500; imgReady(src, function() { that.imgWidth = this.width; that.layoutImg(e); that.img.style.opacity = 1; that.img.style.visibility = 'visible'; that.img.style.marginTop = '-15px'; Mask.show(e); // 换算图片显示高度 // 1. 宽度超过 500 时,高度要等比例压缩 // 2. 加上边框高度 var imgDisplayHeight; if (this.width > 500) { imgDisplayHeight = (this.height + 14) * 500 / this.width; } else { imgDisplayHeight = this.height + 14; } if (window.innerHeight > imgDisplayHeight) { var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; that.img.style.top = (scrollTop + (window.innerHeight - imgDisplayHeight)/2 + 15) + 'px'; that.allowMove = false; } else { that.allowMove = true; that.move(e); } }); }, // 设置大图的宽度与位置 layoutImg: function(e) { var pos = offset(MiniblogImgPop.smallImg); var left = pos.x + pos.width + 30; var width = Math.min(this.imgWidth, 500); // 如果小图右边放不下 if (left + width > window.innerWidth) { left = pos.x - width - 30; // 如果左边也放不下 if (left < 0) { // 根据鼠标位置,选择空间大的一侧放置 if (e.pageX > window.innerWidth / 2) { // 放置在左边 width = Math.min(width, e.pageX - 30); left = 0; } else { // 放置在右边 width = Math.min(width, window.innerWidth - e.pageX - 30); left = window.innerWidth - width; } } } this.img.style.width = width + 'px'; this.img.style.left = left + 'px'; }, hide: function() { var that = this; this.img.style.opacity = 0; this.img.style.marginTop = '0px'; Mask.hide(); this.shown = false; this._hideTimer = window.setTimeout(function() { that.img.src = ''; that.img.style.visibility = 'hidden'; }, 200); }, init: function() { var node = document.createElement('img'); node.id = 'miniblogImgPop'; document.body.appendChild(node); this.img = node; Mask.init(); }, move: function(e) { this.layoutImg(e); // 重新计算大图宽度与位置 if (!this.allowMove) { return; } Mask.move(e); // 根据 Mask 的位置算出大图的位置 var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; this.img.style.top = (scrollTop - Mask.top * Mask.scale) + 14 + 'px'; }, getBigImgsrc: function(obj) { var tempimgs, tempimg, imgsrc, i, l, sname = MiniblogImgPop.sitename, config = MiniblogImgPop.config; if (obj.tagName === 'IMG' || obj.tagName === 'img') { tempimg = obj; } else { tempimgs = obj.getElementsByTagName('IMG'); if (!tempimgs || tempimgs.length === 0) { throw 'cant found the img node.'; } else{ tempimg = tempimgs[0]; } } //针对使用额外属性保存大图地址的网站 if (config.bigSrc) { return tempimg.getAttribute(config.bigSrc) || 'javascript:;'; } //一般处理 imgsrc = tempimg.getAttribute('src'); //console.info(imgsrc); imgsrc = decodeURIComponent(imgsrc); if (typeof config.sFrag === 'object') { for(i=0, l=config.sFrag.length; i this.range ? this.range : top; this.top = top; this.nodes[0].style.height = top + 'px'; this.nodes[1].style.height = (this.sOffset.height - top - this.height) + 'px'; }, init: function() { var node1 = document.createElement('div'); node1.className = 'miniblogImgPop-mask'; document.body.appendChild(node1); var node2 = document.createElement('div'); node2.className = 'miniblogImgPop-mask'; document.body.appendChild(node2); this.nodes = [node1, node2]; } }; var MiniblogImgPop = { preloadImg: function() { var that = this; window.setTimeout(function() { var nodes = $(that.config.feedSelector); for (var i=0; i