Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Chrome Extension
Search
周祺
February 28, 2011
Programming
390
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Chrome Extension
Chrome插件开发
周祺
February 28, 2011
More Decks by 周祺
See All by 周祺
Mobile Web的性能优化与测试
zhouqicf
7
360
Web App
zhouqicf
1
200
Web App开发
zhouqicf
4
290
f2e @ 2012
zhouqicf
6
190
Photoshop影像修饰艺术
zhouqicf
4
390
前端和视觉间的故事
zhouqicf
1
170
CSS模块化
zhouqicf
2
240
Other Decks in Programming
See All in Programming
yield再入門 #phpcon
o0h
PRO
0
710
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
840
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
160
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
270
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
130
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
640
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
2.9k
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
150
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
190
継続モナドとリアクティブプログラミング
yukikurage
3
630
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
350
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.4k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
510
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
420
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
160
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
430
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
470
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
640
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Transcript
Chr me Extension 口碑F2E-由校 2011-02-28
f2e !== Future.f2e HTML + CSS + JAVASCRIPT http://www.adobe.com/cn/devnet/air/ajax/
f2e !== Future.f2e
“你很幸运,因为Chrome插件开发是如此简单,你不需要明白什么是 ActiveX,不需要知道什么叫COM,嗯,让他们一边凉快去吧,这里只有 HTML & Javascript,这里是互联网的世界!” 前端是多么幸运,因为Chrome插件开发对于我们来说是如此简单,这里 只有HTML & CSS &
Javascript,这里是我们的世界! -- via youxiao 互联网前端的世界
Enjoy ! CSS3 ! HTML5 ! audio
! application cache ! canvas ! geolocation ! local storage ! Notifications ! session storage ! video ! web database ! Jquery、YUI、ExtJs……
Chrome APIs ! Bookmarks ! ContextMenus ! I18n ! Omnibox
! History ! A8 ! …
Files
The manifest file { "name" : "Code Cola", //插件名称(i18n 下使用
”__MSG_key__”) "version" : "1.2.2", //插件版本(发布插件时读取该版本号,必须唯一) "default_locale“ : "en", //默认语言 "description" : "Gets information from Google.", //插件描述 //图标 "icons" : { "128": "128.png", "48": "48.png", "32": "32.png", "24": "24.png" }, "background_page": "bg.html", // background_page "options_page": "options.html", //配置⻚页 //插件权限(更改设置时,谷歌会对用户进行提醒) "permissions": ["tabs", "*://*/*"], //工具栏上的按钮图标 "browser_action": { "default_title": "code cola", "default_icon": "codecola.png", "default_popup": "popup.html" //popup⻚页面 } }
Extension UIs Background.html Content scripts Popup.html Execute Js
Background.html Manifest.json : { “background_page”: “bg.html” } //显示有几封新邮件 chrome.browserAction.setBadgeText(object details)
//默认为蓝色的icon,有新邮件时,更改成红色的icon chrome.browserAction.setIcon(object details) //mouseover时显示“有n封新邮件”的title chrome.browserAction.setTitle(object details)
Content scripts Manifest.json : { "content_scripts": [ { "matches": ["*://*/*"],
"css": ["codecola.css"], "js": ["codecola.js"] } ] }
Browser Actions – Popup Manifest.json : { "browser_action": [ {
"default_icon": ["codecola.png"], "default_title": ["codecola"], "default_popup": ["popup.html"] } ] }
Browser Actions – execute JS Background.html: //code chrome.browserAction.onClicked.addListener(function(tab){ chrome.tabs.executeScript(tab.id,{ code:"document.body.bgColor='red'
" }); }); //file chrome.browserAction.onClicked.addListener(function(tab) { chrome.tabs.executeScript(tab.id, {file: "codecola.js"}, function(){ chrome.tabs.insertCSS(id, { file: "codecola.css " }); }); });
Communication
Communication //listener ( background.html ) chrome.extension.onRequest.addListener(function(request, sender, sendResponse){ sendResponse({ "action":
localStorage["codecola_getLink_action"] }); }); // requester ( content Js ) chrome.extension.sendRequest("getUrls", function(response) { console.log(response.action); }); Ps: 在background.html里无法直接操作⻚页面的dom
Communication p 用“Content scripts”来操作DOM p “Content scripts”和“background.html”通过 “chrome.extension”,以事件的方式来进行交互
Options manifest.json: { "options_page": "options.html" } option.html: localStorage["codecola_getLink_action"] = action;
Internationalization (i18n) manifest.json: { "name": "__MSG_messagename__" } Content js: chrome.i18n.getMessage("messagename")
messages.json: { "name": { "message" : "code cola", "description": "xxx" } } http://code.google.com/chrome/extensions/i18n.html
Debug
Learn
Pack “.pem”文件即是该插件的“私有密钥”,第一次打包时生成该密钥
Install
Publish https://chrome.google.com/webstore/developer/update
Have a Try – Apps https://dl-web.dropbox.com/get/dev/Chrome/apps.crx?w=4ea0e4eb
Have a Try – Apps
Have a Try – switch work space 点击浏览器 工具栏图标 获取当前
Tab的ID 改变当前 Tab的Url https://dl-web.dropbox.com/get/dev/Chrome/switch%20work%20space.crx?w=544cade7&dl=1
Try – switch work space https://dl-web.dropbox.com/get/dev/Chrome/switch%20work%20space.crx?w=544cade7
Try – switch work space view-source:https://dl-web.dropbox.com/get/dev/Chrome/switch%20work%20space/background.html?w=8c8998f6
Have a Try – switch work space If KXT? update_rpc.php
Excute Js Code Update Url
Resource http://code.google.com/chrome/extensions/getstarted.html http://code.google.com/intl/zh-CN/chrome/webstore/docs/index.html
Q&A
Thanks.