月度归档:2013年08月

浏览器中实现阅读模式

这里对阅读模式的定义是:去除网页上与主题内容无关的图片、导航、广告等等,给用户提供一个清爽的网页。在PC浏览器中,chrome/firefox都有这样的扩展/插件。我个人用的最多的是chrome上的印象笔记.悦读插件,和evernote整合,非常好用。从IOS 6开始,safari浏览器也提供了阅读器功能,用户界面如下:

safari_readmode_1 safari_readmode_2

当网页中主题内容比较明确、且文字内容较多时,地址栏上就会出现“阅读器”按钮,点击“阅读器”按钮,就会提供给用户一个清爽的网页。更绝的是,如果网页内容包含多个分页,“阅读器”模式下还可以自动整合,无需费力的点击下一页了,相当贴心,如下图所示:

safari_readmode_3

如果要在浏览器中实现这一个功能,可以有三种方法:

1、服务器端对网页进行处理

其思路和百度转码相同,就是在服务器端对网页进行处理,UC浏览器能够做到省流量,也是采用了这一技术。不过百度转码主要目的是为网页瘦身,所以处理出来的效果惨不忍睹。国外有一家公司,提供了免费的readability API,其口号是:

Transforms any article … into a calm, humane, readable experience

详情请访问http://www.readability.com。

使用国外免费的API,实现简单,无需架设服务器,但缺点也是明显的,速度不够理想,容易被墙,说不定哪天就不能使用了。

2、修改webkit,对DOM树进行处理

webkit中,有一个步骤就是解析html,形成DOM树,有了这个DOM树就好办了,有什么节点、节点属性、节点样式都一目了然。所以接下来要做的事情就是筛选主题内容,过滤无关紧要的节点。至于采用什么算法进行筛选,还没有找到现成的C++库,网上有一个C#库:NReadability 可供参考,如果对javascript比较熟的话,直接参考readability提供的js脚本也可以。

通过修改webkit实现阅读模式,速度快,更容易和浏览器界面进行整合(比如,safari中,只有文字较多的网页才会出现阅读器),也比较适合对js前端开发不熟悉的C++程序员,缺点是webkit比较复杂,需要对webkit了解深入,而且之后的维护也是个麻烦事情。

3、注入js,对DOM树进行处理

javascript具有操作DOM的能力,也可以应用样式表来修改节点的样式,所以通过注入JS脚本来实现阅读模式是一个不错的选择。chrome/firefox中扩展插件,或者一种称为bookmarklet的小片代码就是这样实现的。

回到chromium for android,ContentView提供了evaluateJavaScript方法为当前ContentView注入javascript,所以实现起来非常容易。

TODO

在safari中,实现了多页拼接的处理。Readability在一篇文章中也声明实现了多页合并的处理,不过我对javascript研究的不够多,还没有弄清是如何实现的。如果有精通web前端开发的同学一起探讨,非常欢迎。

chrome for android历史发布版本大集合

chrome for android的发布也进入了快通道,基本上windows/linux/android几个平台会同时发布新版本。不过google play上的app没法找到历史版本,有时为了测试对比,到处找一个历史版本。为此,本文整理了所有chrome for android的正式release版本的发布说明,历史版本可以从这里下载。

v28.0.1500.94

FRIDAY, JULY 19, 2013

Chrome for Android has been updated to 28.0.1500.94. This version contains minor bug fixes. A partial list of changes in this build is available in the SVN log. Interested in switching release channels?Find out how. If you find a new issue, please let us know by filing a bug.


v28.0.1500.64

WEDNESDAY, JULY 10, 2013

The Chrome team is excited to announce the promotion of Chrome 28 to the Stable channel. Chrome for Android 28.0.1500.64 contains a number of new features including:

  • Google Translate - When reading web pages in other languages, Chrome will automatically detect and offer to translate them to your language
  • Fullscreen on tablets - Similar to phones, simply scroll down the page and the toolbar will disappear.
  • New user interface for right-to-left (RTL) languages - An optimized interface for RTL languages including Arabic, Farsi, and Hebrew
  • Plenty of stability and performance fixes

A partial list of changes in this build is available in the SVN revision log. If you find a new issue, please let us know by filing a bug. More information about Chrome for Android is available on the Chrome site.

v27.0.1453.90

The Chrome team is excited to announce the promotion of Chrome 27 to the Stable channel. Chrome for Android 27.0.1453.90 contains a number of improvments including:

  • Fullscreen on phones - Scroll down the page and the toolbar will disappear.
  • Simpler searching - Searching from the omnibox will keep your search query visible in the omnibox, making it easier to edit, and show more on your search result page.
  • Client-side certificate support - You can now access sites that require you to use a certificate and Chrome will allow you to select an installed certificate
  • Tab history on tablets - Long press the browser back button to view your tab history
  • And a ton of stability and performance fixes

