Created
August 15, 2018 15:00
-
-
Save jamiekrug/a0c86e84cb15904207ac3c72e20fe35c to your computer and use it in GitHub Desktop.
YouTrack Page Title Rearranger for Tampermonkey : Swap the order of the issue summary and ID in page title, so ID is first (e.g., "Do Foo : FOO-123" --> "FOO-123 : Do Foo")
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 YouTrack Page Title Rearranger for Tampermonkey | |
| // @namespace YouTrackPageTitleRearranger | |
| // @version 0.2 | |
| // @description Swap the order of the issue summary and ID in page title, so ID is first (e.g., "Do Foo : FOO-123" --> "FOO-123 : Do Foo") | |
| // @author brianhegeman, jamiekrug | |
| // @match https://*.myjetbrains.com/youtrack/issue/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| var weInitiatedChange = false; | |
| var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | |
| var mutationObserver = new MutationObserver( titleChangeDetector ); | |
| mutationObserver.observe( document, { childList: true, characterData: true, subtree: true } ); | |
| function titleChangeDetector( mutationRecords ){ | |
| mutationRecords.forEach ( function (mutation) { | |
| if( mutation.type == "childList" && mutation.target.nodeName == "TITLE" ) { | |
| titleChangeHandler (); | |
| } | |
| } ); | |
| } | |
| function titleChangeHandler() { | |
| // Show browser console "verbose" level to see this debug logging. | |
| if( typeof console.debug === "function" ) { | |
| console.debug( "titleChangeHandler", "weInitiatedChange:", weInitiatedChange, "title:", document.title ); | |
| } | |
| // Avoid an infinite loop when this script is what's changing the title | |
| if( weInitiatedChange ) { | |
| weInitiatedChange = false; | |
| //-- No further action needed | |
| } else { | |
| weInitiatedChange = true; | |
| updateTitle(); | |
| } | |
| } | |
| function updateTitle() { | |
| var matches = document.title.match( /(.+)( : )([A-Z]+-[\d]+)$/ ); | |
| if( matches != null ) { | |
| // Swap the order of the issue summary and ID, so ID is first | |
| document.title = matches[3] + matches[2] + matches[1]; | |
| } | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment