maryjeck
火狐狸
火狐狸
  • UID9565
  • 注册日期2005-11-03
  • 最后登录2017-11-15
  • 发帖数281
  • 经验72枚
  • 威望0点
  • 贡献值44点
  • 好评度1点
  • 社区居民
  • 忠实会员
阅读:3262回复:9

求教一个GreaseMonkey脚本

楼主#
更多 发布于:2008-06-06 19:30
就是使大图片按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]);
	}
}


这是我自己写的,不知道为什么没有用哦
wushi777
非常火狐
非常火狐
  • UID12365
  • 注册日期2006-04-17
  • 最后登录2011-04-13
  • 发帖数817
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
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();
fang5566
管理员
管理员
  • UID3719
  • 注册日期2005-03-07
  • 最后登录2024-05-09
  • 发帖数18483
  • 经验4837枚
  • 威望5点
  • 贡献值4316点
  • 好评度1116点
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 终身成就
2楼#
发布于:2008-06-06 19:30
晕,在3.0下,wushi用双斜杠注释的那些字符无法识别!
Firefox More than meets your experience
idragonet
千年狐狸
千年狐狸
  • UID15658
  • 注册日期2006-11-12
  • 最后登录2017-11-15
  • 发帖数2642
  • 经验162枚
  • 威望1点
  • 贡献值74点
  • 好评度118点
  • 社区居民
3楼#
发布于:2008-06-06 19:30
“就是使大图片按FF窗口大小缩小,这样就便于观看。。。。。。。 "


Firefox默认不就是这呀吗?
wushi777
非常火狐
非常火狐
  • UID12365
  • 注册日期2006-04-17
  • 最后登录2011-04-13
  • 发帖数817
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
4楼#
发布于:2008-06-06 19:30
fang5566:晕,在3.0下,wushi用双斜杠注释的那些字符无法识别!回到原帖


我这里也无法显示。 我是把LZ的代码直接拷贝到notepad里修改的,在notepad里显示就是黑方框,再拷贝发上来就是现在显示的样子了。
fang5566
管理员
管理员
  • UID3719
  • 注册日期2005-03-07
  • 最后登录2024-05-09
  • 发帖数18483
  • 经验4837枚
  • 威望5点
  • 贡献值4316点
  • 好评度1116点
  • 社区居民
  • 最爱沙发
  • 忠实会员
  • 终身成就
5楼#
发布于:2008-06-06 19:30
好像是FF3.0的新引擎无法渲染某些ASCII字符!
Firefox More than meets your experience
wushi777
非常火狐
非常火狐
  • UID12365
  • 注册日期2006-04-17
  • 最后登录2011-04-13
  • 发帖数817
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
6楼#
发布于:2008-06-06 19:30
可能是我没有对user.js文件的格式做设置的原因吧。
xoferiF
热心会员
热心会员
  • UID6559
  • 注册日期2005-06-05
  • 最后登录2020-04-24
  • 发帖数418
  • 经验24枚
  • 威望0点
  • 贡献值4点
  • 好评度1点
  • 社区居民
  • 忠实会员
7楼#
发布于:2008-06-06 19:30
估计上面使用的中文编码出了问题,所以看到的是方块。
maryjeck
火狐狸
火狐狸
  • UID9565
  • 注册日期2005-11-03
  • 最后登录2017-11-15
  • 发帖数281
  • 经验72枚
  • 威望0点
  • 贡献值44点
  • 好评度1点
  • 社区居民
  • 忠实会员
8楼#
发布于:2008-06-06 19:30
还是不行,唉唉!
idragonet
千年狐狸
千年狐狸
  • UID15658
  • 注册日期2006-11-12
  • 最后登录2017-11-15
  • 发帖数2642
  • 经验162枚
  • 威望1点
  • 贡献值74点
  • 好评度118点
  • 社区居民
9楼#
发布于:2008-06-06 19:30
maryjeck:还是不行,唉唉!回到原帖


你要保存为UTF-8编码方式。
游客

返回顶部