Show
Ignore:
Timestamp:
06/27/08 20:27:32 (5 months ago)
Author:
gan2
Message:

パレットの選択メニューはテキストフォームのときにだけ出るようにした
インデントがずれていたので修正した (もし意図的だったらごめんなさい)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/customPalletForHaiku/branches/0.2/customPalletForHaiku.user.js

    r14640 r14712  
    33// @namespace      http://kojiran.googlepages.com/ 
    44// @include        http://h.hatena.ne.jp/* 
    5 // @version        0.14 
     5// @version        0.2 
    66// 
    7 // patched by gan2 , lieutar. 
    8 // Original userscript is written by MichaL. 
     7// patched by gan2, lieutar. 
     8// Original userscript is written by MichaeL. 
    99// Idea for this script from lieutar. 
    1010// 
    1111// SEE ALSO: http://wedata.net/databases/hatena-CustomPalletForHaiku 
    12 //  
     12// 
    1313// ==/UserScript== 
    1414 
     
    1919 
    2020 
    21   // ��("ffffff")�͒lj�����v�Ȃ� 
    2221  unsafeWindow.CustomPalletForHaikuPallets = null; 
    2322 
     
    5150 
    5251    return { 
    53         fetch: function(){ 
    54           GM_xmlhttpRequest({ 
    55             method: 'GET', 
    56             url:     WEDATA_FETCH, 
    57             onload: function(res) { 
    58               if ( res.status != 200 ){ 
    59                 alert('something wrong...' + 
    60                       res.status + 
    61                       ' ' + 
    62                       res.statusText ); 
    63                 return; 
    64               } 
    65               var error; 
    66               try { 
    67                 var items = eval("( " + res.responseText + " )"); 
    68                 if (!( items instanceof Array )) throw new Error; 
    69                 var dic = {}; 
    70                 items.forEach( function(item){ 
    71                   dic[item.name] = item.data.colors.split(/\s+/); 
    72                 }); 
    73  
    74               } catch ( error ) { 
    75                 alert("received a malformed data." 
    76                       // + "\n" + error + "\n" + res.responseText 
    77                       ); 
    78                 return; 
    79               } 
    80               var javascriptlet = 
    81                 'javascript:void(window.CustomPalletForHaikuPallets=' + 
    82                 dic.toSource() + ')'; 
    83               location.href = javascriptlet; 
    84             } 
    85           }); 
    86         }, 
    87  
    88         fix: function( name, pallet ){ 
    89           if( !confirm('really ??') ) return; 
    90           var data = { name: name , data: { colors: pallet } }; 
    91           if ( unsafeWindow.CustomPalletForHaikuPallets[name] instanceof Array ) { 
    92             modify( data ); 
    93           } else { 
    94             put( data ); 
    95           } 
    96         } 
    97       }; 
     52      fetch: function(){ 
     53        GM_xmlhttpRequest({ 
     54          method: 'GET', 
     55          url:     WEDATA_FETCH, 
     56          onload: function(res) { 
     57            if ( res.status != 200 ){ 
     58              alert('something wrong...' + 
     59                    res.status + 
     60                    ' ' + 
     61                    res.statusText ); 
     62              return; 
     63            } 
     64            var error; 
     65            try { 
     66              var items = eval("( " + res.responseText + " )"); 
     67              if (!( items instanceof Array )) throw new Error; 
     68              var dic = {}; 
     69              items.forEach( function(item){ 
     70                dic[item.name] = item.data.colors.split(/\s+/); 
     71              }); 
     72            } catch ( error ) { 
     73              alert("received a malformed data." 
     74                    // + "\n" + error + "\n" + res.responseText 
     75                   ); 
     76              return; 
     77            } 
     78            var javascriptlet = 
     79              'javascript:void(window.CustomPalletForHaikuPallets=' + 
     80              dic.toSource() + ')'; 
     81            location.href = javascriptlet; 
     82          } 
     83        }); 
     84      }, 
     85 
     86      fix: function( name, pallet ){ 
     87        if( !confirm('really ??') ) return; 
     88        var data = { name: name , data: { colors: pallet } }; 
     89        if ( unsafeWindow.CustomPalletForHaikuPallets[name] instanceof Array ) { 
     90          modify( data ); 
     91        } else { 
     92          put( data ); 
     93        } 
     94      } 
     95    }; 
    9896  })(); 
    9997 
    10098  Wedata.fetch(); 
    101    
    10299 
    103100  // Below script can not work with GM_* methods.. 
     
    123120      } 
    124121 
    125       // initialize ...  
     122      // initialize ... 
    126123      function initSelector(){ 
    127124        var entryForm     = $X('.//form[@class="entry-form"]')[0]; 
    128125        var textContainer = $X('div[@class="text-container"]', entryForm)[0]; 
    129126        var colors = $N('span', {style: ["margin: 5px 5px"].join(';'), 
    130                                  id: 'pallet-colors'}); 
     127          id: 'pallet-colors'}); 
    131128        var changer = function () { 
    132129          for (var i = 0, l = colors.childNodes.length; i < l; i++) { 
     
    135132          CustomPalletForHaikuPallets[select.value].forEach(function (color) { 
    136133            var cell = $N('span', {style: [ 
    137                                            "background: #" + color, 
    138                                            "padding: 2px 5px" 
    139                                    ].join(';')}); 
     134              "background: #" + color, 
     135              "padding: 2px 5px" 
     136            ].join(';')}); 
    140137            colors.appendChild(cell); 
    141138          }); 
     
    151148        } 
    152149 
    153       // add hooks for original Hatena objects. 
    154       SWFObject = function() { 
    155         deconcept.SWFObject.apply(this, arguments); 
    156         this.addVariable("colors", 
    157                          CustomPalletForHaikuPallets[select.value]); 
    158         //select.style.display = 'none'; 
    159         //colors.style.display = 'none'; 
    160       }; 
    161       SWFObject.prototype = deconcept.SWFObject.prototype; 
    162        
    163       (function(orig){ 
    164         Hatena.Haiku.EntryForm.prototype.writeDrawForm = function(){ 
    165           if ( this.canvas ){ 
    166             var canvas = this.canvas; 
    167             var swf = canvas.getSWF(); 
    168             swf.parentNode.removeChild( swf ); 
    169             delete Hatena.Haiku.Canvas.canvases[canvas.canvasID]; 
    170           } 
    171           var retval = orig.apply(this, arguments); 
    172           var swf = this.canvas.getSWF(); 
    173           this.hasDrawForm = false; 
    174           return retval; 
     150        var $E = Ten.DOM.getElementsByTagAndClassName; 
     151        var textSelector = $E('img', 'input-selector-text')[0]; 
     152        new Ten.Observer(textSelector, 'onclick', function () { 
     153          select.style.display = 'inline'; 
     154          colors.style.display = 'inline'; 
     155        }); 
     156        var drawSelector = $E('img', 'input-selector-draw')[0]; 
     157        new Ten.Observer(drawSelector, 'onclick', function () { 
     158          select.style.display = 'none'; 
     159          colors.style.display = 'none'; 
     160        }); 
     161        var webcamSelector = $E('img', 'input-selector-webcam')[0]; 
     162        new Ten.Observer(webcamSelector, 'onclick', function () { 
     163          select.style.display = 'none'; 
     164          colors.style.display = 'none'; 
     165        }); 
     166 
     167        // add hooks for original Hatena objects. 
     168        SWFObject = function() { 
     169          deconcept.SWFObject.apply(this, arguments); 
     170          this.addVariable("colors", 
     171                           CustomPalletForHaikuPallets[select.value]); 
    175172        }; 
    176       })(Hatena.Haiku.EntryForm.prototype.writeDrawForm); 
    177  
     173        SWFObject.prototype = deconcept.SWFObject.prototype; 
     174         
     175        (function(orig){ 
     176          Hatena.Haiku.EntryForm.prototype.writeDrawForm = function(){ 
     177            if ( this.canvas ){ 
     178              var canvas = this.canvas; 
     179              var swf = canvas.getSWF(); 
     180              swf.parentNode.removeChild( swf ); 
     181              delete Hatena.Haiku.Canvas.canvases[canvas.canvasID]; 
     182            } 
     183            var retval = orig.apply(this, arguments); 
     184            var swf = this.canvas.getSWF(); 
     185            this.hasDrawForm = false; 
     186            return retval; 
     187          }; 
     188        })(Hatena.Haiku.EntryForm.prototype.writeDrawForm); 
    178189 
    179190        entryForm.insertBefore(select, textContainer); 
     
    211222      } 
    212223 
    213     // $X 
    214     // based on: http://lowreal.net/blog/2007/11/17/1 
    215     // 
    216     // $X(exp); 
    217     // $X(exp, context); 
    218     // $X(exp, type); 
    219     // $X(exp, {context: context, 
    220     //          type: type, 
    221     //          namespace: {h:"http://www.w3.org/1999/xhtml"}}); 
    222     function $X (exp, context) { 
    223       var type, namespace={}; 
    224       // console.log(String(exp)); 
    225       if(typeof context == "function"){ 
    226         type = context; 
    227         context = null; 
    228       }else if(typeof context != "undefined" && !context['nodeType']){ 
    229         type = context['type']; 
    230         namespace = context['namespace'] || context['ns']; 
    231         context = context['context']; 
    232       } 
    233  
    234       if (!context) context = document; 
    235       var exp = (context.ownerDocument || context).createExpression(exp, function (prefix) { 
    236         return namespace[prefix] || 
    237           document.createNSResolver((context.ownerDocument == null ? context : context.ownerDocument) 
    238                                     .documentElement).lookupNamespaceURI(prefix) || 
    239           document.documentElement.namespaceURI; 
    240       }); 
    241  
    242       switch (type) { 
    243       case String: 
    244         return exp.evaluate( 
    245           context, 
    246           XPathResult.STRING_TYPE, 
    247           null 
    248         ).stringValue; 
    249       case Number: 
    250         return exp.evaluate( 
    251           context, 
    252           XPathResult.NUMBER_TYPE, 
    253           null 
    254         ).numberValue; 
    255       case Boolean: 
    256         return exp.evaluate( 
    257           context, 
    258           XPathResult.BOOLEAN_TYPE, 
    259           null 
    260         ).booleanValue; 
    261       case Array: 
    262         var result = exp.evaluate( 
    263           context, 
    264           XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, 
    265           null 
    266         ); 
    267         var ret = []; 
    268         for (var i = 0, len = result.snapshotLength; i < len; ret.push(result.snapshotItem(i++))); 
    269         return ret; 
    270       case undefined: 
    271         var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); 
    272         switch (result.resultType) { 
    273         case XPathResult.STRING_TYPE : return result.stringValue; 
    274         case XPathResult.NUMBER_TYPE : return result.numberValue; 
    275         case XPathResult.BOOLEAN_TYPE: return result.booleanValue; 
    276         case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { 
    277           // not ensure the order. 
     224      // $X 
     225      // based on: http://lowreal.net/blog/2007/11/17/1 
     226      // 
     227      // $X(exp); 
     228      // $X(exp, context); 
     229      // $X(exp, type); 
     230      // $X(exp, {context: context, 
     231      //          type: type, 
     232      //          namespace: {h:"http://www.w3.org/1999/xhtml"}}); 
     233      function $X (exp, context) { 
     234        var type, namespace={}; 
     235        // console.log(String(exp)); 
     236        if(typeof context == "function"){ 
     237          type = context; 
     238          context = null; 
     239        }else if(typeof context != "undefined" && !context['nodeType']){ 
     240          type = context['type']; 
     241          namespace = context['namespace'] || context['ns']; 
     242          context = context['context']; 
     243        } 
     244 
     245        if (!context) context = document; 
     246        var exp = (context.ownerDocument || context).createExpression(exp, function (prefix) { 
     247          return namespace[prefix] || 
     248            document.createNSResolver((context.ownerDocument == null ? context : context.ownerDocument) 
     249                                      .documentElement).lookupNamespaceURI(prefix) || 
     250            document.documentElement.namespaceURI; 
     251        }); 
     252 
     253        switch (type) { 
     254        case String: 
     255          return exp.evaluate( 
     256            context, 
     257            XPathResult.STRING_TYPE, 
     258            null 
     259          ).stringValue; 
     260        case Number: 
     261          return exp.evaluate( 
     262            context, 
     263            XPathResult.NUMBER_TYPE, 
     264            null 
     265          ).numberValue; 
     266        case Boolean: 
     267          return exp.evaluate( 
     268            context, 
     269            XPathResult.BOOLEAN_TYPE, 
     270            null 
     271          ).booleanValue; 
     272        case Array: 
     273          var result = exp.evaluate( 
     274            context, 
     275            XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, 
     276            null 
     277          ); 
    278278          var ret = []; 
    279           var i = null; 
    280           while (i = result.iterateNext()) { 
    281             ret.push(i); 
    282           } 
     279          for (var i = 0, len = result.snapshotLength; i < len; ret.push(result.snapshotItem(i++))); 
    283280          return ret; 
    284         } 
    285         } 
    286         return null; 
    287       default: 
    288         throw(TypeError("$X: specified type is not valid type.")); 
    289       } 
    290     } 
    291   }) (this.unsafeWindow || window); 
     281        case undefined: 
     282          var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); 
     283          switch (result.resultType) { 
     284          case XPathResult.STRING_TYPE : return result.stringValue; 
     285          case XPathResult.NUMBER_TYPE : return result.numberValue; 
     286          case XPathResult.BOOLEAN_TYPE: return result.booleanValue; 
     287          case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: { 
     288            // not ensure the order. 
     289            var ret = []; 
     290            var i = null; 
     291            while (i = result.iterateNext()) { 
     292              ret.push(i); 
     293            } 
     294            return ret; 
     295          } 
     296          } 
     297          return null; 
     298        default: 
     299          throw(TypeError("$X: specified type is not valid type.")); 
     300        } 
     301      } 
     302    }) (this.unsafeWindow || window); 
    292303  }.toString() + ')()'; 
    293304