Skip to content

Instantly share code, notes, and snippets.

@nash716
Created Dec 19, 2011
Embed
What would you like to do?
background.html
<html><head>
<script>
var url = 'http://localhost:12000/#receive';
var type;
chrome.tabs.onUpdated.addListener(function(id, info, tab) { // タブが更新されたときに呼ばれる
if (tab.url.match(url)) {
// 命令部分だけを取り出す
type = JSON.parse(tab.url.substring(url.length + 1)).type;
chrome.tabs.getAllInWindow(null, function(tabs) {
for (var i=0; i<tabs.length; i++) {
// ニコニコ動画を開いているタブを探す
if (tabs[i].url.match('http://www.nicovideo.jp/watch/sm')) {
var tabId = tabs[i].id;
switch(type) {
case 'stop':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_play(false);'}
);
break;
case 'play':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_play(true);'}
);
break;
case 'chide':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_setCommentVisible(false);'});
break;
case 'cdisp':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_setCommentVisible(true);'}
);
break;
case 'fullscreen':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_setVideoSize(\'fit\');'}
);
break;
case 'normal':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_setVideoSize(\'normal\');'}
);
break;
case 'mute':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_setMute(true);'}
);
break;
case 'muteoff':
chrome.tabs.executeScript(tabId,
{'code': 'document.getElementById(\'flvplayer\').ext_setMute(false);'}
);
break;
case 'earth':
chrome.tabs.executeScript(tabId,
{'code': 'document.location=\'http://www.nicovideo.jp/watch/sm663696\';'}
);
break;
}
}
}
});
}
});
</script>
</head><body>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment