public
Last active

Trello: Add multiple cards bookmarklet

  • Download Gist
import_cards.js
JavaScript
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
(function () {
var body = document.getElementsByTagName("body")[0];
var bg = document.createElement("div");
bg.setAttribute("style", "position: absolute; z-index: 1000; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.5)");
var form = document.createElement("div");
form.setAttribute("style", "margin: 0 auto; height: 100%; width: 800px; padding: 50px; background: rgb(200, 200, 220);");
 
form.appendChild(document.createTextNode("Board: "));
var list_select = document.createElement("select");
var lists = boardView.model.listList.models;
for (var i = 0; i < lists.length; ++i) {
var option = document.createElement("option");
option.innerText = lists[i].attributes.name;
list_select.appendChild(option);
}
form.appendChild(list_select);
form.appendChild(document.createElement("br"));
 
var cards_entry = document.createElement("textarea");
form.appendChild(document.createTextNode("Enter one card per line:"));
form.appendChild(cards_entry);
var submit = document.createElement("input");
submit.setAttribute("type", "submit");
submit.onclick = function () {
var list = lists[list_select.selectedIndex];
var board_id = list.getBoard().id;
var cards = cards_entry.value.split('\n');
for (var i = 0; i < cards.length; ++i) {
var card = cards[i].trim();
if (card == '') {
continue;
}
 
list.onId(function (list_id) {
return list.cardList.create({
name: card,
pos: list.calcPos(list.cardList.length),
closed: false,
idBoard: board_id,
idList: list_id
});
});
}
 
body.removeChild(bg);
};
form.appendChild(submit);
bg.appendChild(form);
body.appendChild(bg);
})();
import_cards_bookmarklet.txt
1
javascript:%28function%28%29%7Bvar%20f%3Ddocument.getElementsByTagName%28%22body%22%29%5B0%5D%3Bvar%20c%3Ddocument.createElement%28%22div%22%29%3Bc.setAttribute%28%22style%22%2C%22position%3A%20absolute%3B%20z-index%3A%201000%3B%20top%3A%200%3B%20right%3A%200%3B%20bottom%3A%200%3B%20left%3A%200%3B%20background%3A%20rgba%280%2C%200%2C%200%2C%200.5%29%22%29%3Bvar%20a%3Ddocument.createElement%28%22div%22%29%3Ba.setAttribute%28%22style%22%2C%22margin%3A%200%20auto%3B%20height%3A%20100%25%3B%20width%3A%20800px%3B%20padding%3A%2050px%3B%20background%3A%20rgb%28200%2C%20200%2C%20220%29%3B%22%29%3Ba.appendChild%28document.createTextNode%28%22Board%3A%20%22%29%29%3Bvar%20b%3Ddocument.createElement%28%22select%22%29%3Bvar%20j%3DboardView.model.listList.models%3Bfor%28var%20d%3D0%3Bd%3Cj.length%3B%2B%2Bd%29%7Bvar%20e%3Ddocument.createElement%28%22option%22%29%3Be.innerText%3Dj%5Bd%5D.attributes.name%3Bb.appendChild%28e%29%7Da.appendChild%28b%29%3Ba.appendChild%28document.createElement%28%22br%22%29%29%3Bvar%20h%3Ddocument.createElement%28%22textarea%22%29%3Ba.appendChild%28document.createTextNode%28%22Enter%20one%20card%20per%20line%3A%22%29%29%3Ba.appendChild%28h%29%3Bvar%20g%3Ddocument.createElement%28%22input%22%29%3Bg.setAttribute%28%22type%22%2C%22submit%22%29%3Bg.onclick%3Dfunction%28%29%7Bvar%20m%3Dj%5Bb.selectedIndex%5D%3Bvar%20o%3Dm.getBoard%28%29.id%3Bvar%20n%3Dh.value.split%28%22%5Cn%22%29%3Bfor%28var%20l%3D0%3Bl%3Cn.length%3B%2B%2Bl%29%7Bvar%20k%3Dn%5Bl%5D.trim%28%29%3Bif%28k%3D%3D%22%22%29%7Bcontinue%7Dm.onId%28function%28i%29%7Breturn%20m.cardList.create%28%7Bname%3Ak%2Cpos%3Am.calcPos%28m.cardList.length%29%2Cclosed%3Afalse%2CidBoard%3Ao%2CidList%3Ai%7D%29%7D%29%7Df.removeChild%28c%29%7D%3Ba.appendChild%28g%29%3Bc.appendChild%28a%29%3Bf.appendChild%28c%29%7D%29%28%29%3B

Thanks. This is a huge help. You rock!

Thanks from me, too. Still works today. :)

Great tool, thanks. Would be amazing if there will be an option to set label/member for the tasks.

Sounds great, unfortunately:

Uncaught ReferenceError: boardView is not defined

trello change their api?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.