aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--background.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/background.js b/background.js
new file mode 100644
index 00000000..3c0a0222
--- /dev/null
+++ b/background.js
@@ -0,0 +1,15 @@
+chrome.tabs.onUpdated.addListener(
+ function(tabId, changeInfo, tab) {
+ if (youtube_parser(changeInfo.url)) {
+ chrome.tabs.sendMessage( tabId, {
+ message: 'ytvideo',
+ url: changeInfo.url
+ })
+ }
+ }
+);
+function youtube_parser(url) {
+ var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
+ var match = url.match(regExp);
+ return (match && match[7].length == 11) ? match[7] : false;
+}