-
Notifications
You must be signed in to change notification settings - Fork 0
/
mass-action.js
115 lines (96 loc) · 2.71 KB
/
mass-action.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"use strict";
/*
* Mass action extension for Chromium
*/
let current_list = undefined;
/*
* Initialize all observer used by this extension.
*/
function initialize_observers() {
var menu_entries = [
{ match: ".js-add-card", callback: rename_observer },
{ match: ".js-archive-cards", callback: move_to_observer }
];
const Observer = window.MutationObserver || window.WebKitMutationObserver;
let listObserver = new Observer(function(records) {
records.forEach(function(rec) {
$(rec.addedNodes).each(function() {
if ($(rec.target).hasClass('pop-over')) {
menu_entries.forEach(function (entry) {
$(this).find(entry.match).each(function() {
entry.callback.apply(this);
});
}, this);
}
});
});
});
listObserver.observe(document.body, { childList: true, subtree: true });
}
/*
* Authorize trello client with trello API.
*/
function authorize_trello() {
chrome.storage.local.get('login', function(result) {
const name = $('.js-member-name').text();
if ($.isEmptyObject(result) || result.login != name)
Trello.deauthorize();
});
if (Trello.authorized())
return;
Trello.authorize({
type: 'popup',
name: 'Trello Mass action extension',
persist: true,
interactive: true,
scope: {
read: true,
write: true,
account: false
},
expiration: 'never',
success: function () {
const name = $('.js-member-name').text();
chrome.storage.local.set({'login': name});
},
error: function () {
alert('Could not authentificate with Trello. MassTrello will not work correctly');
}
});
}
function basic_callbacks() {
$(document).on('click', '.ma-list-select-all', function() {
const $select = $($(this).parent().prev().children('option'));
$select.prop('selected', true);
$select.trigger('change');
});
$(document).on('click', '.ma-list-unselect-all', function() {
const $select = $($(this).parent().prev().children('option'));
$select.prop('selected', false);
$select.trigger('change');
});
$('.js-open-list-menu').click(function() {
current_list = $(this).closest(".list");
});
$(document).on('click', '.js-open-board', function() {
/* Seems the only way to announce the set list functionality
* after board change
*/
window.setTimeout(function() {
basic_callbacks();
}, 1000);
window.setTimeout(function() {
basic_callbacks();
}, 1800);
});
}
/*
* Intialize the system after the trello page has loaded completly
*/
$(document).ready(function() {
initialize_observers();
authorize_trello();
rename_callbacks();
move_to_callbacks();
basic_callbacks();
});