10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

お題「見ているサイトのソースを別タブで表示する」をできるだけ短いJSスクリプトで書く

Last updated at Posted at 2014-12-03
javascript:
(function() {
  var key = "$$$KEY$$$";
  var html = document.documentElement.outerHTML;
  sessionStorage.setItem(key, html);
  var source = "javascript:" +
    "(function() {" +
    "  var html = sessionStorage.getItem('" + key + "');" +
    "  var node = document.createTextNode(html);" +
    "  document.body.appendChild(node);" +
    "})();";
  open(source);
})();

改行とスペース イラネ

javascript:(function(){var key="$$$KEY$$$";var html=document.documentElement.outerHTML;sessionStorage.setItem(key,html);var source="javascript:(function(){var html=sessionStorage.getItem('"+key+"');var node=document.createTextNode(html);document.body.appendChild(node);})();";open(source);})();

var イラネ

javascript:(function(){key="$$$KEY$$$";html=document.documentElement.outerHTML;sessionStorage.setItem(key,html);source="javascript:(function(){html=sessionStorage.getItem('"+key+"');node=document.createTextNode(html);document.body.appendChild(node);})();";open(source);})();

変数名は1文字

javascript:(function(){k="$$$KEY$$$";h=document.documentElement.outerHTML;sessionStorage.setItem(k,h);s="javascript:(function(){h=sessionStorage.getItem('"+k+"');n=document.createTextNode(h);document.body.appendChild(n);})();";open(s);})();

変数イラネ

javascript:(function(){sessionStorage.setItem('$$$KEY$$$',document.documentElement.outerHTML);open("javascript:(function(){document.body.appendChild(document.createTextNode(sessionStorage.getItem('$$$KEY$$$')));})();");})();

セミコロン イラネ

javascript:(function(){sessionStorage.setItem('$$$KEY$$$',document.documentElement.outerHTML);open("javascript:(function(){document.body.appendChild(document.createTextNode(sessionStorage.getItem('$$$KEY$$$')))})()")})()

function() イラネ

javascript:sessionStorage.setItem('$$$KEY$$$',document.documentElement.outerHTML);open("javascript:document.body.appendChild(document.createTextNode(sessionStorage.getItem('$$$KEY$$$')))")

sessionStorage に入れる key は 1 文字

javascript:sessionStorage.setItem('_',document.documentElement.outerHTML);open("javascript:document.body.appendChild(document.createTextNode(sessionStorage.getItem('_')))")

key イラネ

javascript:sessionStorage.setItem('',document.documentElement.outerHTML);open("javascript:document.body.appendChild(document.createTextNode(sessionStorage.getItem('')))")

170 文字。

【追記】sessionStorage イラネ

open って開いた window のオブジェクトを返すのな。

javascript:open("javascript:setTimeout('document.body.appendChild(document.createTextNode(s))')").s=document.documentElement.outerHTML

134文字。

10
10
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?