Skip to content

Instantly share code, notes, and snippets.

@gtors
Last active July 3, 2018 10:13
Show Gist options
  • Select an option

  • Save gtors/94981a616b46bb0738fcb6a9b81e68ea to your computer and use it in GitHub Desktop.

Select an option

Save gtors/94981a616b46bb0738fcb6a9b81e68ea to your computer and use it in GitHub Desktop.
GreaseMonkey script for YouTrack
// ==UserScript==
// @name Enhance YT
// @namespace youtrack
// @description Enhance YT
// @include https://.../youtrack/issue/*
// @version 1
// @run-at document-end
// @grant none
// ==/UserScript==
/**
* Remove comments until the date mapped via local storage to issue:
* localStorage.setItem('ISSUE-123', '15 Jul 2014 12:40')
*/
let removeComments = () => {
let issue = document.location.href.split('/').pop();
let deleteUntil = Date.parse(localStorage.getItem(issue));
if (deleteUntil != NaN) {
//$('.comment-row:has(.comment_deleted)').remove();
document.querySelectorAll('.comment-row').forEach((comment) => {
let dt = comment.querySelector('.comment-date');
let commentDate = Date.parse(dt.innerText);
if (commentDate < deleteUntil) {
comment.remove();
}
});
}
}
/**
* Converts all h4 headers to collapsible blocks.
*/
let convertHeadersToCollapsibleSections = () => {
document.querySelectorAll('.description_fsi>div>h4').forEach((h) => wrapCollapse(h, 'H4'));
}
let wrapCollapse = (header, headerTag) => {
let wrapper = document.createElement('div', {'class': 'wiki text prewrapped'});
wrapper.innerHTML = `
<span class="wiki-plus" onclick="WikiUtil.wikiCollapse(this)"></span>
<span class="wiki-cut-title"></span>
<span class="wiki-hellip">…</span>
<div class="wiki-hidden"></div>
`;
let wTitle = wrapper.querySelector('.wiki-cut-title');
wTitle.innerText = header.innerText;
let wContainer = wrapper.querySelector('.wiki-hidden');
wContainer.append(header.cloneNode(true));
allNextUntil(header, headerTag).forEach((el) => {
console.log(el.tagName);
el.remove();
wContainer.append(el);
});
header.replaceWith(wrapper);
}
let allNextUntil = (from, tagName) => {
let elements = [];
var el = from.nextElementSibling;
while (el != null && el.tagName != tagName) {
elements.push(el);
el = el.nextElementSibling;
}
return elements;
}
removeComments();
convertHeadersToCollapsibleSections();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment