92 lines
2.9 KiB
JavaScript
92 lines
2.9 KiB
JavaScript
// ==UserScript==
|
|
// @name Sort JIRA names
|
|
// @namespace Violentmonkey Scripts
|
|
// @match https://*.atlassian.net/*
|
|
// @grant GM_info
|
|
// @run-at document-idle
|
|
// @version 1.0
|
|
// @author Rob Pearce
|
|
// @description Makes the list of Jira assignee names actually be sorted
|
|
// ==/UserScript==
|
|
|
|
var MAGICSTRING = '.guavb6-1';
|
|
|
|
|
|
function getnames(aa) {
|
|
let names = '';
|
|
aa.forEach(function (currentValue, currentIndex, listob) {
|
|
names = names + listob[currentIndex].innerText;
|
|
//console.log(currentValue + ' ' + currentIndex + ' ' + listob[currentIndex].innerText);
|
|
});
|
|
return names;
|
|
}
|
|
|
|
function showarr(aa) {
|
|
aa.forEach(function (currentValue, currentIndex, listob) {
|
|
console.log(currentValue + ' ' + currentIndex + ' ' + listob[currentIndex].innerText);
|
|
});
|
|
}
|
|
|
|
function get_sorted_list(parent) {
|
|
let classname = parent.className;
|
|
let toks = classname.split(/ |-/);
|
|
let basename = toks[0];
|
|
let idx = parseInt(toks[1]);
|
|
let child_div_selector = "." + basename + "-" + (idx+1);
|
|
let grandchild_div_selector = "." + basename + "-" + (idx+5);
|
|
let unsorted_names = parent.querySelectorAll(child_div_selector);
|
|
let unsorted_names_a = Array.prototype.slice.call(unsorted_names, 0);
|
|
let sorted_names_a = unsorted_names_a.sort(function(a,b) {
|
|
let va = a.querySelector(grandchild_div_selector).innerText;
|
|
let vb = b.querySelector(grandchild_div_selector).innerText;
|
|
return va.toLowerCase().localeCompare(vb.toLowerCase());
|
|
});
|
|
|
|
return sorted_names_a;
|
|
}
|
|
|
|
function actually_do_sort(elem) {
|
|
let sorted_names = get_sorted_list(elem);
|
|
sorted_names.forEach(function(node) { elem.append(node); });
|
|
}
|
|
|
|
function wait_for(elem_selector, callback) {
|
|
var tries = 0;
|
|
var maxtries = 0;
|
|
var wantit = 1;
|
|
var actually_wait = function() {
|
|
var elem = document.querySelector(elem_selector);
|
|
if (wantit) {
|
|
if (elem) {
|
|
callback(elem);
|
|
tries = 0;
|
|
wantit = 0;
|
|
setTimeout(actually_wait, 250 * Math.pow(1.1, tries));
|
|
} else {
|
|
tries++;
|
|
if (maxtries != 0 && tries >= maxtries) {
|
|
console.warn('doesnt exist after ' + maxtries + ' attempts: ' + elem_selector);
|
|
} else {
|
|
setTimeout(actually_wait, 250 * Math.pow(1.1, tries));
|
|
}
|
|
}
|
|
} else {
|
|
if (elem) {
|
|
tries++;
|
|
if (maxtries != 0 && tries >= maxtries) {
|
|
console.warn('still exists after ' + maxtries + ' attempts: ' + elem_selector);
|
|
} else {
|
|
setTimeout(actually_wait, 250 * Math.pow(1.1, tries));
|
|
}
|
|
} else { // element has disappeared
|
|
wantit = 1;
|
|
tries = 0;
|
|
setTimeout(actually_wait, 250 * Math.pow(1.1, tries));
|
|
}
|
|
}
|
|
};
|
|
actually_wait();
|
|
}
|
|
|
|
wait_for(MAGICSTRING, actually_do_sort);
|