// ==UserScript==
// @name jc_Image_Zoomer_2
// @namespace http://jiichen.at.home/
// @description Zoom Image
// @description Support domain/Host: wretch.cc , yam.com , pixnet.net , qing.weibo.com , facebook(link)
// @require http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js
// @include http://www.wretch.cc/album/*
// @include http://album.blog.yam.com/*
// @include http://*.weibo.com/*
// @include http://photo.pchome.com.tw/*
// @include http://*.pixnet.net/album/set/*
// @include http://*/thread*
// @include http://*.4chan.org/*
// @exclude http://www.youtube.com/
// @exclude https://www.facebook.com/
// @exclude https://app.facebook.com/
// @version 0.1.9
// @modified_date 2014.10.05
// @copyright 2012, jc
// @grant GM_log
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
//GM_addStyle("#jcZoomImgArea {position:fixed; top:0px; left:100px; border:3px solid #66CCFF; background-color:gray; padding:2px; z-index:2147483647;}");
GM_addStyle("#jcZoomImgArea2 {position:fixed; top:0px; left:100px; border:3px solid #66CCFF; background-color:gray; padding:2px; z-index:1000000;}");
var globalImageMinWidth = 190; // mouseenter 時圖的最小寬度
var globalImageMinHeight = 150; // mouseenter 時圖的最小高度
var globalMouseStatus = 0; // 0: mouseleave ; 1: mouseenter
var globalGrabUrl = ''; // 正在抓的網址
var globalDivShowing = 0; // Div 是否顯示中
var globalMouseInDiv = 0; // mouse 是否在 Div 內
var globalDivId = 'jcZoomImgArea2';
var globalMouseOverObj = null; // 滑鼠 mouseenter 的物件
var globalHost, globalDomain;
function doJcGetImageOrHtml(url , x , y) {
// 抓圖檔,如果是網頁則繼續抓圖
globalGrabUrl = url;
GM_log('grab url = ' + url);
$.ajax({
type: "GET" ,
url: url ,
complete: function( xhr , textStatus ) {
/*
if ('success' != textStatus) {
alert("complete error status : " + textStatus);
}
*/
} ,
error: function( xhr , textStatus , errorThrown ) {
/*
var errMsg = xhr.status + ' , ' + xhr.responseText + ' , ' + textStatus + ' , ' + errorThrown;
alert("ERROR : " + errMsg + ' ; ' + url );
*/
var divObj = $('#' + globalDivId);
divObj.append('');
divObj.find('img').one('load' , function() {
var win_h = $(window).height();
var win_w = $(window).width()-30;
var max_img_w = Math.max(x-50 , parseInt(win_w/2 , 10)-50);
var big_img_width = $(this).width();
var big_img_height = $(this).height();
var imgRate = (big_img_height / big_img_width);
if (big_img_width <= globalImageMinWidth) {
$(this).remove();
} else if (big_img_height <= globalImageMinHeight) {
$(this).remove();
} else {
var adjust_img_width = big_img_width;
var adjust_img_height = big_img_height;
var adjust_img_width1 = big_img_width;
var adjust_img_height1 = big_img_height;
var adjust_img_width2 = big_img_width;
var adjust_img_height2 = big_img_height;
// 依據 img 寬高調整 div 位置
var space1 = 10; // 預留之空白或邊框寬度
if ((big_img_height + space1) > win_h) {
adjust_img_height1 = (win_h - space1);
//adjust_img_width1 = parseInt(adjust_img_height1 * (big_img_width / big_img_height) , 10);
adjust_img_width1 = parseInt(adjust_img_height1 / imgRate , 10);
}
if ((big_img_width + space1) > max_img_w) {
adjust_img_width2 = max_img_w;
//adjust_img_height2 = parseInt(adjust_img_width2 * (big_img_height / big_img_width) , 10);
adjust_img_height2 = parseInt(adjust_img_width2 * imgRate , 10);
}
adjust_img_width = Math.min(adjust_img_width1 , adjust_img_width2);
adjust_img_height = Math.min(adjust_img_height1 , adjust_img_height2);
$(this).width(adjust_img_width)
.height(adjust_img_height);
GM_log("x = " + x + " , adjust_img_width = " + adjust_img_width + " , win_w = " + win_w);
GM_log("y = " + y + " , adjust_img_height = " + adjust_img_height + " , win_h = " + win_h);
if ((x + 50 + adjust_img_width) > win_w) {
divObj.css('left' , (x - adjust_img_width - 50) + 'px');
} else {
divObj.css('left' , (win_w - adjust_img_width - 30) + 'px');
//divObj.css('left' , '30px');
}
}
});
divObj.find('img').each(function() {
$(this).attr('src' , $(this).attr('data-src'));
});
} ,
success: function(response, status, xhr) {
// 由於抓圖需要時間,如果抓完後發現使用者已經在看其他圖(網址不同),則返回
if (url != globalGrabUrl) {
return false;
}
var divObj = $('#' + globalDivId);
divObj.css('left' , (x + 50) + 'px');
var ct = xhr.getResponseHeader("content-type") || "";
//alert(ct);
if (ct.indexOf('html') > -1) {
// handle html page (如果是 HTML 網頁)
$(response).find('img').each(function() {
divObj.append('
');
//divObj.append('