<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel rdf:about="https://let.hatelabo.jp/tily/rss">
    <link>https://let.hatelabo.jp/tily/rss</link>
    <description></description>
    <title>Bookmarklets from tily</title>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="https://let.hatelabo.jp/tily/let/gYC-xbvG4IGfcA"/>
        <rdf:li rdf:resource="https://let.hatelabo.jp/tily/let/gYC-xJCi-NDTOQ"/>
      </rdf:Seq>
    </items>
  </channel>
  <item rdf:about="https://let.hatelabo.jp/tily/let/gYC-xbvG4IGfcA">
    <link>https://let.hatelabo.jp/tily/let/gYC-xbvG4IGfcA</link>
    <dc:date>2012-03-04T22:51:53Z</dc:date>
    <description>Cookpad Recipe Scalable</description>
    <dc:creator>tily</dc:creator>
    <title>[Let] Cookpad Recipe Scalable</title>
    <content:encoded>&lt;a href="javascript:%22https%3A%2F%2Flet.st-hatelabo.com%2Ftily%2Flet%2FgYC-xbvG4IGfcA.bookmarklet.js%20%28arg%29%22.replace%28%2F%28%5CS%2B%29%5Cs%2B%28%5CS%2A%29%2F%2Cfunction%28s%2Curl%2Carg%29%7Bs%3Ddocument.createElement%28%22script%22%29%3Bs.charset%3D%22utf-8%22%3Bs.src%3Durl%2B%22%3Fs%3D%22%2BencodeURIComponent%28arg%29%3Bdocument.body.appendChild%28s%29%7D%29%3Bvoid%280%29%3B"&gt;Cookpad Recipe Scalable&lt;/a&gt;&lt;pre&gt;/*
 * @title Cookpad Recipe Scalable
 * @description Cookpad Recipe Scalable
 * @include http://cookpad.com/recipe
 * @license MIT License
 */
