Last active
April 11, 2017 13:27
-
-
Save anteriovieira/e621911ec7c232e5cd48ab186de2af51 to your computer and use it in GitHub Desktop.
Angular hijacked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ng = angular.module; | |
function module() { | |
var hijacked = ng.apply(this, arguments); | |
function component() { | |
} | |
hijacked.component = component; | |
return hijacked; | |
} | |
angular.module = module; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.config(['$provide', function($provide) { | |
$provide.decorator("$rootScope", function($delegate) { | |
var Scope = $delegate.constructor; | |
var origBroadcast = Scope.prototype.$broadcast; | |
var origEmit = Scope.prototype.$emit; | |
Scope.prototype.$broadcast = function() { | |
console.log("$broadcast was called on $scope " + $scope.$id + " with arguments:", | |
arguments); | |
return origBroadcast.apply(this, arguments); | |
}; | |
Scope.prototype.$emit = function() { | |
console.log("$emit was called on $scope " + $scope.$id + " with arguments:", | |
arguments); | |
return origEmit.apply(this, arguments); | |
}; | |
return $delegate; | |
}); | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const listDirectivesApp = () => { | |
const listDirectives = name => { | |
return angular | |
.module(name) | |
._invokeQueue | |
.filter(item => 'directive' === item[1]) | |
.map(item => item[2][0]); | |
}; | |
return angular | |
.modules | |
.map(listDirectives) | |
.reduce((acc, l) => acc.concat(l), []); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Inside vendor.js | |
source: http://stackoverflow.com/questions/24889783/angularjs-get-list-of-all-registered-modules | |
*/ | |
(function(orig) { | |
angular.modules = []; | |
angular.module = function() { | |
if (arguments.length > 1) { | |
angular.modules.push(arguments[0]); | |
} | |
return orig.apply(null, arguments); | |
} | |
})(angular.module); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment