// ==UserScript==
// @name           Dreamwidth Bug Resolver
// @namespace      http://afunamatata.com/greasemonkey/
// @description    Mark a bug as RESOLVED FIXED with one click
// @include        http://bugs.dwscoalition.org/*_bug.cgi*
// ==/UserScript==


var current_status = document.getElementById('static_bug_status');
if ( current_status ) {

    var new_status;
    var new_resolution;

    if ( current_status.textContent.indexOf('ASSIGNED') == 0 || current_status.textContent.indexOf('REOPENED') == 0 ) { 
        new_status = "RESOLVED";
        new_resolution = "FIXED";
    } else if (current_status.textContent.indexOf('RESOLVED') == 0 ) {
        new_status = "REOPENED";
        new_resolution = "";
    } 

    if (new_status) {
        var change_status_link = document.createElement('a');
        change_status_link.innerHTML = "Set status to " + new_status;
        change_status_link.href="#";
        change_status_link.addEventListener("click", function(event) {
            document.getElementById("bug_status").value = new_status;
            document.getElementById("resolution").value = new_resolution;
            document.getElementById("resolution").className = "";
            document.location = "#bug_status";
            event.preventDefault();
            event.stopPropagation();
        }, false);
    
        current_status.parentNode.appendChild( change_status_link );
    }
}
