-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIDSelector.js
48 lines (42 loc) · 1.23 KB
/
IDSelector.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
// ==UserScript==
// @name Filter Bubble ID Selector
// @version 1
// @grant none
// @include https://bubble.labs.vu.nl/data/export
// ==/UserScript==
var actions = [
{
keyCodeList: [17, 13], // Ctrl+Enter
actionFunction: function(){selectIDs();}
}
]
var keyCodeMap = {};
mapContains = function(keyCode) {
return keyCodeMap[keyCode];
}
containsAllAndOnly = function(keyCodeList) {
return keyCodeList.length == Object.keys(keyCodeMap).filter(item => keyCodeMap[item]).length && keyCodeList.every(mapContains);
}
onkeydown = onkeyup = function(e) {
e = e || event; // to deal with IE
if (e.type == 'keydown') {
keyCodeMap[e.keyCode] = true;
}
keyCodeMap[e.keyCode] = e.type == 'keydown';
actions.forEach(function(element) {
if (containsAllAndOnly(element.keyCodeList)) {
element.actionFunction();
}
});
}
selectIDs = function() {
var idString = prompt("Please enter the list of ID's.", "Format should be ['id1','id2'...]");
if (idString == null || idString == "") {
alert("Something went wrong.");
} else {
var idList = JSON.parse(idString.replace(/'/g,"\""));
for (var i=0; i<idList.length; i++) {
document.getElementById("source_" + idList[i]).click();
}
}
}