一行代码,浏览器变临时编辑器


这是 Jose 在CoderWall 分享的一个小技巧:在浏览器地址栏中输入下面这行代码,回车即可把浏览器变临时编辑器。

1
data:text/html, < html contenteditable>

为什么它能奏效?

这是用了数据URI的格式(Data URI’s format),并告诉浏览器渲染 HTML。不过 contenteditable 是 HTML5 的一个新全局属性,所以这个小技巧只能用于支持该属性的现代浏览器。(IE 8 – 就不行了 :( )

test in IE 8

 

并非只能纯文字,也可粘贴图片(如下图)。赶紧复制粘贴那行代码,然后回车,来试试呗。

test in Comodo

有趣的内容还在下面

不少程序员受 Jose 的启发,开始对这行代码加工改造了。

● jakeonrails 童鞋改成了一个支持 Ruby 代码高亮的编辑器  https://gist.github.com/4666256

test in Chrome 24

代码:

1
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>

● slawdan 提示说:如果把上面的 ace/mode/ruby 改成 ace/mode/python,那么就得到了一个 Python 版的编辑器咯。其他语言依此类推。

● jdkanani 后来的补充:(2013-1-30 22:06:48 更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
改造成支持其他语言语法高亮的,可把 ace/mode/ruby 替换为:
 
Python -> ace/mode/python
C/C++ -> ace/mode/c_cpp
Javscript -> ace/mode/javascript
Java -> ace/mode/java
Scala -> ace/mode/scala
Markdown -> ace/mode/markdown
CoffeeScript -> ace/mode/coffee
其他……
 
jakeonrails 语法高亮风格用的是 monokai。
如果需要换成其他风格,,可把 ace/theme/monokai 替换为:
 
Eclipse -> ace/theme/eclipse
TextMate -> ace/theme/textmate
其他……

不想复制粘贴代码的懒汉童鞋,可以直接戳下面这些链接

Ruby 编辑器 、Python 编辑器PHP 编辑器 、Javascript 编辑器 、Java 编辑器 、C/C++ 编辑器 (也可把这些链接作为浏览器书签收藏哦。)

 

● montas 的改造:You can use textarea and make it “invisible” if you want autofocus.

1
data:text/html, < textarea style = "font-size: 1.5em; width: 100%; height: 100%; border: none; outline: none" autofocus />

或直接戳 链接

 

● bgrins 的改造:编辑内容时,自动变换背景颜色;停止后变换白色。

1
data:text/html, < html >< head >< link href = 'http://fonts.googleapis.com/css?family=Open+Sans' rel = 'stylesheet' type = 'text/css' >< style type = "text/css" > html { font-family: "Open Sans" } * { -webkit-transition: all linear 1s; }</ style >< script >window.onload=function(){var e=false;var t=0;setInterval(function(){if(!e){t=Math.round(Math.max(0,t-Math.max(t/3,1)))}var n=(255-t*2).toString(16);document.body.style.backgroundColor="#ff"+n+""+n},1e3);var n=null;document.onkeydown=function(){t=Math.min(128,t+2);e=true;clearTimeout(n);n=setTimeout(function(){e=false},1500)}}</ script ></ head >< body contenteditable style = "font-size:2rem;line-height:1.4;max-width:60rem;margin:0 auto;padding:4rem;" >

 

● fvsch 的改造:

1
data:text/html, < body contenteditable style = "font-size:2rem;line-height:1.4;max-width:60rem;margin:0 auto;padding:4rem;" >

或直接戳 链接

 

这些个奇淫技巧就到此为止吧。

 

编译整理:伯乐在线 - 黄利民

文章链接:http://blog.jobbole.com/32823/

 【如需转载,请在正文中标注并保留原文链接、译文链接和译者等信息,谢谢合作!】

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值