// TODO: 曖昧表現 (少々、適量、多め、好きなだけ等)
(function() {

  // ----[main]-------------------------------

  var MULTI_NUMS = '０１２３４５６７８９'.split('');
  var DELICIOUS_REGEXP = /(肉|豚|ブタ|ぶた|牛|ビーフ|鳥|鶏|とり|トリ|バター|油|塩|しお|砂糖|さとう)/;
  var healthyLevel = 0;
  var byNum = 1;
  var html = [
    '&amp;lt;div id=&amp;quot;operations&amp;quot;&amp;gt;',
      '&amp;lt;h3&amp;gt;操作&amp;lt;/h3&amp;gt;',
      '&amp;lt;div&amp;gt;',
        '&amp;lt;button id=&amp;quot;healthier&amp;quot;&amp;gt;ヘルシーに&amp;lt;/button&amp;gt;',
        '&amp;lt;button id=&amp;quot;delicious&amp;quot;&amp;gt;うまそうに&amp;lt;/button&amp;gt;',
        '&amp;lt;button id=&amp;quot;clear&amp;quot;&amp;gt;クリア&amp;lt;/button&amp;gt;',
        '&amp;lt;input id=&amp;quot;by&amp;quot; type=&amp;quot;text&amp;quot; style=&amp;quot;width:3em&amp;quot; /&amp;gt;',
        '&amp;lt;button id=&amp;quot;multiply&amp;quot;&amp;gt;倍&amp;lt;/button&amp;gt;',
      '&amp;lt;/div&amp;gt;',
    '&amp;lt;/div&amp;gt;'
  ].join('');

  $('div#operations').remove();
  $('div#ingredients').before($(html));

  eachIngredient(function(name, quantity) {
    $.data(quantity.get(0), 'original', quantity.html());
  });
  $.data($('span.servings_for').get(0), 'original', $('span.servings_for').html());

  multiplyIngredients(byNum);
  multiplyServingsFor(byNum);

  $('button#healthier').click(function() {
    healthyLevel++;
    multiplyIngredients((1 - healthyLevel*0.1)*byNum, DELICIOUS_REGEXP);
  });
  $('button#delicious').click(function() {
    healthyLevel--;
    multiplyIngredients((1 - healthyLevel*0.1)*byNum, DELICIOUS_REGEXP);
  });
  $('button#clear').click(function() {
    healthyLevel = 0;
    byNum = 1;
    multiplyIngredients(byNum);
    multiplyServingsFor(byNum);
  });
  $('button#multiply').click(function() {
    byNum = $('input#by').val();
    multiplyIngredients(byNum);
    multiplyServingsFor(byNum);
  });

  // ----[utility]-----------------------------------

  function eachIngredient(callback) {
    $('div.ingredient_row').each(function() {
      var name = $('div.ingredient_name', this);
      var quantity = $('div.ingredient_quantity', this);
      if(name.size() &amp;gt; 0 &amp;amp;&amp;amp; quantity.size() &amp;gt; 0) callback(name, quantity);
    })
  }
  function multiplyIngredients(by, regex) {
    eachIngredient(function(name, quantity) {
      if(regex &amp;amp;&amp;amp; !regex.test(name.html())) return;
      var orig = $.data(quantity.get(0), 'original');
      var conv = replaceNumber(orig, function(n) { return round(n*by) });
      //console.log(name.html() + ':' + orig + ' -&amp;gt; ' + conv);
      quantity.html(conv);
    });
  }
  function multiplyServingsFor(by) {
    var orig = $.data($('span.servings_for').get(0), 'original');
    var conv = replaceNumber(orig, function(n) { return round(n*by) })
    $('span.servings_for').html(conv);
  }
  function round(n) {
    return Math.round(n*100)/100;
  }
  function replaceNumber(text, callback) {
    text = text
      .replace(/[０-９]/g, function(s) { return String.fromCharCode(s.charCodeAt(0) - 65248);})
      .replace(/([0-9]+)分の([0-9]+)/g, function(a, f, s) { return s + '/' ; f })
      .replace(/半分?/g, '0.5')
      .replace(/．/g, '.')
      .replace(/／/g, '/');
    text = text.replace(/(([0-9]+)(　|\s|と))?([0-9\.\/]+)/g, function(all, add, addnum, addsym, num) {
      //console.log(all, add, addnum, addsym, num);
      var n = eval(num);
      if(add) n = n + eval(addnum);
      return callback(n);
    });
    return text;
  }
})();&lt;/pre&gt;</content:encoded>
  </item>
  <item rdf:about="https://let.hatelabo.jp/tily/let/gYC-xJCi-NDTOQ">
    <link>https://let.hatelabo.jp/tily/let/gYC-xJCi-NDTOQ</link>
    <dc:date>2011-06-12T04:54:56Z</dc:date>
    <description>NoIME</description>
    <dc:creator>tily</dc:creator>
    <title>[Let] NoIME</title>
    <content:encoded>&lt;a href="javascript:%22https%3A%2F%2Flet.st-hatelabo.com%2Ftily%2Flet%2FgYC-xJCi-NDTOQ.bookmarklet.js%20%28arg%29%22.replace%28%2F%28%5CS%2B%29%5Cs%2B%28%5CS%2A%29%2F%2Cfunction%28s%2Curl%2Carg%29%7Bs%3Ddocument.createElement%28%22script%22%29%3Bs.charset%3D%22utf-8%22%3Bs.src%3Durl%2B%22%3Fs%3D%22%2BencodeURIComponent%28arg%29%3Bdocument.body.appendChild%28s%29%7D%29%3Bvoid%280%29%3B"&gt;NoIME&lt;/a&gt;&lt;pre&gt;/*
 * @title NoIME
 * @description NoIME
 * @include http://*
 * @license MIT License
 * @require http://dl.dropbox.com/u/511116/noime/roma.js
 * @require http://dl.dropbox.com/u/511116/noime/noime.js
 * @require jQuery
 */
$(&amp;quot;textarea,input[type='text']&amp;quot;).each(function(){ NoIME(this) })&lt;/pre&gt;</content:encoded>
  </item>
</rdf:RDF>
