Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save domharrington/d30771913655ad7950982dffdef765f9 to your computer and use it in GitHub Desktop.
Save domharrington/d30771913655ad7950982dffdef765f9 to your computer and use it in GitHub Desktop.
Adds a delete button to ionic app user device tokens
// ==UserScript==
// @name Adds a delete button to ionic app user device tokens
// @namespace http://tampermonkey.net/
// @version 0.1
// @author Dom Harrington (https://github.com/domharrington)
// @match https://apps.ionic.io/app/*/users/list
// @grant none
// ==/UserScript==
(function() {
'use strict';
setTimeout(function () {
var users = document.querySelectorAll('tr[ng-click]');
console.log('users', users);
[].map.call(users, function (user) {
user.onclick = function () {
setTimeout(addDeleteButtons, 1000);
};
});
}, 1000);
var $http = angular.element(document.body).injector().get('$http');
function addDeleteButtons() {
var tokens = document.querySelectorAll('.push-tokens code');
console.log('push device tokens', tokens);
[].map.call(tokens, function (token) {
var button = document.createElement('button');
button.textContent = 'Delete';
button.onclick = deleteToken.bind(null, token, angular.element(token).scope().token.id);
token.appendChild(button);
});
function deleteToken(el, token) {
console.log('Deleting: ', token);
if (!localStorage.ionicApiToken) return alert('API token must be set at `localStorage.ionicApiToken`');
$http.delete('https://api.ionic.io/push/tokens/' + token, {
headers: { Authorization: 'Bearer ' + localStorage.ionicApiToken }
}).then(function () {
alert('Successfully deleted: ' + token);
el.remove();
}).catch(function (err) {
alert('Error deleting token');
console.error(err);
});
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment