一行代码,浏览器变临时编辑器
来源:互联网 发布:geo数据库 编辑:程序博客网 时间:2024/05/01 07:38
这是 Jose 在CoderWall 分享的一个小技巧:在浏览器地址栏中输入一行代码:data:text/html, <html contenteditable> ,回车即可把浏览器变临时编辑器。
为什么它能奏效?
这是用了数据URI的格式(Data URI’s format),并告诉浏览器渲染 HTML。不过 contenteditable 是 HTML5 的一个新全局属性,所以这个小技巧只能用于支持该属性的现代浏览器。(IE 8 – 就不行了 )
并非只能纯文字,也可粘贴图片(如下图)。赶紧复制粘贴那行代码,然后回车,来试试呗。
有趣的内容还在下面
不少程序员受 Jose 的启发,开始对这行代码加工改造了。
● jakeonrails 童鞋改成了一个支持 Ruby 代码高亮的编辑器 https://gist.github.com/4666256
代码:
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 更新)
改造成支持其他语言语法高亮的,可把 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.
data:text/html, <
textarea
style
=
"font-size: 1.5em; width: 100%; height: 100%; border: none; outline: none"
autofocus />
或直接戳 链接。
● bgrins 的改造:编辑内容时,自动变换背景颜色;停止后变换白色。
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 的改造:
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/
- 一行代码,浏览器变临时编辑器
- 一行代码,浏览器变临时编辑器
- 一行代码,浏览器变临时编辑器
- 一行代码,浏览器变临时编辑器
- 一行代码,浏览器变临时编辑器
- 一行代码,浏览器变临时编辑器
- 一行代码,浏览器变临时编辑器
- 一行代码,浏览器变临时编辑器
- 一行代码让浏览器变编辑器
- 11.16 快速计算出某数字的+1或^2的总次数,一行代码浏览器变编码编辑器
- 怎样让浏览器变身代码编辑器?
- 怎样让浏览器变身代码编辑器?
- 浏览器变编辑器
- 仅在地址栏输入简单代码,浏览器变编辑器
- 一点奇淫技巧-让浏览器变代码编辑器
- 临时代码编辑器
- 浏览器变编辑器小技巧
- 浏览器秒秒钟变编辑器
- MYSQL 主从数据库同步
- E-R图--我的错误认知
- careercup1.2: reverse a C-Style String.
- SQL批量添加数据库中所有用户数据表描述
- Eclipse小项目放到OA系统的实施
- 一行代码,浏览器变临时编辑器
- I2C总线原理及应用实例
- 统计某元素或者某行(列)出现的次数
- 获取identity的几种方法
- Eclipse复制项目发布到服务器Tmocat上的问题
- findbugs 错误分析
- 架构师给程序员的一封信
- 软件随想录(local.joelonsoftware.com/wiki)-2000年05月12日 策略书之一: Ben and Jerry模式与Amazon模式 - Strategy Letter I
- 淡谈Yahoo关于性能优化的N条军规