Show
Ignore:
Timestamp:
06/26/08 21:13:04 (5 months ago)
Author:
gan2
Message:

リビジョン 14602 の状態に戻した

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/customPalletForHaiku/tags/0.1.4/customPalletForHaiku.user.js

    r14641 r14644  
    55// @version        0.14 
    66// 
    7 // patched by gan2 , lieutar. 
    8 // Original userscript is written by MichaL. 
    9 // Idea for this script from lieutar. 
     7// patched by gan2 
     8// Idea for this script from lieutar 
    109// 
    11 // SEE ALSO: http://wedata.net/databases/hatena-CustomPalletForHaiku 
    12 //  
    1310// ==/UserScript== 
    1411 
    15 (function(){ 
    16    
    17   if ( !(unsafeWindow && unsafeWindow.Hatena && unsafeWindow.Hatena.Star) ) 
    18     return; 
    19  
    20  
    21   // ��("ffffff")�͒lj�����v�Ȃ� 
    22   unsafeWindow.CustomPalletForHaikuPallets = null; 
    23  
    24   var WEDATA_BASE  = 'http://wedata.net/databases/hatena-CustomPalletForHaiku'; 
    25   var WEDATA_FETCH = WEDATA_BASE + '/items.json' 
    26  
    27   // -------- 
    28   function log () { 
    29     var c = unsafeWindow.console; 
    30     if (c) { 
    31       c.log.apply(c, arguments); 
    32     } 
    33   } 
    34  
    35   //  
    36   var Wedata = (function(){ 
    37  
    38     function getHatenaID (){ 
    39       return unsafeWindow.Hatena.Visitor.name; 
    40     } 
    41  
    42     //TODO: implement me! 
    43     function put ( data ) { 
    44       throw new Error ( 'this operation is not supported still' ); 
    45     } 
    46  
    47     //TODO: implement me! 
    48     function modify ( data ) { 
    49       throw new Error ( 'this operation is not supported still' ); 
    50     } 
    51  
    52     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         } 
     12location.href = 'javascript:(' + function() { 
     13  (function (w) { 
     14    if (w && w.Hatena && w.Hatena.Star) { 
     15      // 白("ffffff")は追加する必要なし 
     16      var pallets = { 
     17        'original': [ 
     18          "dedfde", "9ca2a5", "292829", 
     19          "de3039", "732c00", "f7b29c", "ffdf4a", 
     20          "7bbead", "295d52", "8cc7ef", "736dad" 
     21        ], 
     22        'kikuyamaru': [ 
     23          "000000", "eefd4c", "fef40c", "d6b331", 
     24          "9d5038", "f94a29", "dd001d", "91e71e", 
     25          "0c6c54", "2842bd", "2d366c", "1a1819", 
     26          "333333", "666666", "999999", "cccccc", 
     27          "fdd386", "ffcba6", "3e3725", "a700ad", 
     28          "356843", "1190b1", "4b00d4", "fed50c", 
     29          "fff381", "fd7622", "e85e66", "129e36", 
     30          "5f713a", "f9518d", "62c3e1" 
     31        ], 
     32        'gan2': [ 
     33          "dedfde", "c6c7c6", "9ca2a5", "63696b", "313431", "212421", // 黒 
     34          "ffcfce", "f7aaad", "e74d52", "de3039", // 赤 
     35          "b58a73", "9c6142", "732800", "4a2008", // 茶 
     36          "ffdfd6", "ffd3c6", "ffc3ad", "ffb29c", // 肌 
     37          "ffef94", "ffdf4a", // 黄 
     38          "f7b28c", "ef8242", "de7d4a", // 橙 
     39          "def3ef", "addbce", "7bbead", "316d63", "295d52", // 緑 
     40          "d6ebff", "8ccbef", "7b96ce", // 水 
     41          "b5aed6", "7b75b5" // 紫 
     42        ], 
     43        'wacom': [ 
     44          "f6d001", "9b3279", "d70067", "71a334", "016c9a" 
     45        ], 
     46        'dwacom': [ 
     47          "dedfde","9ca2a5","292829","de3039", 
     48          "732c00","f7b29c","ffdf4a","7bbead", 
     49          "295d52","8cc7ef","736dad","f6d001", 
     50          "9b3279","d70067","71a334","016c9a" 
     51        ] 
    9752      }; 
    98   })(); 
    99  
    100   Wedata.fetch(); 
    101    
    102  
    103   // Below script can not work with GM_* methods.. 
    104   // But work with real window object. 
    105   location.href = 'javascript:(' + function() { 
    106     (function (w) { 
    107  
    108       function log () { 
    109         var c = w.console; 
    110         if (c) { 
    111           c.log.apply(c, arguments); 
    112         } 
    113       } 
    114  
    115       function delayUntill( cond, action , max ){ 
    116         setTimeout( function(){ 
    117           if ( cond() ) { 
    118             action(); 
    119           } else if ( max > 0 ){ 
    120             delayUntill( cond , action , max - 1 ); 
    121           } 
    122         }, 10 ); 
    123       } 
    124  
    125       // initialize ...  
    126       function initSelector(){ 
    127         var entryForm     = $X('.//form[@class="entry-form"]')[0]; 
    128         var textContainer = $X('div[@class="text-container"]', entryForm)[0]; 
    129         var colors = $N('span', {style: ["margin: 5px 5px"].join(';'), 
    130                                  id: 'pallet-colors'}); 
    131         var changer = function () { 
    132           for (var i = 0, l = colors.childNodes.length; i < l; i++) { 
    133             colors.removeChild(colors.firstChild); 
    134           } 
    135           CustomPalletForHaikuPallets[select.value].forEach(function (color) { 
    136             var cell = $N('span', {style: [ 
    137                                            "background: #" + color, 
    138                                            "padding: 2px 5px" 
    139                                    ].join(';')}); 
    140             colors.appendChild(cell); 
    141           }); 
    142           entryForm.insertBefore(colors, textContainer); 
    143         }; 
    144         var select = $N('select', { 
    145           name: 'pallets', 
    146           style: ["width: 300px", "margin: 2px 0px"].join(';')}); 
    147         select.addEventListener('change', changer, false); 
    148         for (var p in CustomPalletForHaikuPallets) { 
    149           var opt = $N('option', {value: p}, p); 
    150           select.appendChild(opt); 
    151         } 
    152  
    153       // add hooks for original Hatena objects. 
     53 
     54      var entryForm = $X('.//form[@class="entry-form"]')[0]; 
     55      var textContainer = $X('div[@class="text-container"]', entryForm)[0]; 
     56      var colors = $N('span', {style: ["margin: 5px 5px"].join(';'), id: 'pallet-colors'}); 
     57      var changer = function () { 
     58        for (var i = 0, l = colors.childNodes.length; i < l; i++) { 
     59          colors.removeChild(colors.firstChild); 
     60        } 
     61        pallets[select.value].forEach(function (color) { 
     62          var cell = $N('span', {style: [ 
     63            "background: #" + color, 
     64            "padding: 2px 5px" 
     65          ].join(';')}); 
     66          colors.appendChild(cell); 
     67        }); 
     68        entryForm.insertBefore(colors, textContainer); 
     69      }; 
     70      var select = $N('select', { 
     71        name: 'pallets', 
     72        style: ["width: 300px", "margin: 2px 0px"].join(';')}); 
     73      select.addEventListener('change', changer, false); 
     74      for (var p in pallets) { 
     75        var opt = $N('option', {value: p}, p); 
     76        select.appendChild(opt); 
     77      } 
     78      entryForm.insertBefore(select, textContainer); 
     79      changer(); 
     80 
    15481      SWFObject = function() { 
    15582        deconcept.SWFObject.apply(this, arguments); 
    156         this.addVariable("colors", 
    157                          CustomPalletForHaikuPallets[select.value]); 
     83        this.addVariable("colors", pallets[select.value]); 
    15884        //select.style.display = 'none'; 
    15985        //colors.style.display = 'none'; 
     
    175101        }; 
    176102      })(Hatena.Haiku.EntryForm.prototype.writeDrawForm); 
    177  
    178  
    179         entryForm.insertBefore(select, textContainer); 
    180         changer(); 
    181       } 
    182  
    183       delayUntill( function(){ return CustomPalletForHaikuPallets } , 
    184                    initSelector, 100 ); 
    185  
    186  
    187  
    188       // utilities 
    189       function $N(name, attr, childs) { 
    190         var ret = document.createElement(name); 
    191         for (var k in attr) if (attr.hasOwnProperty(k)) { 
    192           var v = attr[k]; 
    193           if (k == "class") ret.className = v; 
    194           else ret.setAttribute(k, v); 
    195         } 
    196         switch(typeof childs){ 
    197         case "string": 
    198           ret.appendChild(document.createTextNode(childs)); 
    199           break; 
    200         case "object": 
    201           for (var i=0, len=childs.length; i<len; i++) { 
    202             var child = childs[i]; 
    203             if (typeof child == "string") { 
    204               ret.appendChild(document.createTextNode(child)); 
    205             } else { 
    206               ret.appendChild(child); 
    207             } 
     103    } 
     104 
     105 
     106    // -------- 
     107    function log () { 
     108      var c = w.console; 
     109      if (c) { 
     110        c.log.apply(c, arguments); 
     111      } 
     112    } 
     113 
     114    function $N(name, attr, childs) { 
     115      var ret = document.createElement(name); 
     116      for (var k in attr) if (attr.hasOwnProperty(k)) { 
     117        var v = attr[k]; 
     118        if (k == "class") ret.className = v; 
     119        else ret.setAttribute(k, v); 
     120      } 
     121      switch(typeof childs){ 
     122      case "string": 
     123        ret.appendChild(document.createTextNode(childs)); 
     124        break; 
     125      case "object": 
     126        for (var i=0, len=childs.length; i<len; i++) { 
     127          var child = childs[i]; 
     128          if (typeof child == "string") { 
     129            ret.appendChild(document.createTextNode(child)); 
     130          } else { 
     131            ret.appendChild(child); 
    208132          } 
    209133        } 
    210         return ret; 
    211       } 
     134      } 
     135      return ret; 
     136    } 
    212137 
    213138    // $X 
     
    290215    } 
    291216  }) (this.unsafeWindow || window); 
    292   }.toString() + ')()'; 
    293  
    294 })(); 
     217}.toString() + ')()';