-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
27 lines (24 loc) · 963 Bytes
/
content.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
var container, module, run, shadowRoot, viewURL;
container = document.createElement('span');
module = angular.module('myApp', [])
shadowRoot = document.documentElement.createShadowRoot();
shadowRoot.appendChild(container);
viewURL = chrome.runtime.getURL('view.html');
module.controller('MyCtrl', ['$scope', function ($scope) {
$scope.state = 'off';
$scope.$on('switch', function () {
console.log('switching');
$scope.state = $scope.state === 'off' ? 'on' : 'off';
});
}]);
module.run(['$rootElement', '$rootScope', function ($rootElement, $rootScope) {
$rootElement.html('<ng-include src="\'' + viewURL + '\'" />');
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
console.log('got message', message);
if (message === 'switch') {
$rootScope.$broadcast('switch');
$rootScope.$apply();
}
});
}]);
angular.bootstrap(container, [module.name]);