Skip to content

Instantly share code, notes, and snippets.

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

  • Save ibolmo/9206949b7b4f6e9358aa to your computer and use it in GitHub Desktop.

Select an option

Save ibolmo/9206949b7b4f6e9358aa to your computer and use it in GitHub Desktop.
Trello Sort Search Cards by Earliest Deadline First
// ==UserScript==
// @name TrelloSortSearch
// @author Olmo Maldonado <ibolmo@gmail.com>
// @namespace https://gist.github.com/ibolmo
// @version 0.0.6
// @description Trello Sort Search Cards by Earliest Deadline First
// @match https://trello.com/search?q=*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
// @run-at document-end
// @copyright 2014+, Olmo Maldonado
// ==/UserScript==
(function(){
var go = function(){
var list = $('div.js-list')
list.children('.search-result-card').sort(function(a, b){
var dueA = $(a).find('.badge-state-due-future .badge-text').text().match(/\d+/) * 1;
if (!dueA) return -1;
var dueB = $(b).find('.badge-state-due-future .badge-text').text().match(/\d+/) * 1;
if (!dueB) return 1;
return dueA < dueB ? -1 : 1;
}).detach().appendTo(list);
};
var check = function(){
if ($('div.js-list .search-result-card').length){
console.log('Sort start.');
go();
} else {
console.log('Waiting for search to finish ...');
setTimeout(check, 500);
}
};
check();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment