Skip to content

Instantly share code, notes, and snippets.

@ajhsu
Last active June 1, 2018 07:46
Show Gist options
  • Select an option

  • Save ajhsu/fcd3d4c6d82092fae7e9d87a326e8c5c to your computer and use it in GitHub Desktop.

Select an option

Save ajhsu/fcd3d4c6d82092fae7e9d87a326e8c5c to your computer and use it in GitHub Desktop.
Temporary fixes slash issue on GitLab's WebIDE
// ==UserScript==
// @name Fix GitLab's WebIDE slash issue
// @version 0.1
// @author ajhsu
// @match https://gitlab.yourdomain.com/-/ide/project/*
// ==/UserScript==
/**
* Attach event handler for history.pushState
*/
(function(history) {
const pushState = history.pushState;
history.pushState = function(state) {
const res = pushState.apply(history, arguments);
if (typeof history.onpushstate == "function") {
history.onpushstate({
state: state
});
}
return res;
};
})(window.history);
/**
* Main
*/
(function() {
const encodedSlash = encodeURIComponent("/");
const branchPrefixes = ["feature/", "hotfix/", "release/", "support/"];
function checkForRedirection() {
branchPrefixes
.filter(function(prefix) {
return window.location.href.indexOf("blob/" + prefix) !== -1;
})
.forEach(function(prefix) {
window.location = window.location.href.replace(
prefix,
prefix.replace("/", encodedSlash)
);
});
}
checkForRedirection();
history.onpushstate = function() {
checkForRedirection();
};
})();
@ajhsu
Copy link
Copy Markdown
Author

ajhsu commented Jun 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment