hack のためのネタ帳, etc,,,

Google Maps の現在位置に pin を打ちます。スケールも保存します。
javascript:(function(){var d,q,l=document.getElementById('link'); if(l&&l.href&&l.href.match('^(.*ll=)([^&]*)(.*)$')) {if(d=window.prompt('Description','here')) {q='q='+RegExp.$2+'+('+encodeURIComponent(d)+')'; if(l.href.match('^(.*)(q=[^&]*)(.*)$')) {location.href=RegExp.$1+q+RegExp.$3;} else {location.href=l.href+'&'+q;}}}})();
2009-10-20:
仕様が変ったのかも?
シンプルにしてみた。
javascript:(function(){var d,q,l=document.getElementById('link'),h=l?l.href:'',z=h.match('[?&](z=[0-9]*)')?RegExp.$1:'';if(h.match('[?&]ll=([^&]*)')){if(d=prompt('Description','here')){q=RegExp.$1+'('+encodeURIComponent(d)+')';location.href='http%3A//maps.google.com/maps?iwloc=A&'+z+'&q='+q;}}})();

SourceForge

SourceForge の download ページ(ダウンロードのダイアログが出るページ)でミラーの一覧を得ます。

aria2c とかに食わせると幸せになれるかも?
と思って作ってみたけど意外と速度が稼げず。
ラスト1マイルがボトルネックとかかなぁ???
javascript:(function(){var D=document,O=D.all?"onreadystatechange":"onload",e=D.getElementsByTagName("A"),f=D.createElement("IFRAME"),s="",b=location.toString().match(/^.*download/)+"?use_mirror=",i=0;for(;i<e.length;i++){if(e[i].href.match("mirror_choices")){f.src=e[i].href;f[O]=function(){var e=f.contentWindow.document.getElementsByName("mirror"),i=1;for(;i<e.length;i++){s+=" "+b+e[i].value.split(",")[0];}prompt("mirrors",s);};f.width=f.height=1;D.body.appendChild(f);break;}}})();

FORM 入力の補助

resizable Element (last update: 2007-02-02)

フォーカスしている Element のサイズを変更可能にします。
CTRL+カーソルキーで伸縮、CTRL+Pauseで最大化します。
javascript:(function(){document["onkey"+(document.all?"down":"press")]=function(e){if(!e){e=event;e.target=e.srcElement;}var t=e.target;w=t.offsetWidth,h=t.offsetHeight;if(e.ctrlKey){switch(e.keyCode){case 3:case 19:t.style.width="100%";return false;case 39:w+=32;case 37:w-=16;w=w<16?16:w;t.style.width=w+"px";return false;case 40:h+=32;case 38:h-=16;h=h<16?16:h;t.style.height=h+"px";return false;}}}})();

resizable TEXTAREA (last update: 2007-02-02)

全ての TEXTAREA を幅 100%、高さ 30em にし、伸縮ボタンを追加します。
javascript:(function(){var D=document,B="insertBefore",C="onclick",H="height",e=D.getElementsByTagName("TEXTAREA"),i=0,f=function(s,d){return function(){s[H]=(parseInt(s[H])+d)+"em"}};for(;i<e.length;i++){var t=e[i],s=t.style,p=t.parentNode,b=D.createElement("INPUT");b.type="button";b.value="-";b[C]=f(s,-4);p[B](b,t);b=b.cloneNode(0);b.value="+";b[C]=f(s,4);p[B](b,t);s.width="100%";s[H]="30em";}})();

toggle maximize TEXTAREA (last update: 2009-09-29)

TEXTAREA をダブルクリックしたとき「最大化/元に戻す」のトグル動作するようにします。
javascript:(function(){var d=document,f=d.forms,b=d.body,a=d.getElementsByTagName("TEXTAREA"),p={width:0,height:0,top:0,left:0,position:0},i,o="ondblclick";function n(d,s,k){for(k in p)d[k]=s[k]==null?null:s[k];};for(i=0;i<a.length;i++){a[i][o]=function(){var s=this.style,e=this[o];if(e.tgl=!e.tgl){n(e,s);s.position="absolute";s.top=s.left=0;s.width=s.height="100%";}else{n(s,e);}}}})();

sort SELECT (last update: 2009-09-30)

SELECT 要素をソートします。
javascript:(function() {var d=document,g="getElementsByTagName",S=d[g]("SELECT"),t=d.all?"innerText":"textContent",i,j,s,o,c;for(i=0;i<S.length;i++){s=S[i],o=s[g]("OPTION"),c=[];for(j=0;j<o.length;j++)c.push(o[j]);c.sort(function(a,b){return a[t]<b[t]?-1:b[t]<a[t]?1:0});for(j=0;j<c.length;j++)s.appendChild(c[j]);}})();
SELECT 要素をフィルターします。
livedoor wiki のカテゴリー選択のように、大量の OPTION 要素を含む SELECT 要素等の操作性を格段に向上できます。
IE対応簡易版 (new: 2010-05-31)
javascript:(function(){var i,D=document,C="createElement",I="insertBefore",L="length",G="getElementsByTagName",e=D[G]("SELECT"),N=null;for(i=0;i<e[L];i++)(function(e){if(!e.fltr){e.fltr=1;var i,k="innerText",P=e.parentNode,t=D[C]("INPUT"),b=[],l=e[G]("OPTION");k=e[k]?k:"textContent";e.style.height=(e.size=20)+"em";P[I](t,P[I](D[C]("BR"),e));for(i=0;i<l[L];i++){b.push(l[i])}t.onkeyup=function(){for(i=0;i<b[L];i++){if(b[i][k].match(t.value))e[I](b[i],N);else e.removeChild(e[I](b[i],N),N);}}}})(e[i]);})();
IE非対応版(文字数過多のため) (new: 2011-02-08)
javascript:(function(){var i,D=document,C="createElement",I="insertBefore",L="length",V="value",F="INPUT",G="getElementsByTagName",e=D[G]("SELECT"),N=null;for(i=0;i<e[L];i++)(function(e){if(!e.fltr){e.fltr=1;var i,k="innerText",P=e.parentNode,t=D[C](F),s=D[C](F),x=D[C](F),b=[],l=e[G]("OPTION");k=e[k]?k:"textContent";s.type=x.type="button";s[V]="-";x[V]="+";s.onclick=function(){e.size=1};x.onclick=function(){e.style.height=(e.size=20)+"em"};P[I](s,P[I](x,P[I](t,P[I](D[C]("BR"),e))));for(i=0;i<l[L];i++){b.push(l[i]);l[i][k]=l[i][V]+":"+l[i][k]}t.onkeyup=function(){for(i=0;i<b[L];i++){if(b[i][k].match(t[V]))e[I](b[i],N);else{e[I](b[i],N);e.removeChild(b[i]);}}}}})(e[i]);})();

show form value (new: 2010-06-02)

radio, checkbox, option の value をラベルに表示します。
javascript:(function(){var e = document.getElementsByTagName("INPUT");for (var i = 0; i < e.length; i++) {if(e[i].type.match(/checkbox|radio/)) {e[i].parentNode.insertBefore(document.createTextNode(e[i].value + ": "), e[i].nextSibling);}}var e = document.getElementsByTagName("OPTION");for (var i = 0; i < e.length; i++) {e[i].insertBefore(document.createTextNode(e[i].value + ": "), e[i].firstChild);}})();
2015-05-01 修正
javascript:(function(){var e,i;e=document.getElementsByTagName("INPUT");for(i=0;i<e.length;i++){if(e[i].type.match(/checkbox|radio/)){e[i].parentNode.insertBefore(document.createTextNode(e[i].name+":"+e[i].value+": "),e[i].nextSibling);}}e=document.getElementsByTagName("OPTION");for(i=0;i<e.length;i++){e[i].insertBefore(document.createTextNode(e[i].name+":"+e[i].value+": "),e[i].firstChild);}})();

append Option (new: 2013-08-01)

SELECT 要素に OPTION を追加します。
javascript:(function(){var D=document,e=D.getElementById(prompt("id for a SELECT element", "id")),opt=D.createElement("option"),val=prompt("value for a new OPTION element", "value");opt.appendChild(D.createTextNode(val));opt.value=val;e.appendChild(opt);})();

save input (new: 2015-05-01)

指定した pattern を name に持つ要素の入力状況を保存する。

2015-05-01

2019-10-16

