Skip to content

Instantly share code, notes, and snippets.

@oa414
Created December 4, 2012 05:56
Show Gist options
  • Select an option

  • Save oa414/4201117 to your computer and use it in GitHub Desktop.

Select an option

Save oa414/4201117 to your computer and use it in GitHub Desktop.
把AndroidSDK的文档里面一句JavaScript注释掉,提高打开的速度
#===================================================================
# FileName: changeSDKJS.rb
# Author: Lin Xiangyu
# Email: [email protected]
# WebSite: http://linxiangyu.info
# CreateTime: 2012.12.04
#===================================================================
# Android SDK里面有自带的文档,但是在大陆打开很慢,原因是会去加载一个jsapi,然后被墙
# <script src="http://www.google.com/jsapi" type="text/javascript"></script>
# 把SDK里面的HTML文档里面这句话注释掉就行了
# 我是从http://www.douban.com/note/250736841/ 和 http://my.oschina.net/willedward/blog/91260 发现的原因,他们用Java写了一份
# 我写了一个Ruby版本的,在我的Mac OS X10.8 + Ruby 1.9.3下能正常运行
# when you open the document of Android SDK docs, it will require a JavaScript: <script src="http://www.google.com/jsapi" type="text/javascript"></script>
# This script can help you comment this statement of SDK document and improve the speed of openning the docs
# Usage: ruby scriptname SDKpath
# Example: ruby changeSDKJS.rb ~/program/android-sdk-macosx/
require 'find'
$jsline = %Q|<script src="http://www.google.com/jsapi" type="text/javascript"></script>|
$jscomment = "<!--" + $jsline + "-->"
def process(path)
puts "Processing #{path}"
newfile = File.new(path + 'tmp', 'w')
File.open(path) do |oldfile|
while line = oldfile.gets
if line.include? $jsline
puts "FIND"
newfile.puts $jscomment
else
newfile.puts line
end
end
end
File.delete(path)
File.rename(path + 'tmp', path)
end
Find.find(ARGV[0]) do |path|
if path =~ /(.)+\.html$/
process(path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment