This commit is contained in:
Slava Rogozhkin 2025-09-18 08:07:21 +03:00
parent 4b3439a757
commit f720a61a03
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
// ==UserScript==
// @name TabName_in_ZephyrPlayer
// @namespace Violentmonkey Scripts
// @match https://jira.slife.fun/secure/Tests.jspa*
// @grant none
// @version 1.0
// @author -
// @description 17.09.2025, 17:12:31
// ==/UserScript==
// Ожидание элемента -- искомый элемент находится в h2.title
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
// ждём и немного логируем
waitForElm("h2").then((elm) => {
console.log("Element is ready");
console.log(elm.title);
}, 1000);
// Включаем наблюдателя по доке MutationObserver
var mutationObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
// Получилась какая-то шляпа. Но иначе я не смог
if (mutation.type === 'attributes') {
const element = mutation.target;
const attributeName = mutation.attributeName;
const oldValue = mutation.oldValue;
const newValue = element.getAttribute(attributeName);
if (attributeName === 'title' && element.tagName === 'H2' ) {
document.title = newValue
}
}
});
});
// Наблюдаем за различными параметрами. Пытался определить какой именно нужный, чтобы меньше отслижвать - всё ломалось, поэтому отслеживаю всё.
mutationObserver.observe(document.documentElement, {
attributes: true,
characterData: true,
childList: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
});