Contents
2. 프로그램 목ì � ¶
- í�¬ë¡¬ì�€ 아시다시피 Plug-inì�„ ì„¤ì¹˜í• ìˆ˜ 있다 extension programì�´ë�¼ê³ ë�„ 하는것 ê°™ì�€ë�° ë� 쉽게 만들수 있는것 같다. 논문ì�„ 살펴보는ë�° ì‚¬ì „ê¸°ëŠ¥ì�„ 쓰기위해 마우스를 ì˜¬ë ¸ì§€ë§Œ 실행ì�´ ë�˜ì§€ 않았다.. 화난다=ã…‚= 그래서 ì‚´ì§� 살펴보니 .json확장ìž�ë�„ ë³´ì�´ëŠ”ê²ƒ 같지만 문법ë�„ ê°„ë‹¨í•˜ê³ CSS와 HTML. DOM형ì‹�ì�˜ 문서구조ë�„ íŒŒì•…í•˜ê³ ìžˆìœ¼ë‹ˆ ì–´ë µì§€ 않ì�„것 같았다. 그래서 간단히 네ì�´ë²„ ë§�í�¬ë¥¼ ê¸�어와 HTML elementë¶„ì„�ì�„ 통해 Naverì‚¬ì „ì�„ 하는 Plug-inì�„ 만들어볼까 한다.
4.1. ê¼ ë´�야하는 ì¤‘ìš”í•˜ë‹¤ê³ ìƒ�ê°�하는 것 ¶
- Chrome extention overview
- Overview
- Tutorial (getstarted) with fileset(manifest.json,.js,.html)
- manifest.json� attribute.
- Contents policy security. 확장기능 작성하는ë�° ê¼ ì•Œì•„ì•¼í•˜ëŠ” 작성법
- Overview
4.2.1. 기본기 ¶
í�¬ë¡¬ì�˜ 개발ìž� API주소는 지금 사ì�´íЏ ì�´ì „ì�„ í•˜ê³ ìžˆëŠ”ë�° 맨앞ì—� codeê°€ developer로 ì�´ì „하는것 같았다. 여튼 indexì�˜ 주소는 다ì�Œê³¼ 같다.
Tutorial� 진행하면 다�과 같다.
그런� �거 확장� 어떻게 실행시켜보�면
Chrome브ë�¼ìš°ì €ì—�서 í™˜ê²½ì„¤ì •(우측ìƒ�단ì—� ë Œì¹˜ëª¨ì–‘) -> ë�„구 -> 확장프로그램 -> 우측ìƒ�단 개발ìž� 모드 Check -> ì••ì¶•í•´ì œë�œ 확장프로그램 로드 를 하면 ë‚´ 컴퓨터ì—� 있는 플러그ì�¸ í�´ë�” 째로 올릴수 있다.
4.2.2. íŠœí† ë¦¬ì–¼ ë”°ë�¼í•´ë³´ê¸° ¶
flickrì—�서 permissionì�„ 받아 사진ì�„ ê¸�어오는 플러그ì�¸ì�„ 만드는것 같다. 파ì�¼êµ¬ì„±ì�€ HTML안ì—� 스타ì�¼ì�„ ì �용하는 CSS. AJAX, Javascript를 ì�´ìš©í•˜ì—¬ (AJAXì�˜ ì •ì�˜ë¥¼ ì•Œì•„ë³´ì•„ì•¼ê² ë‹¤ ) ë‚´ìš©ì�„ 구성한다. jsonì�„ 통해 ë˜ í•˜ëŠ”ê±´ê°€. í�¥ë¯¸ë¡êµ°.
Wikipedia JSON : http://ko.wikipedia.org/wiki/JSON
ì˜�어로 보는게 ë�” ìž�세하지만 난 한êµì�¸ì�´ë�¼. 간단히 ë§�하ìž�ë©´ ì�¸í„°ë„·ì—�서 ìž�료를 ì£¼ê³ ë°›ì�„때 ê·¸ ìž�료형ì‹�ì�„ ì •ì�˜í•˜ëŠ” 문서ì�¸ë�° javascript구문ì�„ 사용하는 파ì�¼ì�´ë‹¤. xml보다 webì—�서 효과ì �ì�´ê¸° 때문ì—� webìƒ�ì—�서 ì“°ì�¸ë‹¤ê³ 한다. 좋ì�€ê±° 배우네.
Wikipedia Ajax : http://ko.wikipedia.org/wiki/Ajax
Ajax는 비ë�™ê¸°ì‹�으로 ë�°ì�´í„°ë¥¼ ì£¼ê³ ë°›ê¸° 위해 (A는 Asyncronous) HTMLê³¼ CSS ë�™ì � ì •ë³´ 표시를 위한 ë�™ì � 언어와 DOM문서형 구조를 가진 XML, jsonë§Œì�´ Ajax를 뜻하는 것ì�´ 아니ë�¼ ì�´ëŸ° 조합으로 ì�´ë£¨ì–´ì§„ 비ë�™ê¸° 웹 어플리케ì�´ì…˜ 기법ì�„ 뜻한다.
ë� 여기까지 ìš©ì–´ì •ë¦¬ ë�¬ë‚˜.
ìž� ì�´ì œ ë”°ë�¼í•´ë³´ìž�.
- ë”°ë�¼í•˜ë‹¤ê°€ 실수한ì � : manifest.json파ì�¼ì�„ menifest.jsonì�´ë�¼ 해서 updateê°€ 안ë�¨. jsonì •ì�˜í• 때 다ì�Œ element를 위해 , 를 붙여야하는ë�° 안붙여서 ì—�러. ê·¸ë ‡ì§€ë§Œ 나머지는 복붙해서 잘 ê°€ì ¸ì˜´.
4.2.2.1. 첫번째 작성 ì˜ˆì œ ¶
- popup.js
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var req = new XMLHttpRequest();
req.open(
"GET",
"http://api.flickr.com/services/rest/?" +
"method=flickr.photos.search&" +
"api_key=90485e931f687a9b9c2a66bf58a3861a&" +
"text=hello%20world&" +
"safe_search=1&" + // 1 is "safe"
"content_type=1&" + // 1 is "photos only"
"sort=relevance&" + // another good one is "interestingness-desc"
"per_page=20",
true);
req.onload = showPhotos;
req.send(null);
function showPhotos() {
var photos = req.responseXML.getElementsByTagName("photo");
for (var i = 0, photo; photo = photos[i]; i++) {
var img = document.createElement("image");
img.src = constructImageURL(photo);
document.body.appendChild(img);
}
}
// See: http://www.flickr.com/services/api/misc.urls.html
function constructImageURL(photo) {
return "http://farm" + photo.getAttribute("farm") +
".static.flickr.com/" + photo.getAttribute("server") +
"/" + photo.getAttribute("id") +
"_" + photo.getAttribute("secret") +
"_s.jpg";
}
- popup.html
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
min-width:357px;
overflow-x:hidden;
}
img {
margin:5px;
border:2px solid black;
vertical-align:middle;
width:75px;
height:75px;
}
</style>
<!-- JavaScript and HTML must be in separate files for security. -->
<script src="popup.js"></script>
</head>
<body>
</body>
</html>
- manifest.json
{
"name": "My First Extension",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"http://api.flickr.com/"
]
}
4.2.3. ë‚´ê°€ ì›�하는것 ¶
- 마우스를 ì˜¬ë¦¬ê³ ëª‡ì´ˆê°€ 지나면 Text를 ì�½ì–´ì„œ ìž‘ì�€ íŒ�ì—…ì°½ì�„ ë�„움 - 3순위
- í…�스트를 ë�”블í�´ë¦í•˜ë©´ íŒ�ì—…ì�´ ìž�ë�™ì—´ë¦¬ë©´ì„œ ì‚¬ì „ì�„ ë�„워줌 - 1순위
4.2.3.1. í�´ë¦í•˜ë©´ íŒ�ì—…ì°½ ë�„우기 구현 ¶
- window.open함수를 ì�´ìš©í•˜ì—¬ body를 ë�”블 í�´ë¦í•˜ë©´ 새로운 íŒ�ì—…ì°½ì�„ ë�„운다.
<html>
<head>
<script language="javascript">
<!--
function na_open_window(name, url, left, top, width, height, toolbar, menubar, statusbar,
scrollbar, resizable)
{
toolbar_str = toolbar ? 'yes' : 'no';
menubar_str = menubar ? 'yes' : 'no';
statusbar_str = statusbar ? 'yes' : 'no';
scrollbar_str = scrollbar ? 'yes' : 'no';
resizable_str = resizable ? 'yes' : 'no';
window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height
+',toolbar='+toolbar_str+',menubar='
+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str
+',resizable='+resizable_str);
}
// -->
</script>
</head>
<body ondblclick = "na_open_window('win', 'popup.html', 50, 100, 100, 30, 0, 0, 0, 0, 0)">
</body>
</html>
<html> Hello World! </html>
4.2.4.1. History 지워주는 extension ¶
- 충격과 ê³µí�¬ë‹¤. 구글ì—�서 ì œê³µí•´ì¤€ Sampleì�´ 잘못ë�˜ìžˆì–´ì„œ 한참ì�„ 해멨다.
{
"name" : "BrowsingData API: Basics",
"version" : "1.1",
"description" : "A trivial usage example.",
"permissions": [
"browsingData"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html" //ì�´ê²Œ 그냥 popup으로 ë�˜ìžˆì—ˆë‹¤. browser_actionì�„ 보니 default_popupì�„ 해야지 action iconì�„ ëˆŒë €ì�„때 popupì�´ 뜬다.
},
"manifest_version": 2
}
4.2.4.2. Contents policy security ¶
- �건 매우 강조�어야한다.
<div OnClick="func()"> 와 ê°™ì�€ html 태그안ì�˜ inline ì�´ë²¤íЏ attachë�„ 안ë�˜ê¸° 때문ì—� documentì�˜ 쿼리를 ë‚ ë¦¬ë�˜ê°€ element를 찾아서 document.addEventListener 함수를 통해 event를 받아 functionì�´ ì—°ê²°ë�˜ê²Œ 해야한다. ì•„ ì�´ê±° 힘드네. ë�¼ëŠ” ìƒ�ê°�ì�´ 들었다.4.3. 헤메는 것 ¶
- Chrome extentionì�˜ overview를 ì�½ì–´ë³´ì•˜ëŠ”ë�° 다양한 기능ì�„ ì§€ì›�한다. 그중ì—� extentionì—�서 기본으로 ì œê³µí•˜ëŠ” background.htmlì�´ë�¼ëŠ”ê²ƒì�´ 있는ë�° ì�´ê²ƒì�´ extention기능으로 넣어놓ì�€ script를 모ë‘� í�¬í•¨í•˜ê³ ë©”ì�¸ 페ì�´ì§€ 밑단ì—� backgroundì—�서 계ì†�ë�Œì•„가면서 ì�´ë²¤íЏ 체킹ì�´ë‚˜ ë�°ì�´íƒ€ 처리를 해주는것 같았다. ì•„ì§�ë�„ ì •í™•ížˆ ëª¨ë¥´ê² ë‹¤ - 2012/7/3
"background": { "scripts": ["background.js"] },
"permissions": [
"tabs", "http://*/*"
],
조금� 찾아보�










