Created
October 2, 2020 10:27
-
-
Save Matus-Stastny/3e4d42b7929fc8f8a44da5b719e509b5 to your computer and use it in GitHub Desktop.
Script used by Tampermonkey extension to hide autogenerated files in Gitlab's MR.
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 Gitlab hide .graphql.js/.ts diffs | |
// @version 0.1 | |
// @author Matus | |
// @include https://gitlab.skypicker.com/*/*/-/merge_requests/*/diffs | |
// @grant none | |
// ==/UserScript== | |
function waitUntilLoaded(){ | |
return new Promise((res, reject) => { | |
const intervalId = window.setInterval(() => { | |
const fileHeaders = document.getElementsByClassName('file-header-content'); | |
if(fileHeaders.length > 0){ | |
res(fileHeaders); | |
window.clearInterval(intervalId) | |
} | |
}, 2000) | |
}) | |
} | |
(async function() { | |
const fileHeaders = await waitUntilLoaded(); | |
const fileHeadersArr = [].slice.call(fileHeaders); | |
function eventFire(el, etype){ | |
if (el.fireEvent) { | |
el.fireEvent('on' + etype); | |
} else { | |
const evObj = document.createEvent('Events'); | |
evObj.initEvent(etype, true, false); | |
el.dispatchEvent(evObj); | |
} | |
} | |
console.log("%c Tampermonkey script has just collapesed all '.graphql.js' files", "background: #222; color: #bada55" ); | |
fileHeadersArr.forEach(header => { | |
const title = header.childNodes[2].innerText; | |
if(title.slice(-10) === 'graphql.js' || title.slice(-10) === 'graphql.ts'){ | |
eventFire(header.childNodes[0], 'click') | |
} | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment