Last active
August 29, 2015 14:03
-
-
Save atiking/7910881635122d03fd1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Redmine Link To Reporter | |
// @namespace http://www.jinyao.me | |
// @description Add a link to reassign the issue to reporter and commenter | |
// @include */issues/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function addJQuery(callback) { | |
var script = document.createElement('script'); | |
script.setAttribute('src', 'http://lib.sinaapp.com/js/jquery/2.0.3/jquery-2.0.3.min.js'); | |
script.addEventListener('load', function () { | |
var script = document.createElement('script'); | |
script.textContent = 'window.jQ=jQuery.noConflict(true);(' + callback.toString() + ')();'; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
// the guts of this userscript | |
function main() { | |
console.log('Redmine Link To Reporter Start.'); | |
unique_commenter = { | |
}; | |
jQ('#history') .find('[href^=\'/users\']') .each(function () { | |
var commenter_id = jQ(this) .attr('href') .split('/') [2]; | |
if (!unique_commenter[commenter_id]) { | |
jQ('#issue_assigned_to_id') .after( | |
jQ(this) .clone() .click(function () { | |
jQ('#issue_assigned_to_id') .val(commenter_id); | |
console.log(commenter_id); | |
return false; | |
}).css({"padding": "3px"}) | |
) | |
unique_commenter[commenter_id] = true; | |
} | |
}) | |
jQ('#issue_assigned_to_id') .after( | |
jQ('.issue > p.author > a') .first() .clone() .click(function () { | |
reporter_id = jQ(this) .attr('href') .split('/') [2]; | |
jQ('#issue_assigned_to_id') .val(reporter_id); | |
return false; | |
}).prepend("报告者:") | |
) | |
} | |
// load jQuery and execute the main function | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment