-
-
Save kmagiera/9b882a976e32bb36043c 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 Side-by-side view on gitlab | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author Krzys | |
// @match http://gitlab.oddshot.tv/* | |
// @grant none | |
// ==/UserScript== | |
/* jshint -W097 */ | |
'use strict'; | |
// Add this: | |
var _wr = function(type) { | |
var orig = history[type]; | |
return function() { | |
var rv = orig.apply(this, arguments); | |
var e = new Event(type); | |
e.arguments = arguments; | |
window.dispatchEvent(e); | |
return rv; | |
}; | |
}; | |
history.pushState = _wr('pushState'), history.replaceState = _wr('replaceState'); | |
window.addEventListener('replaceState', function(e) { | |
fire(); | |
}); | |
var _getVars = function() { | |
var vars = {}, hash; | |
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | |
for(var i = 0; i < hashes.length; i++) | |
{ | |
hash = hashes[i].split('='); | |
vars[hash[0]] = hash[1]; | |
} | |
return vars; | |
} | |
var timeout; | |
var fire = function() { | |
timeout && window.clearTimeout(timeout); | |
if (window.location.pathname.endsWith('/diffs')) { | |
var vars = _getVars(); | |
if (vars["view"] === undefined) { | |
var handler = () => { | |
var element = $('a[href*="parallel"]').get(0); | |
if (element) element.click(); | |
else timeout = window.setTimeout(handler, 100); | |
}; | |
handler(); | |
} | |
} | |
} | |
fire(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment