-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnativedb-clear-tab-names.user.js
61 lines (53 loc) · 1.93 KB
/
nativedb-clear-tab-names.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==UserScript==
// @name NativeDB Title Updater
// @namespace https://github.com/kraibse/nativedb-clear-tab-names
// @version 1.0
// @description Updates the browser tab title based on the page's NativeDB component title
// @author kraibse
// @match https://nativedb.red4ext.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Configuration
const titleSelector = '.title>h1';
const observerConfig = {
childList: true,
subtree: true,
characterData: true
};
// Function to update the document title
function updateTitle() {
const titleElement = document.querySelector(titleSelector);
if (titleElement) {
const newTitle = titleElement.textContent.trim();
if (newTitle && document.title !== newTitle) {
document.title = newTitle;
}
}
}
const observer = new MutationObserver((mutations) => {
const shouldUpdate = mutations.some(mutation => {
// Check if the mutation target is our title element or contains it
return mutation.target.matches?.(titleSelector) ||
mutation.target.querySelector?.(titleSelector) ||
[...(mutation.addedNodes || [])].some(node =>
node.matches?.(titleSelector) || node.querySelector?.(titleSelector)
);
});
if (shouldUpdate) {
updateTitle();
}
});
function initializeObserver() {
// First update the title immediately if the element exists
updateTitle();
// Then start observing for changes
observer.observe(document.body, observerConfig);
}
if (document.readyState === 'complete' || document.readyState === 'interactive') {
initializeObserver();
} else {
document.addEventListener('DOMContentLoaded', initializeObserver);
}
})();