Skip to content

Instantly share code, notes, and snippets.

@lipkau
Last active July 9, 2020 03:05
Show Gist options
  • Save lipkau/481342249739847f2d7f8d3099783ce4 to your computer and use it in GitHub Desktop.
Save lipkau/481342249739847f2d7f8d3099783ce4 to your computer and use it in GitHub Desktop.
UserScript for Atlassian's Jira and Confluence
// ==UserScript==
// @name AtlassianTuner
// @description Custom javascript to inject onto Atlassian's Jira and Confluence to make experience better (at least for me)
// @namespace https://gist.github.com/lipkau/481342249739847f2d7f8d3099783ce4
// @author Oliver Lipkau
// @version 0.10.1
// @include https://*.bsh-sdd.com*
// @require https://code.jquery.com/jquery-2.2.4.min.js#sha256=BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=
// @require https://cdnjs.cloudflare.com/ajax/libs/anchor-js/3.2.2/anchor.min.js#sha256=WofcoLT8gToeaSmVRe28qpnlFxdBJH1n4K6Bk3YowvU=
// @run-at document-start
// @grant none
// @updateURL https://gist.github.com/lipkau/481342249739847f2d7f8d3099783ce4/raw/AtlassianTuner.user.js
// @downloadURL https://gist.github.com/lipkau/481342249739847f2d7f8d3099783ce4/raw/AtlassianTuner.user.js
// @supportURL https://gist.github.com/lipkau/481342249739847f2d7f8d3099783ce4
// ==/UserScript==
// Confluence has an old version of jQuery in AJS.$
// lets expose a newer version of jquery to global scope
var $, jQuery;
$ = jQuery = window.jQuery;
// ============================
$(() => {
/*
Atlassian has it's 'AUI' exposed. It contains some useful helper functions.
Documentation: https://docs.atlassian.com/aui/latest/docs/helper.html
Used here:
Triggers a resize event, which recalculates the heights of the elements:
AJS.$(window).resize();
Toggles the Confluence SideBar
AJS.Confluence.Sidebar.toggle();
Toggles the JIRA SideBar
AJS.sidebar(".aui-sidebar").toggle();
*/
// remove crap
// must be remove() and @run-at document-start
$('#footer').remove();
// add a "close" button to announcements
let closeButton = $('<span/>').html("x").css({
float: "right",
fontSize: "21px",
fontWeight: 700,
lineHeight: 1,
color: "#000",
textShadow: "0 1px 0 #fff",
filter: "alpha(opacity=20)",
opacity: 0.2,
WebkitAppearance: "none",
padding: 0,
cursor: "pointer",
background: "0 0",
border: 0,
position: "relative",
top: "-2px",
right: "-21px"
}).addClass("closeButton").on("click", function() {
$(this).parent().hide();
AJS.$(window).resize();
});
$('#header-precursor').find($('.aui-message')).prepend(closeButton);
// fix shortcut to hide sidebar
// '[' does not work when it requires a modifier
$('body').keypress(function(e) {
if (e.which == 91) { //91 == [
if (AJS !== undefined) {
if (AJS.Confluence !== undefined) {
if (AJS.Confluence.Sidebar.toggle !== undefined) {
AJS.Confluence.Sidebar.toggle();
} else {
// a theme might break SideBar.toggle()
// in this case, we simulate a click on the button:
// <div id="splitter-button">
$("#splitter-button").click();
}
} else if (AJS.sidebar !== undefined) {
AJS.sidebar(".aui-sidebar").toggle();
}
}
}
});
// add an anchor link icon
// https://github.com/bryanbraun/anchorjs
anchors.add();
// fix page action bar on confluence
$('#navigation').each(function() {
$('<div/>').css({
height: $(this).outerHeight(),
width: $(this).outerWidth(),
float: 'right',
lineHeight: 1.5,
position: 'relative'
}).prependTo('#main-header');
}).css({
position: 'fixed',
//top: shall not be set
margin: 0,
padding: 5,
border: '1px solid #ccc',
borderTopWidth: 0,
borderRightWidth: 0,
borderBottomLeftRadius: 3,
right: $(window).width() - $('#main').offset().left - $('#main').outerWidth(),
backgroundColor: $('#main').css('backgroundColor'),
zIndex: 1
});
if ($('#splitter-content').length) {
$('#splitter-content').scroll(function() {
$('#navigation').css({
top: $(this).scrollTop() < $('#main').offset().top ? $('#main').offset().top : $('#header').outerHeight() + $('#header-precursor').outerHeight()
});
});
} else {
$(window).scroll(function() {
$('#navigation').css({
top: $(this).scrollTop() < $('#main').offset().top ? $('#main').offset().top : $('#header').outerHeight()
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment