|
阅读:3600回复:9
求教一个GreaseMonkey脚本
就是使大图片按FF窗口大小缩小,这样就便于观看。。。。。。。
// ==UserScript==
// @name ImageFit
// @description Fit the image for reading.
// @version 1.0
// @namespace ImageFit
// @author Crystalfluxay
// @include http://*.lqqm.net/*
// @include http://*.zatan.org/*
// ==/UserScript==
var AllImages = document.images;
var winWidth = 0;
var winHeight = 0;
function findDimensions() //函数:获取尺寸
{
winWidth = 0;
winHeight = 0;
//获取窗口宽度
if (window.innerWidth)
winWidth = window.innerWidth;
else if ((document.body) && (document.body.clientWidth))
winWidth = document.body.clientWidth;
//获取窗口高度
if (window.innerHeight)
winHeight = window.innerHeight;
else if ((document.body) && (document.body.clientHeight))
winHeight = document.body.clientHeight;
/* nasty hack to deal with doctype switch in IE */
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
{
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}
}
function Wa_SetImgAutoSize( img)
{
var MaxWidth=winWidth * 0.96;//设置图片宽度界限
var MaxHeight=winHeight * 0.96;//设置图片高度界限
var HeightWidth=img.offsetHeight/img.offsetWidth;//设置高宽比
var WidthHeight=img.offsetWidth/img.offsetHeight;//设置宽高比
if(img.readyState!="complete")return false;//确保图片完全加载
if(img.offsetWidth>MaxWidth)
{
img.width=MaxWidth;
img.height=MaxWidth*HeightWidth;
}
if(img.offsetHeight > MaxHeight )
{
img.height=MaxHeight;
img.width=MaxHeight*WidthHeight;
}
}
if (AllImages != null)
{
findDimensions();
window.onresize=findDimensions;
for (i=0; i < AllImages.length; i++)
{
Wa_SetImgAutoSize( AllImages[i]);
}
}
这是我自己写的,不知道为什么没有用哦 |
|
|
1楼#
发布于:2008-06-06 19:30
// ==UserScript==
// @name ImageFit
// @description Fit the image for reading.
// @version 1.0
// @namespace http://test.com
// @author Crystalfluxay
// @include http://*lqqm.net/*
// @include http://*zatan.org/*
// ==/UserScript==
function findDimensions() //�����ȡ�ߴ�
{
winWidth = 0;
winHeight = 0;
//��ȡ���ڿ��
if (window.innerWidth)
winWidth = window.innerWidth;
else if ((document.body) && (document.body.clientWidth))
winWidth = document.body.clientWidth;
//��ȡ���ڸ߶�
if (window.innerHeight)
winHeight = window.innerHeight;
else if ((document.body) && (document.body.clientHeight))
winHeight = document.body.clientHeight;
/* nasty hack to deal with doctype switch in IE */
if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth)
{
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}
}
function Wa_SetImgAutoSize( img)
{
var MaxWidth=winWidth * 0.96;//����ͼƬ��Ƚ���
var MaxHeight=winHeight * 0.96;//����ͼƬ�߶Ƚ���
var HeightWidth=img.offsetHeight/img.offsetWidth;//���ø߿��
var WidthHeight=img.offsetWidth/img.offsetHeight;//���ÿ�߱�
// if(img.readyState!="complete")return false;//ȷ��ͼƬ��ȫ����
if(img.offsetWidth>MaxWidth)
{
img.width=MaxWidth;
img.height=MaxWidth*HeightWidth;
}
if(img.offsetHeight > MaxHeight )
{
img.height=MaxHeight;
img.width=MaxHeight*WidthHeight;
}
}
function reset()
{
AllImages = document.images;
if (AllImages != null)
{
findDimensions();
for (i=0; i < AllImages.length; i++)
{
Wa_SetImgAutoSize( AllImages[i]);
}
}
}
addEventListener("resize",reset,true);
reset(); |
|
|
2楼#
发布于:2008-06-06 19:30
晕,在3.0下,wushi用双斜杠注释的那些字符无法识别!
|
|
|
|
3楼#
发布于:2008-06-06 19:30
“就是使大图片按FF窗口大小缩小,这样就便于观看。。。。。。。 "
Firefox默认不就是这呀吗? |
|
|
|
4楼#
发布于:2008-06-06 19:30
|
|
|
5楼#
发布于:2008-06-06 19:30
好像是FF3.0的新引擎无法渲染某些ASCII字符!
|
|
|
|
6楼#
发布于:2008-06-06 19:30
可能是我没有对user.js文件的格式做设置的原因吧。
|
|
|
7楼#
发布于:2008-06-06 19:30
估计上面使用的中文编码出了问题,所以看到的是方块。
|
|
|
8楼#
发布于:2008-06-06 19:30
还是不行,唉唉!
|
|
|
9楼#
发布于:2008-06-06 19:30
|
|
|


