前端开发资源汇总
UserScript
UserScript 介绍:
UserScript 又称“油猴脚本”,其实就是一个在浏览器中能本地执行扩展名为
.user.js
的js文件,使用UserScript可以自定义被浏览的网页,更多详细可参考维基百科中的介绍。
UserScript 优势:
在Chrome中,UserScript类似于一个精简的Chrome扩展,两者的区别在于Chrome扩展是在浏览器启动的时候就会执行,但UserScript是在使用的时才候执行,这样就大大减少了Chrome的内存占用。而且UserScript只是一个单纯的js文件,可以随意定制修改。
- Chrome原生安装UserScript脚本
- Chrome油猴脚本管理插件 - TamperMonkey
- 自定义油猴脚本模版
热门油猴脚本推荐:
油猴脚本搜索(根据受欢迎程度排列):
- Greasemonkey API
Chrome userscript 模本
// ==UserScript==
// @name MyUserScript Template
// @namespace https://github.com/MrLeo/Leo.UserScript
// @description userscript for mr.leo
// @match http://*/*
// @include http://*/*
// @require http://code.jquery.com/jquery-latest.js
// @updateURL uploadFilePath.user.js
// @downloadURL uploadFilePath.user.js
// @version 0.1
// ==/UserScript==
//根据传入的URL,在head里生成script引用DOM对象
function createScriptLink(url){
var scriptElement = document.createElement('script');
scriptElement.setAttribute('type', 'text/javascript');
scriptElement.setAttribute('src', url);
document.head.appendChild(scriptElement);
console.log('[添加引用]', (new XMLSerializer()).serializeToString(scriptElement));
}
;(function(){
//在head引入JQuery
window.jQuery || createScriptLink('//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js')
if($){$ = window.jQuery;}
console.log('[leo]', `${$}`);
})();