Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save co3k/4265184 to your computer and use it in GitHub Desktop.
Save co3k/4265184 to your computer and use it in GitHub Desktop.
User script to inject associated revisions to ticket note list on redmine.openpne.jp
// ==UserScript==
// @name inject assosicated revisions to ticket note list
// @namespace co3k.org
// @include https://redmine.openpne.jp/issues/*
// @version 1
// ==/UserScript==
(function(){
var xpathToIssueChangesets = "//*[@id='issue-changesets']/div[contains(@class, 'changeset')]/p/span/a[contains(@href, '/activity?from')]";
var changesets = document.evaluate(xpathToIssueChangesets, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if (1 > changesets.snapshotLength) {
return;
}
var xpathToJournal = "//*[@id='history']/div[contains(@class, 'journal')]/h4/a[contains(@href, '/activity?from')]";
var journals = document.evaluate(xpathToJournal, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
if (1 > journals.snapshotLength) {
return;
}
for (var i = 0; i < changesets.snapshotLength; i++) {
var changeset = changesets.snapshotItem(i);
var changesetTimestamp = Date.parse(changeset.getAttribute("title").replace(/-/g, "/"));
for (var j = 0; j < journals.snapshotLength; j++) {
var journal = journals.snapshotItem(j);
var journalTimestamp = Date.parse(journal.getAttribute("title").replace(/-/g, "/"));
if (journalTimestamp > changesetTimestamp) {
var newNote = document.createElement("div");
newNote.setAttribute("class", "journal has-notes");
newNote.innerHTML = '<h4 style="background-color: rgb(255, 255, 221)"><img class="gravatar" src="https://secure.gravatar.com/avatar/DUMMY?rating=PG&size=24&default="></img> Commit '+changeset.parentNode.innerHTML+'</h4>';
var newDetailUl = document.createElement("ul");
newDetailUl.setAttribute("class", "details");
var newDetailLi = document.createElement("li");
newDetailLi.innerHTML = "<strong>Commit </strong>";
newDetailLi.appendChild(changeset.parentNode.parentNode.getElementsByTagName("a")[0].cloneNode());
newDetailUl.appendChild(newDetailLi);
newNote.appendChild(newDetailUl);
newNote.appendChild(changeset.parentNode.parentNode.parentNode.getElementsByClassName("wiki")[0].cloneNode());
journal.parentNode.parentNode.parentNode.insertBefore(newNote, journal.parentNode.parentNode);
break;
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment