mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
Removed Init Delay + use Undefined rather than Delete + Switched preventDefault() to not async + uses Traces + Removed polling
This commit is contained in:
@@ -13,16 +13,5 @@ export const settings = await ReactiveStore.getPluginStorage("ElementHider", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const Settings = () => {
|
export const Settings = () => {
|
||||||
const [hiddenElementsCount, setHiddenElementsCount] = React.useState(settings.hiddenElements.length);
|
|
||||||
|
|
||||||
// Update count when settings change
|
|
||||||
React.useEffect(() => {
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
setHiddenElementsCount(settings.hiddenElements.length);
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
@@ -90,7 +90,7 @@ function generateElementSelector(element: HTMLElement): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[Element Hider] Generated specific selector: ${selector}`);
|
trace.log(`Generated specific selector: ${selector}`);
|
||||||
return selector;
|
return selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,10 +112,10 @@ function saveHiddenElement(element: HTMLElement): void {
|
|||||||
|
|
||||||
if (existingIndex === -1) {
|
if (existingIndex === -1) {
|
||||||
settings.hiddenElements.push(elementInfo);
|
settings.hiddenElements.push(elementInfo);
|
||||||
console.log(`[Element Hider] Saved element: ${elementInfo.selector}`);
|
trace.log(`Saved element: ${elementInfo.selector}`);
|
||||||
console.log(`[Element Hider] Total stored: ${settings.hiddenElements.length}`);
|
trace.log(`Total stored: ${settings.hiddenElements.length}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`[Element Hider] Element already saved: ${elementInfo.selector}`);
|
trace.log(`Element already saved: ${elementInfo.selector}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,8 +126,8 @@ function removeSavedElement(element: HTMLElement): void {
|
|||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
settings.hiddenElements.splice(index, 1);
|
settings.hiddenElements.splice(index, 1);
|
||||||
console.log(`[Element Hider] Permanently removed: ${selector}`);
|
trace.log(`Permanently removed: ${selector}`);
|
||||||
console.log(`[Element Hider] Remaining stored: ${settings.hiddenElements.length}`);
|
trace.log(`Remaining stored: ${settings.hiddenElements.length}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ function matchesStoredSelector(element: HTMLElement): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`[Element Hider] Invalid selector: ${storedElement.selector}`, error);
|
trace.warn(`Invalid selector: ${storedElement.selector}`, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,14 +154,14 @@ function hideElementDirectly(element: HTMLElement): void {
|
|||||||
element.classList.add("element-hider-hidden");
|
element.classList.add("element-hider-hidden");
|
||||||
hiddenElements.add(element);
|
hiddenElements.add(element);
|
||||||
hiddenElementsArray.push(element);
|
hiddenElementsArray.push(element);
|
||||||
console.log(`[Element Hider] Hidden element: ${element.tagName}${element.className ? '.' + element.className.split(' ')[0] : ''}`);
|
trace.log(`Hidden element: ${element.tagName}${element.className ? '.' + element.className.split(' ')[0] : ''}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide the target element with animation
|
// Hide the target element with animation
|
||||||
function hideTargetElement(): void {
|
function hideTargetElement(): void {
|
||||||
if (!targetElement) return;
|
if (!targetElement) return;
|
||||||
|
|
||||||
console.log(`[Element Hider] Hiding with animation: ${targetElement.tagName}${targetElement.className ? '.' + targetElement.className.split(' ')[0] : ''}`);
|
trace.log(`Hiding with animation: ${targetElement.tagName}${targetElement.className ? '.' + targetElement.className.split(' ')[0] : ''}`);
|
||||||
|
|
||||||
// Add hiding animation class
|
// Add hiding animation class
|
||||||
targetElement.classList.add("element-hider-hiding");
|
targetElement.classList.add("element-hider-hiding");
|
||||||
@@ -186,7 +186,7 @@ function hideTargetElement(): void {
|
|||||||
|
|
||||||
// Unhide all elements permanently (remove from storage)
|
// Unhide all elements permanently (remove from storage)
|
||||||
function unhideAllElements(): void {
|
function unhideAllElements(): void {
|
||||||
console.log(`[Element Hider] Permanently unhiding ${settings.hiddenElements.length} saved elements`);
|
trace.log(`Permanently unhiding ${settings.hiddenElements.length} saved elements`);
|
||||||
|
|
||||||
// Show all currently hidden elements
|
// Show all currently hidden elements
|
||||||
hiddenElementsArray.forEach(element => {
|
hiddenElementsArray.forEach(element => {
|
||||||
@@ -205,19 +205,19 @@ function unhideAllElements(): void {
|
|||||||
function processAllElements(): void {
|
function processAllElements(): void {
|
||||||
if (settings.hiddenElements.length === 0) return;
|
if (settings.hiddenElements.length === 0) return;
|
||||||
|
|
||||||
console.log(`[Element Hider] Scanning document for ${settings.hiddenElements.length} stored selectors`);
|
trace.log(`Scanning document for ${settings.hiddenElements.length} stored selectors`);
|
||||||
let hiddenCount = 0;
|
let hiddenCount = 0;
|
||||||
|
|
||||||
// Use querySelectorAll for each stored selector with validation
|
// Use querySelectorAll for each stored selector with validation
|
||||||
settings.hiddenElements.forEach((storedElement, index) => {
|
settings.hiddenElements.forEach((storedElement, index) => {
|
||||||
try {
|
try {
|
||||||
console.log(`[Element Hider] Searching for: ${storedElement.selector}`);
|
trace.log(`Searching for: ${storedElement.selector}`);
|
||||||
const elements = document.querySelectorAll(storedElement.selector);
|
const elements = document.querySelectorAll(storedElement.selector);
|
||||||
console.log(`[Element Hider] Found ${elements.length} matches for selector ${index + 1}`);
|
trace.log(`Found ${elements.length} matches for selector ${index + 1}`);
|
||||||
|
|
||||||
// Limit to prevent over-hiding (safety check)
|
// Limit to prevent over-hiding (safety check)
|
||||||
if (elements.length > 10) {
|
if (elements.length > 10) {
|
||||||
console.warn(`[Element Hider] Selector too broad (${elements.length} matches), skipping: ${storedElement.selector}`);
|
trace.warn(`Selector too broad (${elements.length} matches), skipping: ${storedElement.selector}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,16 +226,16 @@ function processAllElements(): void {
|
|||||||
if (!hiddenElements.has(htmlElement)) {
|
if (!hiddenElements.has(htmlElement)) {
|
||||||
hideElementDirectly(htmlElement);
|
hideElementDirectly(htmlElement);
|
||||||
hiddenCount++;
|
hiddenCount++;
|
||||||
console.log(`[Element Hider] Hid element ${elemIndex + 1}/${elements.length} for selector ${index + 1}`);
|
trace.log(`Hid element ${elemIndex + 1}/${elements.length} for selector ${index + 1}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`[Element Hider] Invalid selector: ${storedElement.selector}`, error);
|
trace.warn(`Invalid selector: ${storedElement.selector}`, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hiddenCount > 0) {
|
if (hiddenCount > 0) {
|
||||||
console.log(`[Element Hider] Total elements hidden: ${hiddenCount}`);
|
trace.log(`Total elements hidden: ${hiddenCount}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,20 +278,20 @@ function setupElementObserver(): void {
|
|||||||
subtree: true
|
subtree: true
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`[Element Hider] Set up reactive element observer`);
|
trace.log(`Set up reactive element observer`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global functions
|
// Global functions
|
||||||
(window as any).showAllElementsFromSettings = unhideAllElements;
|
(window as any).showAllElementsFromSettings = unhideAllElements;
|
||||||
(window as any).debugElementHider = () => {
|
(window as any).debugElementHider = () => {
|
||||||
console.log(`=== Element Hider Debug Info ===`);
|
trace.log(`=== Element Hider Debug Info ===`);
|
||||||
console.log(`Stored elements: ${settings.hiddenElements.length}`);
|
trace.log(`Stored elements: ${settings.hiddenElements.length}`);
|
||||||
console.log(`Currently hidden elements: ${hiddenElementsArray.length}`);
|
trace.log(`Currently hidden elements: ${hiddenElementsArray.length}`);
|
||||||
console.log(`Reactive hiding enabled: true`);
|
trace.log(`Reactive hiding enabled: true`);
|
||||||
settings.hiddenElements.forEach((element, index) => {
|
settings.hiddenElements.forEach((element, index) => {
|
||||||
console.log(`${index + 1}. ${element.selector} (${element.tagName})`);
|
trace.log(`${index + 1}. ${element.selector} (${element.tagName})`);
|
||||||
});
|
});
|
||||||
console.log(`================================`);
|
trace.log(`================================`);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle highlighting target element
|
// Handle highlighting target element
|
||||||
@@ -346,11 +346,13 @@ document.addEventListener('contextmenu', (event: MouseEvent) => {
|
|||||||
const eventX = event.clientX;
|
const eventX = event.clientX;
|
||||||
const eventY = event.clientY;
|
const eventY = event.clientY;
|
||||||
|
|
||||||
|
// Prevent default immediately if we plan to handle it
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
// Wait to see if the built-in context menu appears
|
// Wait to see if the built-in context menu appears
|
||||||
contextMenuTimeout = window.setTimeout(() => {
|
contextMenuTimeout = window.setTimeout(() => {
|
||||||
// If we're still waiting and no built-in menu appeared, show our custom menu
|
// If we're still waiting and no built-in menu appeared, show our custom menu
|
||||||
if (waitingForBuiltInMenu && currentContextElement) {
|
if (waitingForBuiltInMenu && currentContextElement) {
|
||||||
event.preventDefault();
|
|
||||||
showCustomMenu(eventX, eventY);
|
showCustomMenu(eventX, eventY);
|
||||||
}
|
}
|
||||||
waitingForBuiltInMenu = false;
|
waitingForBuiltInMenu = false;
|
||||||
@@ -438,7 +440,7 @@ function showCustomMenu(x: number, y: number): void {
|
|||||||
customMenu.style.left = `${finalX}px`;
|
customMenu.style.left = `${finalX}px`;
|
||||||
customMenu.style.top = `${finalY}px`;
|
customMenu.style.top = `${finalY}px`;
|
||||||
|
|
||||||
console.log(`[Element Hider] Context menu opened for: ${currentContextElement?.tagName}`);
|
trace.log(`Context menu opened for: ${currentContextElement?.tagName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close custom context menu
|
// Close custom context menu
|
||||||
@@ -561,11 +563,10 @@ contextMenuObserver.observe(document.body, {
|
|||||||
|
|
||||||
// Initialize plugin
|
// Initialize plugin
|
||||||
function initializePlugin() {
|
function initializePlugin() {
|
||||||
console.log("[Element Hider] Initializing plugin...");
|
trace.log("Initializing plugin...");
|
||||||
|
|
||||||
// Wait for DOM to be ready
|
// Process immediately when DOM is ready
|
||||||
setTimeout(() => {
|
trace.log("Starting element processing...");
|
||||||
console.log("[Element Hider] Starting element processing...");
|
|
||||||
|
|
||||||
// Process existing elements
|
// Process existing elements
|
||||||
processAllElements();
|
processAllElements();
|
||||||
@@ -573,8 +574,7 @@ function initializePlugin() {
|
|||||||
// Set up reactive observer for new elements
|
// Set up reactive observer for new elements
|
||||||
setupElementObserver();
|
setupElementObserver();
|
||||||
|
|
||||||
console.log("[Element Hider] Plugin fully initialized");
|
trace.log("Plugin fully initialized");
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run initialization when DOM is ready
|
// Run initialization when DOM is ready
|
||||||
@@ -600,10 +600,10 @@ unloads.add(() => {
|
|||||||
removeHighlight();
|
removeHighlight();
|
||||||
|
|
||||||
// Clean up global functions
|
// Clean up global functions
|
||||||
delete (window as any).showAllElementsFromSettings;
|
(window as any).showAllElementsFromSettings = undefined;
|
||||||
delete (window as any).debugElementHider;
|
(window as any).debugElementHider = undefined;
|
||||||
|
|
||||||
console.log("[Element Hider] Plugin unloaded");
|
trace.log("Plugin unloaded");
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("[Element Hider] Plugin loaded - Right-click any element to hide it!");
|
trace.log("Plugin loaded - Right-click any element to hide it!");
|
||||||
Reference in New Issue
Block a user