javascript:(function(pattern){
  function clicktocopy(v) {
    var txt=document.body.appendChild(document.createElement("textarea"));
    Object.assign(txt.style, {width: "100%", height: "100%", position: "fixed", top: 0, left:0});
    txt.value=v;
    txt.addEventListener("click",e=>{
      txt.select();
      document.execCommand("copy");
      txt.parentNode.removeChild(txt);
    });
  }
  
  var e,i,v=[];
  e=document.querySelectorAll("INPUT,TEXTAREA");
  for(i=0;i<e.length;i++){
    if(e[i].name.match(pattern)){
      if(e[i].type.match(/checkbox|radio/)) {
        v.push(e[i].checked?"true":"");
      }else{
        v.push(e[i].value);
      }
    }
  }
  clicktocopy(JSON.stringify({[pattern]: v}));
})(prompt("pattern");

restore input (new: 2015-05-01)

save input で保存したデータをリストアする。

2015-05-01

2019-10-16

javascript:(function(s){
  var v,pat,vals,i;
  v=JSON.parse(s);
  for(pat in v){
    vals = v[pat];
    e=document.querySelectorAll("INPUT,TEXTAREA");
    for(i=0;i<e.length;i++){
      if(e[i].name.match(pat)){
        if(e[i].type.match(/checkbox|radio/)) {
          e[i].checked=vals.shift();
        }else{
          e[i].value=vals.shift();
        }
      }
    }  
  }
})(prompt("data"));

hack 支援

スクリプト実行用の編集エリアと出力エリアを追加します。
出力エリアには echo() 関数で出力が可能です。
javascript:(function(){var D=document,A="appendChild",E="createElement",f=D[E]("FORM"),s=D[E]("TEXTAREA"),r=D[E]("INPUT");s.style.width="100%";s.style.height="20ex";r.type="button";r.value="run";r.onclick=function(){function echo(s){c.value+=s+"\n";}eval(s.value);};var c=s.cloneNode(0),e=r.cloneNode(0);e.value="cls";e.onclick=function(){c.value=""};f[A](s);f[A](r);f[A](e);f[A](c);D.body[A](f);})();
オブジェクトのプロパティをテーブル表示します。
ダブルクリックで消えます。
javascript:(function(e){var D=document,A="appendChild",C="create",E=C+"Element",T=C+"TextNode",t=D.body[A](D[E]("TABLE")),K=[];t.border=1;t.ondblclick=function(){t.parentNode.removeChild(t);};for(var i in e){K.push(i);}K.sort();for(var i=0;i<K.length;i++){var k=K[i],r=t.insertRow(t.rows.length),h=r[A](D[E]("TH")),d=r[A](D[E]("TD")),s="";h.style.textAlign="left";h[A](D[T](k));try{s+=e[k];}catch(x){s+=x;}d[A](D[T](s));}})(eval(prompt("","document")));

閲覧支援

increment
javascript:(function(d){location.href=location.href.match(/([0-9]+)([^0-9]*)$/)&&(RegExp.leftContext+(Array(RegExp.$1.length).join("0")+(parseInt(RegExp.$1)+d)).slice(-RegExp.$1.length)+RegExp.$2)||location.href;})(1)
decrement
javascript:(function(d){location.href=location.href.match(/([0-9]+)([^0-9]*)$/)&&(RegExp.leftContext+(Array(RegExp.$1.length).join("0")+(parseInt(RegExp.$1)+d)).slice(-RegExp.$1.length)+RegExp.$2)||location.href;})(-1)
Internet Archive へ飛ばします。
javascript:(function(){location.href="http://web.archive.org/web/"+location.href;})();
自動 index や ftp 等のファイル一覧表示時に、長くて省略されたファイル名を全表示します。
javascript:(function(){var len = 0;var a=document.getElementsByTagName("A");for(var i = 0; i < a.length; i++){len = Math.max(len, a[i].getAttribute("href").length);};for(var i = a.length - 1; 0 <= i; --i){var href=a[i].getAttribute("href");a[i].textContent=href+Array(len-href.length+1).join(" ");}})();
2015-04-26: スペース調整改良版
javascript:(function(){var i,h,d,lh=0,lt=0,a=document.getElementsByTagName("A");for(i=0;i <a.length;i++){lh=Math.max(lh, a[i].getAttribute("href").length);lt=Math.max(lt, a[i].textContent.length);};for(i=a.length-1;0<=i;--i){h=a[i].getAttribute("href");a[i].parentNode.insertBefore(document.createTextNode(Array(lh-h.length-lt+a[i].textContent.length+1).join(" ")),a[i].nextSibling);a[i].textContent=h;}})();
2018-10-19: スペース調整の改良
javascript:(function(){var i,h,d,lh=0,lt=0,A="getAttribute",N="nextSibling",T="textContent",D=document,dec=decodeURIComponent,a=D.getElementsByTagName("A");Object.prototype.each=[].forEach;is=e=>dec(e[A]("href")).slice(0,4) == e[T].slice(0,4);a.each(e=>{if(is(e)){e[N][T]=e[N][T].replace(/^ */,"");e[T]=dec(e[A]("href"));lh=Math.max(lh,e.offsetWidth);}});a.each(e=>{if(is(e)){let s=D.createElement("SPAN");Object.assign(s.style,{display:"inline-block",width:lh-e.offsetWidth+16});e.parentNode.insertBefore(s,e[N]);}});})();
2020-05-24: スペース調整
javascript:(function(){
  let a = document.querySelectorAll("A");
  let maxw = 0;
 	[].forEach.call(a,e=>{
    if (e.getAttribute("href").match(/^\?/)) return;
    console.log(e.href)
    e.nextSibling.textContent = e.nextSibling.textContent.replace(/^ */, "");
    e.textContent = decodeURIComponent(e.getAttribute("href"));
    maxw = Math.max(maxw, e.offsetWidth);
  });
 	[].forEach.call(a,e=>{
    if (e.getAttribute("href").match(/^\?/)) return;
    Object.assign(e.style, {display:"inline-block", width: maxw + 16});
  });
  a = document.querySelector("A");
  Object.assign(a.style, {display:"inline-block", width: maxw + 16});
  a.nextSibling.textContent = a.nextSibling.textContent.replace(/^ */, "");
})();

Keepaliver (Scratch pad 用)

ログインがタイムアウトしないようにIFRAMEを用いて一定時間毎にリロードさせます。
(function(){
  function pad(x,w){
    return ((new Array(w+1)).join("0") + x).slice(-w);
  }
  function date2stamp(d){
    return ""+pad(d.getFullYear(),4)+pad(d.getMonth()+1,2)+pad(d.getDate(),2)+"_"+pad(d.getHours(),2)+pad(d.getMinutes(),2)+pad(d.getSeconds(),2);
  }
  function keepaliver() {
    var e = document.getElementById("keepaliver");
    if (e) e.parentNode.removeChild(e);
    e = document.createElement("IFRAME");
    e.id = "keepaliver";
    e.width = "160";
    e.height = "48";
    document.body.insertBefore(e, document.body.firstChild);
    e.onload = function() {
      var count = document.createTextNode(date2stamp(new Date()));
      e.contentDocument.body.insertBefore(count, e.contentDocument.body.firstChild);
      setTimeout(keepaliver, 30*1000);
    }
    e.contentWindow.location = location.href;
  }
  keepaliver();
})();
2020-09-19:
テーブルのヘッダを表示範囲内の上部に固定します。
例えば以下のページの表などが見易くなります。
[].forEach.call(document.querySelectorAll("table"),table=>{
  let header = table.querySelector("tr:first-of-type");
  header.style.position = "sticky";
  header.style.top = 0;
  console.log(header.height);
  [].forEach.call(table.querySelectorAll(`td[colspan='${header.cells.length}']`), td=>{
		let tr = td.closest("tr");
    tr.style.position = "sticky";
	  tr.style.top = header.offsetHeight+"px";
  });
});
javascript:(function(){[].forEach.call(document.querySelectorAll("table"),table=>{let header = table.querySelector("tr:first-of-type");header.style.position = "sticky";header.style.top = 0;[].forEach.call(table.querySelectorAll(`td[colspan='${header.cells.length}']`), td=>{let tr = td.closest("tr");tr.style.position = "sticky";tr.style.top = header.offsetHeight+"px";});});})();

メモ支援

id 属性が付いている要素への anchor を短剣符(†)で表示します。
javascript:(function(){var D=document,e=D.getElementsByTagName("*");for(var i=e.length-1;0<=i;i--){if(e[i].id){var sup=D.createElement("sup"),a=sup.appendChild(D.createElement("A"));a.href="#"+e[i].id;a.title=e[i].id;a.appendChild(D.createTextNode("†"));e[i].appendChild(sup);}}})();
id 属性が付いている要素、及び name 属性の付いている A 要素への anchor を短剣符(†)で表示します。
javascript:(function(){var D=document,e=D.getElementsByTagName("*"),a=function(l){var sup=D.createElement("sup"),a=sup.appendChild(D.createElement("A"));a.href="#"+l;a.title=l;a.appendChild(D.createTextNode("†"));return sup;};for(var i=e.length-1;0<=i;i--){if(e[i].id){e[i].appendChild(a(e[i].id));}else if(e[i].tagName=="A"&&e[i].name){e[i].appendChild(a(e[i].name));}}})();
リンクコピペ用のテキストを表示します。
何かキーを叩くと一発で消えるるので、CTRL+C を叩けばクリップボードへコピーして消えてくれます。
KDE で使う場合、Klipper の設定で「クリップボードと選択の内容を同期する」を選んでおくとCTRL+Cでマウスの中央ボタンの張り付けが同期するようです。
javascript:(function(){var d=document,t=d.getElementsByTagName("TITLE")[0].innerHTML,l=location.href,a=d.createElement("TEXTAREA");a.value=t+"\n"+l+"\n\x5b\x5b"+t+"\x3e"+l+"\x5d\x5d\n";a.style.width="100%";a.style.height="5em";a.style.position="absolute";a.style.left=(d.body.scrollLeft||d.documentElement.scrollLeft)+"px";a.style.top=(d.body.scrollTop||d.documentElement.scrollTop)+"px";a.onkeyup=function(){this.parentNode.removeChild(this);};d.body.appendChild(a);a.focus();a.select();})();
javascript:(function(){var d=document,b=d.body,w=window.open(),wd=w.document; wd.write('<html><head></head><body></body></html>'); e=wd.createElement("DIV"); e.appendChild(wd.createTextNode(d.getElementsByTagName("HTML")[0].innerHTML)); wd.body.appendChild(e);})();
javascript:(function(){var d=document,b=d.body,w=window.open(),wd=w.document, t=b.innerText?"innerText":"textContent"; wd.write('<html><head></head><body></body></html>'); e=wd.createElement("DIV"); e.appendChild(wd.createTextNode(d.getElementsByTagName("HTML")[0][t])); wd.body.appendChild(e);})();

操作性向上

javascript:(function(){if(location.href.match(/^(.*:\/\/.*\/).+$/))location.href=RegExp.$1;})();
PDF, docx?, xlsx?, pptx? を Google Document Viewer にリンクさせる
javascript:(function(){var%20e=document.getElementsByTagName("A");for(var%20i=0;i<e.length;i++)if(e[i].href.match(/(pdf|docx?|xlsx?|pptx?)$/))e[i].href="http://docs.google.com/viewer?url="+escape(e[i].href);})();
描画領域のサイズを数値指定して変更します。
Screen shot の取得時等に画像サイズの統一のために使うと良いと思います。
javascript:(function(){var w=prompt("innerWidth");if(w)window.innerWidth=w;})();
最近は、JavaScript からリサイズし難い状況なので
手動調整用として
描画領域のサイズを表示。
2022-04-11:
  • fixed に変更
  • click で削除
javascript: (function() {let div = document.createElement('DIV'),callback = e => {div.textContent = "" + document.body.scrollWidth + 'x' + document.body.scrollHeight + " : " + window.innerWidth + "x" + window.innerHeight;}; callback(); window.addEventListener('resize', callback); Object.assign(div.style, {width: '12em', height: '1.5em', background: 'white', border: '1px solid black', position: 'fixed', left: 0, top: 0, zIndex: Number.MAX_SAFE_INTEGER});document.body.appendChild(div); div.addEventListener("click", e=>e.srcElement.parentNode.removeChild(e.srcElement))})();

log

スマホ連携

javascript:(function(){location.href="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl="+location.href;})();
2017-11-14:
javascript:(function(){location.href="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl="+encodeURIComponent(location.href);})();
参考:

翻訳支援

2023-07-14:
javascript:(function(){
  const [,host,path] = location.href.match(/https?:\/\/([^/]*)\/?(.*)/);
  const param = "?_x_tr_sl=auto&_x_tr_tl=ja&_x_tr_hl=ja&_x_tr_pto=wapp";
  const url = `https://${host.replace(".","-")}.translate.goog/${path}${param}`;
  location.href=url;
})();

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます