forked from podStation/podStation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
71 lines (59 loc) · 2.35 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
$(document).ready(function() {
$('#open').click(function(event) {
event.preventDefault();
chrome.runtime.getBackgroundPage(function(bgPage) {
bgPage.openPodStation();
});
});
});
var myApp = angular.module('podstationPopupApp', ['podstationInternalReuse']);
myApp.controller('feedsInPageController', ['$scope', 'analyticsService', function($scope, analyticsService) {
$scope.feedsInPage = [];
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
var tab = tabs[0];
chrome.tabs.sendMessage(tab.id, {action: 'getFeeds'}, function(response) {
chrome.runtime.getBackgroundPage(function(bgPage) {
$scope.$apply(function() {
$scope.feedsInPage = response;
$scope.feedsInPage.forEach(function(item) {
item.added = bgPage.podcastManager.getPodcast(item.url) !== undefined;
item.addPodcast = function() {
var that = this;
// better get the background page again in this case,
// as it may have been unloaded
chrome.runtime.getBackgroundPage(function(bgPage) {
analyticsService.trackEvent('feed', 'add_by_feeds_in_page');
bgPage.podcastManager.addPodcast(that.url);
bgPage.openPodStation('Podcasts');
});
}
});
});
});
});
});
}]);
myApp.filter('chrome_i18n', function() {
return function(input) {
if(typeof input === 'object') {
return chrome.i18n.getMessage(input.message, input.arguments);
}
else if (typeof input === 'string') {
return chrome.i18n.getMessage(input);
}
};
});
angular.module('podstationPopupApp').run(['messageService', 'analyticsService', function(messageService, analyticsService) {
messageService.for('optionsManager').sendMessage('getOptions', {}, function(options) {
if(options.analytics) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-67249070-2', 'auto');
// https://stackoverflow.com/questions/16135000/how-do-you-integrate-universal-analytics-in-to-chrome-extensions/17770829#17770829
ga('set', 'checkProtocolTask', function(){});
analyticsService.trackPageView('/feedsInPage');
}
});
}]);