HTML/CSS/JavaScriptで作る、ブラウザをもっと便利にするモノ
作るのはすごく簡単です
まず、manifest.jsonというファイルを作ります
{
"name": "cookpad speech search",
"description": "クックパッドで音声検索できるようにします",
"version": "0.1",
"content_scripts": [
{
"matches": ["http://cookpad.com/*"],
"js": ["content_script.js"],
"run_at": "document_end"
}
]
}
続いて、content_script.jsを作ります
var keyword = document.querySelector('#keyword');
keyword.setAttribute('x-webkit-speech', '');
中身はこれだけです
拡張機能のページを開く
デベロッパーモードにチェック
パッケージ化されていない拡張機能を読み込む…
先ほどのファイルを保存したフォルダを選択します
var keyword = document.querySelector('#keyword');
console.log(keyword);
keyword.setAttribute('x-webkit-speech', '');
デベロッパーツールのコンソールに要素が出ます
※.jsファイルなどを修正したときは、「再読み込み」ボタンを押さないと反映されないのでご注意を
var keyword = document.querySelector('#keyword');
debugger;
keyword.setAttribute('x-webkit-speech', '');
デベロッパーツールを開いていると、JavaScriptの実行が止まり、ステップ実行できます
Twitterの検索APIを使って、特定のキーワードをAjaxで取ってきてNotificationで取得します。
{
"name": "Tweet Notify",
"description": "特定のキーワードが含まれるTweetをデスクトップに表示します",
"version": "0.1",
"background_page": "background.html",
"icons": {
"48": "Twitter-icon.png"
},
"permissions": [
"notifications",
"http://search.twitter.com/",
"http://twitter.com/"
]
}
<!DOCTYPE html>
<meta charset="utf-8">
<script src="jquery.min.js"></script>
<script>
var CheckTime = 60;
var keyword = 'cookpad.com';
var start = function() {
var api = 'http://search.twitter.com/search.json';
var url = api + '?q=' + encodeURIComponent(keyword);
var main = function() {
$.get(url, function(data) {
if (data && data.results && data.results.length) {
data.results.reverse().forEach(function(item, i) {
var notify = webkitNotifications.createNotification(item.profile_image_url, keyword + 'の検索結果', item.text);
notify.ondisplay = function() {
setTimeout(function() {
notify.cancel();
}, 5 * 1000);
};
notify.show();
});
}
});
};
setInterval(main, 60*1000);
main();
};
start();
</script>
はじめてのChrome extension(チューターをされていた吉川さんのプレゼン資料です)をどうぞ!