A partial list of changes in this build is available in the SVN revision log. If you find a new issue, please let us know by filing a bug. More information about Chrome for Android is available on the Chrome site.

v26.0.1410.58

WEDNESDAY, APRIL 3, 2013

The Chrome team is excited to announce the promotion of Chrome 26 to the Stable channel for Android. This update will be rolling out to Google Play over the next few hours.  Chrome for Android 26.0.1410.58 contains a number of updates including:

  • Password Sync
  • Autofill Sync
  • Fixed issue where blank page would be loaded rather than URL
  • Performance and stability improvements

You can find out more about the release on the Chrome blog.  If you find a new issue, please let us know by filing a bug.

v25.0.1364.169

FRIDAY, MARCH 8, 2013

Chrome for Android Stable Channel has been updated to 25.0.1364.169. This version is currently rolling out to Google Play over the next few hours.

This update improves font clarity and includes other stability fixes. Known issues are available on theChrome support site.

Interested in other release channels of Chrome for Android? A Beta channel is now available and can be run side by side with Stable. If you find a new issue, please let us know by filing a bug. More information on Chrome for Android is available on the Chrome site.

v25.0.1364.123

WEDNESDAY, FEBRUARY 27, 2013

The Chrome team is excited to announce the promotion of Chrome 25 to the Stable Channel for Android. Chrome 25.0.1364.123 is currently rolling out to Google Play over the next few hours. This update contains a huge number of changes over the previous release, including:

  • Improved scrolling performance
  • Increased responsiveness to pinch-zooming on pages
  • Faster interactive pages thanks to the latest version of the V8 javascript engine
  • Audio now continues to play while Chrome is in the background
  • Expanded support for HTML5 features
  • Support for pausing audio in Chrome when phone is in use (note: this requires an additional permission)

This update also picks up other important stability and performance fixes since the last release, along with some minor UI adjustments. Known issues are available on the Chrome support site.

Interested in other release channels of Chrome for Android? A Beta channel is now available and can be run side by side with Stable. If you find a new issue, please let us know by filing a bug. More information on Chrome for Android is available on the Chrome site.

SublimeText配置

在我的一台开发机上在ubuntu系统下使用eclipse,经常会出现死机,不得不寻求其它的代码编辑器。windows下大名鼎鼎的source insight放到linux下就状况不断。后看到chromium项目推荐了sublime text这款编辑器,用起来感觉还不错。下面记录一下使用过程中的一些设置,网上各种资料比较凌乱,所以就稍微整理一下,供自己今后翻阅。

1. 过滤不相关的文件

可以针对某个特定的工程,进入菜单project | Edit Project,编辑当前工程的sublime-project文件,加入两个过滤器,folder_exclude_patternsfile_exclude_patterns,如下所示:

"folders":
[
    {
        "path":"/home/alex/android/source/android4.2",
        "file_exclude_patterns":
        [
            "*.o"
        ],
        "folder_exclude_patterns":
        [
            ".repo"
        ]
    }
]

2. 模拟eclipse的快捷键

在eclipse中,有几个快捷键用的非常多,分别为:

CTRL+TAB 头文件和c/c++文件之间切换
CTRL+SHIFT+R 对话框中输入文件名(有联想功能),快速打开文件
CTRL+o 输入方法(函数)名,可快速定位到方法(函数)
CTRL+l 输入行号,快速定位到指定行
CTRL+h 打开文件搜索对话框


可以修改sublime text的Key Bindings达到模拟eclipse快捷键的效果,有两个配置项可以修改,一个是Key Bindings-Default,一个是Key Bindings-User,最好修改后一个配置文件。进入菜单Preferences | Key Bindings - User,加入如下行:

[
{ "keys": ["ctrl+shift+r"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },
{ "keys": ["ctrl+o"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} },
{ "keys": ["ctrl+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
{ "keys": ["ctrl+t"], "command": "show_overlay", "args": {"overlay": "goto", "text": "#"} },
{ "keys": ["ctrl+tab"], "command": "switch_file", "args": {"extensions": ["cpp", "cxx", "cc", "c", "hpp", "hxx", "h", "ipp", "inl", "m", "mm"]} }
]

3. 针对项目的代码风格设置

chromium的项目的代码缩进为两个空格,而其它项目的代码缩进一般为4个空格,所以我就希望针对特定的项目进行代码风格设置,方法是编辑当前工程的sublime-project文件,加入如下行(和folders项平级):

"settings":
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"draw_white_space": "all"
}

4. 插件集合

sublime_text的插件扩展机制非常强大,已经有很多人出于不同的需求,开发出各种插件。首先说一下插件的安装。

按ctrl+shit+p显示命令列表,在其中输入install,选择Package Control: Install package,接着就会出现插件列表,选择你所需要的插件即可。