NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Sfera tasks helper
// @namespace http://tampermonkey.net/
// @version 0.2
// @description
// @author anador
// @match https://sfera.inno.local/tasks/*
// @grant GM_addStyle
// @license MIT
// ==/UserScript==
// развернутое по умолчанию описание в задачах
GM_addStyle(`
div[data-testid=text-editor-attribute]>div>div>div {
height: 100% !important;
}
` );
// определяем выбранный таб на основе смещения вправо специального div, который подсвечивает активный таб
// такой костыль пришлось делать, потому что нет другого простого способа зацепиться за активный таб при разных расширениях экрана
function getTabNameByLabelTranslation(translation) {
translation = Number(translation);
if (translation === 0) return "Задачи";
else if (translation === 72) return "Бэклог";
else if (translation === 143) return "Доски";
else if (translation === 209) return "Структура задач";
else if (translation >= 300 && translation <= 350) return "Конструктор фильтров";
else if (translation >= 410 && translation <= 530) return "Учет рабочего времени";
else return "Задачи — Сфера";
}
// замена favicon
(function () {
let list = document.querySelectorAll('link[rel="icon"], link[rel="shortcut icon"]');
list.forEach(el => {
el.remove();
});
let link = document.createElement('link');
link.rel = 'icon';
link.href = 'https://sfera.inno.local/app/knowledge/api/page/v1/images/f2722ffe-b052-42ed-ae40-295d1398daaf';
document.head.appendChild(link);
})();
(function () {
observer = new MutationObserver(() => {
// если открыта таска, берем заголовок из номера + названия таски
if ((task = document.querySelector('div[data-testid="path-path-attribute"]')?.firstChild?.lastChild?.innerText) && (taskName = document.querySelector('input[data-testid="string-name-attribute"]')?.value)) {
// observer.disconnect();
document.title = `[${task}] ${taskName}`
}
else {
// костыль
if (activeTabLabel = document.querySelector('div[role="tablist"]')?.lastChild) {
translation = +window.getComputedStyle(activeTabLabel).transform.split(',')[4]
docTitle = getTabNameByLabelTranslation(translation);
if (docTitle === "Задачи — Сфера") {
document.title = `${docTitle}`;
}
else {
document.title = `${docTitle} — Задачи.Cфера`;
}
}
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
})
// открытие задач в новом окне
// monkey patch метода pushState
var pushState = history.pushState;
history.pushState = function () {
pushState.apply(history, arguments);
if (fullTaskName = arguments[2].match(/\?open=(\w+-\d+)/)) {
fullTaskName = fullTaskName[1]; // получить из всего матча нужную группу
[taskArea, taskNum] = fullTaskName.split('-');
window.open(`/tasks/area/${taskArea}/task/${fullTaskName}`, '_blank');
search = location.search;
queryParams = new URLSearchParams(search);
queryParams.delete('open');
history.pushState({}, '', `${location.pathname}?${queryParams}`);
}
else return false;
};
})();
// включение проверки правописания
(function () {
spellCheckObserver = new MutationObserver(() => {
if (!document.body) return false;
if (!document.querySelector('.mce-content-body')) return false;
document.body.spellcheck = true;
document.querySelector('.mce-content-body').spellcheck = true;
});
spellCheckObserver.observe(document.body, {
childList: true,
subtree: true,
})
})();