Skip to content

Instantly share code, notes, and snippets.

@long-long-float
Last active December 22, 2015 13:49
Show Gist options
  • Save long-long-float/b404cf4b25cf500c3854 to your computer and use it in GitHub Desktop.
Save long-long-float/b404cf4b25cf500c3854 to your computer and use it in GitHub Desktop.
自動でフォームを埋めるブックマークレット
javascript:(function(){var d;d=function(a,b){var e;e=document.createElement('script');e.type='text/javascript';e.src=a;if(b){e.onloadDone=false;e.onload=function(){e.onloadDone=true;return b()};e.onReadystatechange=function(){if(e.readyState==='loaded'&&!e.onloadDone){e.onloadDone=true;return b()}}}if(typeof e!=='undefined'){return document.getElementsByTagName('head')[0].appendChild(e)}};d('//code.jquery.com/jquery-1.11.1.min.js',function(){var c,words;words=['hoge','fuga','piyo'];c=function(b){var i;return((function(){var a,_results;_results=[];for(i=a=1;1<=b?a<=b:a>=b;i=1<=b?++a:--a){_results.push(words[Math.floor(Math.random()*words.length)])}return _results})()).join(" ")};$('input').each(function(){var a,month,now,today;switch($(this).attr('type')){case'text':return $(this).val(c(3));case'number':return $(this).val(1);case'date':now=new Date();a=("0"+now.getDate()).slice(-2);month=("0"+(now.getMonth()+1)).slice(-2);today=now.getFullYear()+"-"+month+"-"+a;return $(this).val(today);case'radio':return $(this).attr('checked',true)}});return $('textarea').each(function(){return $(this).val(c(10))})})}).call(this);
loadScript = (src, callback) ->
e = document.createElement('script')
e.type = 'text/javascript'
e.src = src
if callback
e.onloadDone = false
e.onload = ->
e.onloadDone = true
callback()
e.onReadystatechange = ->
if e.readyState == 'loaded' and !e.onloadDone
e.onloadDone = true
callback()
if typeof(e) != 'undefined'
document.getElementsByTagName('head')[0].appendChild(e)
loadScript '//code.jquery.com/jquery-1.11.1.min.js', ->
words = ['hoge', 'fuga', 'piyo']
genWords = (count) ->
(words[Math.floor(Math.random() * words.length)] for i in [1..count]).join(" ")
$('input').each ->
switch $(this).attr('type')
when 'text'
$(this).val(genWords(3))
when 'number'
$(this).val(1)
when 'date'
now = new Date()
day = ("0" + now.getDate()).slice(-2)
month = ("0" + (now.getMonth() + 1)).slice(-2)
today = now.getFullYear()+"-"+(month)+"-"+(day)
$(this).val(today)
when 'radio'
$(this).attr('checked', true)
$('textarea').each ->
$(this).val(genWords(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment