Redmine Quick Jump Sort and direct jump

Sorts redmines project_quick_jump_box and enhances redmine by project shortcuts

  1. // ==UserScript==
  2. // @name Redmine Quick Jump Sort and direct jump
  3. // @version 0.4
  4. // @description Sorts redmines project_quick_jump_box and enhances redmine by project shortcuts
  5. // @match https://yourredmineserver.com/*
  6. // @namespace https://yourredmineserver.com/*
  7. // @copyright 2013+, bestmacfly
  8. // @author bestmacfly
  9. // ==/UserScript==
  10.  
  11. //please configure shortcuts here
  12. var project_shortcuts=new Array();
  13. project_shortcuts["c"]="project identifier 1";
  14. project_shortcuts["v"]="project identifier 2";
  15. project_shortcuts["d"]="project identifier 3";
  16.  
  17. //to which target would you like to jump when shortcut is pressed?
  18. //possible values e.g: overview, issues, welcome
  19.  
  20. var project_shortcuts_target="issues";
  21.  
  22. //please configure projects that should be removed from list
  23. var project_remove=new Array("project identifier 1","project identifier 2");
  24.  
  25. //please do not change following code!
  26.  
  27. function compare(a,b) {
  28. var atext=a.text;
  29. var btext=b.text;
  30. if (atext.toUpperCase() < btext.toUpperCase())
  31. return -1;
  32. if (atext.toUpperCase() > btext.toUpperCase())
  33. return 1;
  34. return 0;
  35. }
  36.  
  37. //Get selectbox
  38. var selectBox=document.getElementById("project_quick_jump_box");
  39.  
  40. //Copy text uand value to array. In addition uppercase variant is copied for better sorting.
  41. //start with third element, the first and second are labels
  42. var options=new Array();
  43. var index=0;
  44. for(var i=2;i<selectBox.options.length;i++){
  45. var currentOption=selectBox.options[i];
  46. //Check if option is on removelist
  47. var remove=false;
  48. for(var ri=0;ri<project_remove.length;ri++){
  49. if(currentOption.value.indexOf("/"+project_remove[ri]+"?")>-1){
  50. remove=true;
  51. break;
  52. }
  53. }
  54. if(!remove){
  55. if(currentOption.text.indexOf("»")>-1){ //subprojects shouldnt be sorted -> at the moment this only works for ONE subproject
  56. options[index-1].subOption=currentOption;
  57. }else{
  58. options[index++]=currentOption;
  59. }
  60. }
  61. }
  62.  
  63. for(i=selectBox.options.length;i>1;i--) {
  64. selectBox.options[i] = null;
  65. }
  66.  
  67. //sort
  68. options.sort(compare);
  69.  
  70. //Build up new optionlist
  71. for(i=0;i<options.length;i++){
  72. selectBox.options[selectBox.options.length]=options[i];
  73. if(options[i].subOption!=null)
  74. selectBox.options[selectBox.options.length]=options[i].subOption;
  75. }
  76.  
  77. //Jump to project on key pressed
  78. function keyPressed(char){
  79. var project=project_shortcuts[String.fromCharCode(char)];
  80. if(project!=undefined)
  81. {
  82. window.location.href="/projects/"+project+"?jump="+project_shortcuts_target;
  83. }
  84. }
  85.  
  86. //Register listener for key actions
  87. document.addEventListener('keypress', function(e) {
  88. e = e || window.event;
  89. var char = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
  90. if(typeof e.target.type == "undefined" || !e.target.nodeName.match(/input|select|textarea/i)) keyPressed(char);
  91. }, true);