Skip to content

Instantly share code, notes, and snippets.

@w4-hojin
Last active May 18, 2018 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w4-hojin/3fb3606314bd2c7a50884ec61dab6d80 to your computer and use it in GitHub Desktop.
Save w4-hojin/3fb3606314bd2c7a50884ec61dab6d80 to your computer and use it in GitHub Desktop.
Youtrack Helper
// ==UserScript==
// @name Youtrack Helper
// @namespace https://kyte.today/
// @version 1.3.8
// @description Make useful links in youtrack.
// @author Hojin Lee <hojin@wisefour.com>
// @require https://code.jquery.com/jquery-1.12.4.min.js
// @require https://raw.githubusercontent.com/hazzik/livequery/master/dist/jquery.livequery.min.js
// @match https://youtrack.gabepos.com/*
// @grant none
// @updateUrl https://gist.githubusercontent.com/w4-hojin/3fb3606314bd2c7a50884ec61dab6d80/raw/Youtrack_Helper.user.js
// @downLoadUrl https://gist.githubusercontent.com/w4-hojin/3fb3606314bd2c7a50884ec61dab6d80/raw/Youtrack_Helper.user.js
// ==/UserScript==
window.jQ = $.noConflict(true);
(function($) {
'use strict';
var done = false;
function getIssue() {
let spilted_indexs = window.location.href.split(/[/#\?]/);
let issueIndex = spilted_indexs.lastIndexOf('issue') + 1;
if (issueIndex !== 0) {
return spilted_indexs[issueIndex];
}
return null;
}
function mainFunction() {
let toolbarElem = $('.toolbar_fsi');
if (toolbarElem.length === 0) {
return false;
}
let issue = getIssue();
let gitCommand = `git checkout -b '#${issue}' origin/master`;
let gitCommandElem = $('div#gitCommand');
if (gitCommandElem.length === 0) {
toolbarElem.append($(`<div id="gitCommand" style="color: lightgray;"></div>`));
gitCommandElem = $('div#gitCommand');
}
gitCommandElem.text(gitCommand);
return true;
}
function tryRun() {
setTimeout(function () {
if (done) {
return;
}
done = mainFunction();
if (!done) {
tryRun();
}
}, 500);
}
$(document).ready(function() {
done = false;
tryRun();
$(window).on('hashchange',function(){
done = false;
tryRun();
});
});
})(window.jQ);
(function($) {
'use strict';
let done = false;
function mainFunction() {
let zplElem = $('.wiki.text:contains(zpl://)').not('.zplLinked');
if (zplElem.length === 0) {
return true;
}
if (zplElem.text()) {
zplElem.addClass('zplLinked');
zplElem.html(function(index, html){
// return html.replace(/(zpl:\/\/[\w?&#=;]+)/g, '$1<a href="$1"><span class="sb-toolbar-ico sb-link-ico font-icon icon-link-2"></span></a>');
return html.replace(/(zpl:\/\/[\w?&#=;]+)/g, '<a href="$1">$1</a>');
});
return true;
} else {
return false;
}
}
function tryRun() {
setTimeout(function () {
if (done) {
return;
}
done = mainFunction();
if (!done) {
tryRun();
}
}, 500);
}
$(document).ready(function() {
done = false;
tryRun();
$(window).on('hashchange',function(){
done = false;
tryRun();
});
});
})(window.jQ);
(function($) {
'use strict';
var done = false;
function tryRun() {
console.log('Try to find gerrit change-id!');
setTimeout(function () {
if (done) {
return;
}
var gerritElem = $('.wiki.text:contains(Change-Id: )').filter(() => ($(this).children().length === 0) ).parent();
if (gerritElem.length === 0) {
return;
}
if (gerritElem.text()) {
done = true;
gerritElem.html(function(index, html){
return html.replace(/(Change-Id: (\w+))/g, '<a href="https://gerrit.wisefour.com/#/q/$2" target=_blank>$1</a>');
});
} else {
tryRun();
}
}, 500);
}
$(document).ready(function() {
done = false;
tryRun();
$(window).on('hashchange',function(){
done = false;
tryRun();
});
});
})(window.jQ);
// For popup
(function($) {
'use strict';
$(document).on( "click", ".yt-dialog-overlay" ,function() {
let zplElem = $('.wiki.text:contains(zpl://)').not('.zplLinked');
if (zplElem.length === 0) {
return true;
}
if (zplElem.text()) {
zplElem.addClass('zplLinked');
zplElem.html(function(index, html){
return html.replace(/(zpl:\/\/[\w?&#=;]+)/g, '<a href="$1">$1</a>');
});
return true;
} else {
return false;
}
});
$(document).ready(function() {
console.warn('ready');
$(window).on('hashchange',function(){
console.warn('hashchange');
});
$('.yt-dialog-overlay').livequery(function(){
console.warn('yt-dialog-overlay', $(this));
});
});
})(window.jQ);
(function($) {
'use strict';
function getIssue() {
// https://youtrack.gabepos.com/youtrack/agiles/110-20/114-79?tab=columns-and%20rows&issue=WT-2250
let spilted_indexs = window.location.href.split(/[/#\?\&=]/);
let issueIndex = spilted_indexs.lastIndexOf('issue') + 1;
if (issueIndex !== 0) {
return spilted_indexs[issueIndex];
}
return null;
}
$(document).on( "click", ".yt-dialog-overlay" ,function() {
let toolbarElem = $('.yt-issue-layout__wrapper');
if (toolbarElem.length === 0) {
return false;
}
let issue = getIssue();
let gitCommand = `git checkout -b '#${issue}' origin/master`;
let gitCommandElem = $('div#gitCommand');
if (gitCommandElem.length === 0) {
toolbarElem.prepend($(`<div id="gitCommand" style="color: lightgray;"></div>`));
gitCommandElem = $('div#gitCommand');
}
gitCommandElem.text(gitCommand);
return true;
});
})(window.jQ);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment