---
title: "greasemonkey油猴子初学过程中遇到的问题"
author: "buddie"
date: "2018-08-14T17:54:18Z"
tags: ["GreaseMonkey", "jQuery", "settimeout"]
categories: ["Web前端"]
slug: "greasemonkey"
draft: false
lastmod: "2018-08-14T18:01:57Z"
id: 2428710
url: "https://buddie.iteye.com/blog/2428710"
---

之前了解过Chrome浏览器自定义插件，那Firefox浏览器中怎么定义插件呢？

搜索到了greasemonkey-泥猴子

试着写一个HelloWorld遇到了以下两个问题

1、JQuery的使用

```
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
```

 网上搜索的方式大多是这种，可是还是不好用，还是提示“$”符不识别

 最后搜索到解决方案，加入以下代码

```
var $ = unsafeWindow.jQuery;
```

 这样就可以使用$("#id")的方式来使用JQuery了！

 

2、setTimeout不识别

    greasemonkey中需要以下面的方式才能使用setTimeout

```
window.reloadPage=function(){
	window.location.reload();
}
var ints=setTimeout(reloadPage,500);
```

 

 

 

附上greasemonkey的官网地址：

[https://greasemonkey.en.softonic.com/](https://greasemonkey.en.softonic.com/)