jQueryとGreasemonkeyの相性が素晴らしく良い件

pixiv_add-bookmark.user.js · GitHubを弄ってて実感した。

DOMツリー構築とE4X


jQueryjQueryHTMLDOM
GreasemonkeyscriptFirefoxE4X使


 var $mainTable = $(
  <table class="gm-pixiv-bookmark-maintable">
   <tr>
    <th>グループ:</th>
    <td/>
   </tr>
   <tr>
    <th>公開設定:</th>
    <td>
     <input type="radio" id="res0" name="restrict" value="0" checked="true" />
     <label for="res0">公開</label>
     <input type="radio" id="res1" name="restrict" value="1"/>
     <label for="res1">非公開</label>
    </td>
   </tr>
   <tr>
    <th>コメント:</th>
    <td>
     <input type="text" name="comment" maxLength="140" />
    </td>
   </tr>
  </table>.toString()
 );

XML使

jQueryUIと@resource


jQueryUI使CSS
Greasemonkey
// @resource       flora http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/flora.css
// @resource       floraDialog http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/flora.dialog.css
// @resource       iDialogE http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-e.gif
// @resource       iDialogN http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-n.gif
// @resource       iDialogNE http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-ne.gif
// @resource       iDialogNW http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-nw.gif
// @resource       iDialogS http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-s.gif
// @resource       iDialogSE http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-se.gif
// @resource       iDialogSW http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-sw.gif
// @resource       iDialogTitle http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-title.gif
// @resource       iDialogTitlebarCloseHover http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-titlebar-close-hover.png
// @resource       iDialogTitlebarClose http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-titlebar-close.png
// @resource       iDialogW http://jquery-ui.googlecode.com/svn/tags/1.6rc2/themes/flora/i/dialog-w.gif

CSS
CSSpath
.flora.ui-dialog .ui-dialog-titlebar-close {
 width: 16px;
 height: 16px;
 background: url(i/dialog-titlebar-close.png) no-repeat;
 position:absolute;
 top: 6px;
 right: 7px;
 cursor: default;
}

CSSGM_getResourceText
pathGM_getResourceURLdataURL

 var filaName2ResourceName = {
  'dialog-e.gif':'iDialogE'
  ,'dialog-n.gif':'iDialogN'
  ,'dialog-ne.gif':'iDialogNE'
  ,'dialog-nw.gif':'iDialogNW'
  ,'dialog-s.gif':'iDialogS'
  ,'dialog-se.gif':'iDialogSE'
  ,'dialog-sw.gif':'iDialogTitle'
  ,'dialog-title.png':'iDialogTitle'
  ,'dialog-titlebar-close-hover.png':'iDialogTitlebarCloseHover'
  ,'dialog-titlebar-close.png':'iDialogTitlebarClose'
  ,'dialog-w.gif':'iDialogW'
 };
/* 中略 */
 var floraDialogCSS = GM_getResourceText('floraDialog');
 $.each(filaName2ResourceName,function(fileName,resourceName){
  floraDialogCSS = floraDialogCSS.replace('i/'+fileName,GM_getResourceURL(resourceName));
 });

GM_addStyleCSSstyle
GM_addStyle(floraDialogCSS);

flora使