Skip to content

Instantly share code, notes, and snippets.

@hedgerh
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save hedgerh/e73cd1136f1f1d453ee2 to your computer and use it in GitHub Desktop.

Select an option

Save hedgerh/e73cd1136f1f1d453ee2 to your computer and use it in GitHub Desktop.
/**
* Angular application
*/
angular.module('SESApp', []);
/**
* Content script for the Soundcloud Following page.
*/
(function() {
// replace the user list with the following template
document.onreadystatechange = function() {
if (document.readyState === "complete") {
var contentDiv = document.querySelector('.usersList');
var parentDiv = document.querySelector('.g-main-scroll-area');
// remove the content being replaced
parentDiv.removeChild(contentDiv);
// get the template
chrome.runtime.sendMessage({
template: 'following/following'
}, function(response) {
// add the template to the page
var newDiv = document.createElement('div');
newDiv.innerHTML = response;
parentDiv.insertBefore(newDiv, parentDiv.childNodes[0]);
});
// angular needs to be bootstrapped manually
var angularDiv = document.querySelector('#content');
angular.bootstrap(angularDiv, ['SESApp']);
angularDiv.classList.add('ng-app');
angularDiv.classList.add('ng-csp');
}
};
}());
/**
* Follow View Controller
*/
angular.module('SESApp')
.controller('FollowingController', ['$scope', '$location', '$q', '$timeout', 'Soundcloud',
function($scope, $location, $q, $timeout, Soundcloud) {
$scope.getList = function(letter) {
$scope.follow = list[letters];
};
$scope.setCurrentLetter = function(letter) {
$scope.currentLetterGroup = $scope.following[letter];
$scope.currentLetter = letter;
};
}
])
.controller('GroupController', ['$scope', '$rootScope', '$location', '$http', 'Groups',
function($scope, $rootScope, $location, $http, Groups) {
(function getGroups() {
$scope.groups = Groups.all();
}());
$scope.activeGroup = [];
$scope.setActiveGroup = function setActiveGroup(group) {
if ($scope.activeGroup != group) {
$scope.activeGroup = group;
$rootScope.$broadcast('activeGroupChanged', group);
}
};
$scope.$apply();
}
])
.controller('StreamController', ['$scope', '$location', '$q', 'streamService', 'Groups', function($scope, $location, $q, streamService, Groups) {
// listen for group change and get the new stream
$scope.$on('activeGroupChanged', function buildActiveStream(event, group) {
streamService.buildStream(group.artists).then(function(stream) {
console.log(stream);
$scope.stream = stream;
});
});
$scope.$apply();
}]);
{
"name": "Soundcloud Enhancement Suite",
"version": "0.1.0",
"manifest_version": 2,
"description": "Soundcloud Enhancement Suite adds new features to the Soundcloud website.",
"icons": {
"48": "img/icon.png"
},
"browser_action": {
"default_icon": "img/icon.png",
"default_title": "Soundcloud Enhancement Suite"
},
"background": {
"page": "html/background/background.html"
},
"options_page": "html/background/options.html",
"permissions": [
"identity",
"storage",
"tabs",
"webRequest",
"webRequestBlocking",
"https://*.soundcloud.com/*",
"https://*.sndcdn.com/"
],
"web_accessible_resources": [
"js/*",
"html/*",
"css/*",
"img/*"
],
"content_scripts": [{
"matches": ["https://soundcloud.com/*/following"],
"js": [
"js/lib/angular/angular.min.js",
"js/app/app.js",
"js/app/controllers.js",
"js/app/content-script.js"
]
}],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment