2007-02-19 bookmarklet 版 bookmarklet maker bookmarklet ajax 2008/01/26 追記 最新版(といってもだいぶ前に書いたもの。機能追加はしていません)です。下の改行付きのコードとは異なります。 javascript:(function(){function $(x){return document.getElementById(x);}function tgl(){if($('bmmaker').clientHeight>0){hide();}else{show();}}function show(){$('bmmaker').style.display='block';$('bmmaker_1').focus();}function hide(){$('bmmaker').style.display='none';}function globalEvents(){document.documentElement.addEventListener('dblclick',show,false);document.documentElement.addEventListener('click',clickHide,false);window.addEventListener('keypress',keyToggle,false);}function remove(){hide();$('bmmaker').parentNode.removeChild($('bmmaker'));document.documentElement.removeEventListener('dblclick',show,false);document.documentElement.removeEventListener('click',clickHide,false);window.removeEventListener('keypress',keyToggle,false);}function clickHide(e){if(e.target==$('start'))return;var b=$('bmmaker');var p=e.target;while(p){if(p==b) return;p=p.parentNode;}hide();}function keyToggle(e){if(e.ctrlKey&&e.which==32){e.preventDefault();tgl();}}function edited(){var edit=$('bmmaker_1');var t=edit.value;if(edit.selectionStart!=edit.selectionEnd){t=t.substring(edit.selectionStart,edit.selectionEnd);}t=t.replace(/(^|[^:\\])\/\/.*/g,'$1');t=t.replace(/^\s+|\s+$/g,'');t=t.replace(/\s*(\r)?\n\s*/g,'');if(!/^javascript:/.test(t))t='javascript:'+t;$('bmmaker_2').value=t;$('bmmaker_link').href=t;$('bmmaker_count').innerHTML='('+t.length+' chars)';}var b=$('bmmaker');if(b){show();return;}var d=document;b=d.createElement('div');b.id='bmmaker';d.body.appendChild(b);with(b.style){width='95%';height='60%';margin='1%';padding='5px 1% 5px 1%';position='absolute';zIndex='99999';top='10%';left='0';color='black';backgroundColor='white';border='#8EB9FF solid 1px';textAlign='left';fontSize='15px';fontFamily='monospace';}var s=[];s.push('','script:<\/p>','','×','<\/p>','','(function(){\n \n})()<\/textarea>','<\/div>','','テスト実行<\/button>','非表示<\/button>','bookmarklet<\/a><\/span>','<\/p>','<\/div>','','script(space removed):<\/p>','','<\/textarea>','<\/div>','<\/div>');b.innerHTML=s.join('');if(/Gecko\//i.test(navigator.userAgent)||document.compatMode!='BackCompat'){b.style.paddingBottom='80px';$('bmmaker_view').style.marginTop='50px';}show();$('bmmaker_1').onkeyup=edited;$('bmmaker_1').onmouseup=edited;$('bmmaker_2').onfocus=function(){$('bmmaker_2').select()};$('bmmaker_do').onclick=function(){try {eval($('bmmaker_2').value);}catch(e){alert(e);}};$('bmmaker_hide').onclick=hide;$('bmmaker_close').onclick=remove;globalEvents();})() - bookmarklet maker が非常に便利なので Ajax 開発向けに bookmarklet にしました。 (2007/02/20)行コメント削除の正規表現に誤りがあったので修正。あとリンクと文字数表示を追加。 javascript:(function(){var d=document,$=function(x){return d.getElementById(x)},b,s=[];b=$('bmmaker');if(!b){b=d.createElement('div');b.id='bmmaker';d.body.appendChild(b);s.push('script:');s.push('(function(){\n \n})()<\/textarea>');s.push('実行<\/button> ');s.push('クリア<\/button>閉じる<\/button>');s.push(' bookmarklet<\/a> <\/span>');s.push('<\/div>');s.push('script(space removed):');s.push('<\/textarea>');s.push('<\/div>');b.innerHTML=s.join('');$('bmmaker_1').onkeyup=function(){var t=$('bmmaker_1').value;t=t.replace(/(^|[^:])\/\/.*/g,'$1');t=t.replace(/\s*(\r)?\n\s*/g,'');if(!/^javascript:/.test(t))t='javascript:'+t;$('bmmaker_2').value=t;$('bmmaker_link').href=t;$('bmmaker_count').innerHTML='('+t.length+' chars)';};$('bmmaker_do').onclick=function(){location.href=$('bmmaker_2').value};$('bmmaker_clear').onclick=function(){$('bmmaker_1').value='(function(){\n \n})()';$('bmmaker_1').onkeyup()};$('bmmaker_close').onclick=function(){b.style.display='none'};}with(b.style){width='100%';height='60%';margin='0';padding='0';display='block';position='fixed';top='10%';left='0';background='silver';}})()改行付き javascript:(function(){ var d=document,$=function(x){return d.getElementById(x)},b,s=[]; b=$('bmmaker'); if(!b){ b=d.createElement('div'); b.id='bmmaker'; d.body.appendChild(b); s.push('<div>script:<br>'); s.push('<textarea id="bmmaker_1" style="width:100%;height:60%">(function(){\n \n})()<\/textarea>'); s.push('<br><button id="bmmaker_do">実行<\/button>  '); s.push('<button id="bmmaker_clear">クリア<\/button><button id="bmmaker_close">閉じる<\/button>'); s.push(' <a id="bmmaker_link">bookmarklet<\/a> <span id="bmmaker_count"><\/span>'); s.push('<\/div>'); s.push('<div>script(space removed):<br>'); s.push('<textarea id="bmmaker_2" style="width:100%;height:20%"><\/textarea>'); s.push('<\/div>'); b.innerHTML=s.join(''); $('bmmaker_1').onkeyup=function(){ var t=$('bmmaker_1').value; t=t.replace(/(^|[^:])\/\/.*/g,'$1'); // 行コメント削除(「://〜」は除外) t=t.replace(/\s*(\r)?\n\s*/g,''); // 改行回りの空白を除去 if(!/^javascript:/.test(t))t='javascript:'+t; $('bmmaker_2').value=t; $('bmmaker_link').href=t; $('bmmaker_count').innerHTML='('+t.length+' chars)'; }; $('bmmaker_do').onclick=function(){location.href=$('bmmaker_2').value}; $('bmmaker_clear').onclick=function(){$('bmmaker_1').value='(function(){\n \n})()';$('bmmaker_1').onkeyup()}; $('bmmaker_close').onclick=function(){b.style.display='none'}; } with(b.style){ width='100%'; height='60%'; margin='0'; padding='0'; display='block'; position='fixed'; top='10%'; left='0'; background='silver'; } })() 例えば Google のトップページでこの bookmarklet を実行すると、Google の検索結果に Ajax アクセスする bookmarklet が書きやすくなります。 - こうなるとコードアシストも欲しくなるなぁ。できるかな? « これからドラッグ&ドロップを書く人のた… 毎度 IE6 でハマる »