Skip to content

Instantly share code, notes, and snippets.

@tetsutan
Created October 24, 2011 13:08
Show Gist options
  • Save tetsutan/1308985 to your computer and use it in GitHub Desktop.
Save tetsutan/1308985 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name OpenAll Redmine
// @namespace org.no-ip.knell
// @include *
// ==/UserScript==
(function(){
var check_redmine = function(){
var metas = document.getElementsByTagName('meta');
for(var i in metas){
if(metas[i].name == "description" && metas[i].content == "Redmine"){
return true;
}
}
return false;
};
var check_tickets_path = function(){
var href = document.location.href;
return href.match(/projects\/[^\/]*\/issues/)
};
var set_open_all_button = function(){
var already_exist = document.getElementById('redmine_open_all');
if(already_exist) return;
var form = document.getElementById("query_form");
if(!form) return false;
var p = form.getElementsByClassName("buttons")
if(!p) return false;
var a = document.createElement("a");
a.id = "redmine_open_all";
a.className="icon icon-checked";
a.href = "#";
a.innerHTML = "OpenALL";
a.addEventListener('click',open_all)
p[0].appendChild(a);
};
var root_url = location.protocol + "//" + location.host + "/";
var open_all = function(e){
var issues = document.getElementsByClassName("issue")
for(var i in issues){
var issue = issues[i]
var inputs = issue.getElementsByTagName("input");
for(var j in inputs){
if(inputs[j].checked){
setTimeout((function(url){
return function(){
window.open(url)
}
})(root_url + "issues/" + inputs[j].value),100);
}
}
}
return false;
};
var set_all_click_to_refresh = function(){
var as = document.getElementsByTagName("a");
for(var i=0; i<as.length; i++){
var className = "icon" // icon icon-checked
var pattern = new RegExp('(^|\\s)' + className + '(\\s|$)');
if(!patter.test(as[i].className)){
continue;
}
as[i].addEventListener("click",function(e){
setTimeout(function(){
set_open_all_button()
},2000)
});
}
};
var update_apply_filters_observer = function(){
// var orig = apply_filters_observer;
// if(orig){
// apply_filters_observer = function(){
// set_open_all_button()
// arguments.apply(this,orig)
// };
// }
};
// window.addEventListener("load",function(){
window.addEventListener ("DOMContentLoaded", function(){
if(check_redmine() && check_tickets_path()){
update_apply_filters_observer()
set_all_click_to_refresh();
set_open_all_button()
}
}, false);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment