Greasemonkeyã¡ã¢
ãã¤ã®éã«ãgreasemonkeyã®ä¸ã§jQueryã¨ãã®ã©ã¤ãã©ãªã使ããããã«ãªã£ã¦ã¾ããã
ä»ã«ãè²ã
ã¨ç¥ããªããã¨ããã£ãã®ã§ã¡ã¢ãã¦ããã¾ãã
@require
ã¹ã¯ãªããã®å é ã«è²ã æ¸ããããã«ã@requireãã£ã¦æ¸ãã¨ãå¤é¨JavaScriptãincludeãã¦ä½¿ããã¨ãã§ãã¾ãã
ä¾ï¼
// ==UserScript== // @name test // @include http://localhost/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js // ==/UserScript== (function($){ $('body').click(function(){ alert('ã¯ãªãã¯ãã¾ããã'); }); })(jQuery);
æã£ããã¨
ãªããã$ãã使ããªãããjQueryãã¯ä½¿ããã®ã«ããªã®ã§ã¹ã¯ãªããå
¨ä½ãé¢æ°ã§å²ãã§ãjQueryãã渡ãã¦ãããã®ãã»ãªãªã¼ã¿ããã
ã©ã¤ãã©ãªã®URLã¯ã AJAX Libraries API - Google Codeã«ããã®ã使ãã®ãè¯ãã§ãã
@requireã使ãã¹ã¯ãªãããä½æããå ´åãå³ä¸ã®ãµã«ãå³ã¯ãªãã¯ãã¦ãæ°è¦ã¦ã¼ã¶ã¼ã¹ã¯ãªãããã§ä½ãã¨ãã¾ãããã¾ããã§ãããã@requireãã£ã¦æ¸ãããç¶æ
ã®ã¹ã¯ãªãããã¡ã¤ã«ãFirefoxã«ãã©ãã°&ãããããã¦ãã¦ã¼ã¶ã¼ã¹ã¯ãªããã®ã¤ã³ã¹ãã¼ã«ããããã¨ã§ã@requireã®ãã¡ã¤ã«ããã¦ã³ãã¼ãããã¦ãã¼ã«ã«ã«ä¿åããã¦ã¹ã¯ãªããããå©ç¨ã§ããããã«ãªãã¿ããã§ããç§ã¯ãããç¥ããã«å°ä¸æéã»ã©é ãæ±ãããã¨ã«ãªã£ãã®ã§è¦æ³¨æã§ãã
@resouce
ã@resouceãã使ãã¨ãã¹ã¯ãªããã®ä¸ã§CSSãç»åãã¡ã¤ã«ãæ±ããããã«ãªãã¾ãã
// @resource name url
ã£ã¦æå®ãã¦
GM_getResourceText('name');
ã£ã¦æ¸ãã¨ãurlã§æå®ãããã¡ã¤ã«ã®ããã¹ããã¼ã¿ãåå¾ã§ãã¾ãã
ãã¤ããªãã¡ã¤ã«ã®å ´åã¯
GM_getResourceURL('name');
ã£ã¦æ¸ãã¨ãurlã§æå®ãããã¡ã¤ã«ã®ä¸èº«ã示ããdata:ãå½¢å¼ã®URLãåå¾ã§ãã¾ãã
ä¾ï¼
// ==UserScript== // @name test // @include http://localhost/* // @resource style http://gist.github.com/raw/99181/9d511e468af600a93df53e17c0ab1de1e2f17a90/gistfile1.css // @resource image http://img.f.hatena.ne.jp/images/fotolife/s/syttru/20080221/20080221011637.png // ==/UserScript== (function(){ // ã¹ã¿ã¤ã«ã·ã¼ããèªã¿è¾¼ã var style = GM_getResourceText('style'); // style -> ".test_style{ color ... }" GM_addStyle(style); // divè¦ç´ ãä½ã£ã¦ã¹ã¿ã¤ã«ã·ã¼ããé©ç¨ãã¦bodyã«è¿½å ãã var div = document.createElement('div'); div.setAttribute('class', 'test_style'); div.innerHTML = 'ãããªã®ãã¼'; document.body.appendChild(div); // bodyã®æ«å°¾ã«ç»åã追å ãã var img = document.createElement('img'); var image = GM_getResourceURL('image'); // image -> "data:image/png;base64,iVBORw0K..." img.setAttribute('src', image); img.setAttribute('alt', 'ã½ã¼ãã³ã¹'); document.body.appendChild(img); })();
æã£ããã¨
@resourceã§èªã¿è¾¼ãCSSãç»åãã¡ã¤ã«ã¯ãhttp://ãããhttps://ãããftp://ãå½¢å¼ã®URLã§æå®ããªãã¨ããã¾ãããã¤ã¾ããã¡ã¤ã«ãç½®ãã¦ããå ´æãå¿
è¦ã ã¨ãããã¨ã§ãã
ç»åãã¡ã¤ã«ã¯Frickrã¨ãはてなフォトライフã¨ãã®ç»åå
±æãµã¼ãã¹ãå©ç¨ãã¦ãCSSã¨ãã®ããã¹ããã¡ã¤ã«ã¯gistã¨ãGoogle Codeのプロジェクトホスティングã¨ãAssemblaã¨ãã®ã½ã¼ã¹ã³ã¼ãã®ãã¹ãã£ã³ã°ãµã¼ãã¹ã使ãã®ãããããããªãããªã¼ã¨æãã¾ããã