Skip to content

Instantly share code, notes, and snippets.

@ninedraft
Last active February 27, 2020 09:55
Show Gist options
  • Save ninedraft/5bdcb67a0ed2da27ffa4aaa43701079c to your computer and use it in GitHub Desktop.
Save ninedraft/5bdcb67a0ed2da27ffa4aaa43701079c to your computer and use it in GitHub Desktop.
Export merge requests from Gitlab page to a formatted text list with links and short descriptions
// ==UserScript==
// @name Export merge requests to a text file
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://git.kodix.ru/vgr/garage/merge_requests
// @grant none
// ==/UserScript==
(function() {
'use strict';
function copyToClipboard(text) {
var dummy = document.createElement("textarea");
// to avoid breaking orgain page when copying more words
// cant copy when adding below this code
// dummy.style.display = 'none'
document.body.appendChild(dummy);
//Be careful if you use texarea. setAttribute('value', value), which works with "input" does not work with "textarea". – Eduard
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
var button = document.createElement("button");
button.innerHTML = "Export MRs";
button.type = "submit";
button.classList.add("btn");
button.classList.add("append-right-10");
button.classList.add("js-bulk-update-toggle");
button.addEventListener ("click", function() {
var query = "//*[contains(concat(' ', normalize-space(@class),' '), 'merge-request-title-text ')]/a";
var formatter = function(elem, i) {
return "review " + elem.innerText + ". Link: " + elem.href;
}
var result = document.evaluate(query, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null)
var thisNode = result.iterateNext()
var tasks = [];
while(thisNode) {
tasks.push(thisNode);
thisNode = result.iterateNext();
}
var txt =tasks.map(formatter).join('\n');
copyToClipboard(txt);
if (!button.innerHTML.includes('✅')) {
button.innerHTML += ' ✅';
}
});
var navigation = document.getElementsByClassName("nav-controls")[0];
navigation.appendChild(button);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment