Last active
June 1, 2018 07:46
-
-
Save ajhsu/fcd3d4c6d82092fae7e9d87a326e8c5c to your computer and use it in GitHub Desktop.
Temporary fixes slash issue on GitLab's WebIDE
This file contains hidden or 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 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(); | |
| }; | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/45878