こんばんは!変態アドベントカレンダー( http://atnd.org/events/22020 )の11日目です。
Chrome Web Store - 変態アドベントカレンダー 2011 11日目
- Chrome拡張のアイコンをクリックするといつでもATNDにいけます。
- Googleさんで検索したときに便利になります。
ソース
javascriptの書き方わからんのやけど(´・ω・`)。一応書いとくね。
manifest.json
設定ファイルね。
browser_actionがブラウザの右上に出てるアイコンの部分。
content_scriptsがページ読み込んだときの動作。
{
"name": "変態アドベントカレンダー 2011 11日目",
"version": "1.2",
"description": "\"変態アドベントカレンダー2011\"の11日目のChrome拡張です。",
"icons": {
"16": "icons/hen16.png",
"32": "icons/hen32.png",
"48": "icons/hen48.png",
"128": "icons/hen128.png"
},
"browser_action": {
"default_icon": "icons/hen19.png",
"default_title": "変態アドベントカレンダー2011"
},
"background_page": "background.html",
"content_scripts": [ {
"js": [ "content.js" ],
"matches": [ "http://www.google.com/search?*", "http://www.google.co.jp/search?*" ],
"run_at": "document_end"
} ],
"permissions": [
"tabs",
"http://www.google.com/search?*",
"http://www.google.co.jp/search?*"
]
}
アイコンクリックしたらatndに飛ぶようにしたー。
<html>
<head>
<script>
const ATND_URL = "http://atnd.org/events/22020";
function goToAtnd() {
chrome.tabs.getAllInWindow(undefined, function(tabs) {
for (var i = 0, tab; tab = tabs[i]; i++) {
if (tab.url && isAtndUrl(tab.url)) {
chrome.tabs.update(tab.id, {selected: true});
return;
}
}
chrome.tabs.create({url: ATND_URL});
});
}
function isAtndUrl(url) {
return (url == ATND_URL);
}
chrome.browserAction.onClicked.addListener(function(tab) {
goToAtnd();
});
</script>
</head>
</html>
content.js
もしかして: 変態?
var topstuffElem = document.getElementById('topstuff')
if(topstuffElem) {
var element = document.createElement('p');
element.className='ssp';
element.innerHTML = '<span class="spell ng">もしかして: </span><a href="http://atnd.org/events/22020" class="spell"><b>変態</b></a> <br>';
topstuffElem.appendChild(element);
}
ちなみに
ChromeWebStoreで"変態"で検索かけると...
Chrome Web Store
わーい
続くといいなぁ。おやすみ。