-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
executable file
·648 lines (569 loc) · 19.9 KB
/
init.js
File metadata and controls
executable file
·648 lines (569 loc) · 19.9 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/**
* ruTorrent hide-dotpaths Plugin
* Copyright (C) 2025 JMSolo (QuickBox.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Hides dot-prefixed files and directories from all ruTorrent path dropdowns
*
* @author JMSolo
* @version 2.5.210
*/
// Plugin initialization
plugin = new rPlugin("hide-dotpaths");
// Plugin metadata
plugin.author = "JMSolo";
plugin.descr =
"Hide dot-prefixed files and directories from all ruTorrent path dropdowns";
plugin.version = "2.5.210";
// Simple configuration
let config = {
filterSelects: true,
filterModals: true,
filterAutocomplete: true,
filterAjax: true,
filterFilemanager: true,
preserveParentDirs: true,
debugMode: false,
applyFilemanagerPatch: true, // Option to apply server-side patch
};
// Advanced debug logging function with intelligent deduplication
function debugLog(messageKey, ...args) {
// Check if config exists first
if (typeof config === "undefined") return;
// Use advanced debug system if available
if (config.debugMode && window.hideDotpathsAdvancedDebug) {
window.hideDotpathsAdvancedDebug.log(messageKey, ...args);
} else if (config.debugMode && window.hideDotpathsDebugCache) {
// Fallback to legacy cache system
window.hideDotpathsDebugCache.smartDebugLog(messageKey, ...args);
} else if (config.debugMode) {
// Final fallback - use a simple logging mechanism
const message = theUILang[messageKey] || messageKey;
const formattedMessage =
args.length > 0 ? message + args.join("") : message;
// Use a simple logging function to avoid circular dependency
if (typeof window.hideDotpathsSimpleLog === "undefined") {
window.hideDotpathsSimpleLog = function (msg) {
// Only log if debug mode is enabled and we haven't logged this recently
const now = Date.now();
if (
!window.hideDotpathsSimpleLog.lastLog ||
now - window.hideDotpathsSimpleLog.lastLog > 1000
) {
console.debug("[hide-dotpaths]", msg);
window.hideDotpathsSimpleLog.lastLog = now;
}
};
}
window.hideDotpathsSimpleLog(formattedMessage);
}
// No diagnostic logging here - it creates spam
}
// NEW: Apply filemanager patch programmatically
function applyFilemanagerPatch() {
debugLog("hide-dotpaths-debug-applying-filemanager-patch");
// Override filemanager settings to force hide hidden files
if (window.flm?.settings) {
window.flm.settings.getSettingValue = function (name) {
if (name === "showhidden") {
debugLog("hide-dotpaths-debug-patch-intercepting-showhidden");
return false; // Force disable show hidden files
}
// Use the same logic as the actual patch
return $type(theWebUI.settings["webui.flm.settings." + name])
? theWebUI.settings["webui.flm.settings." + name]
: this.defaults[name];
};
debugLog("hide-dotpaths-debug-filemanager-patch-applied");
}
// Replace checkbox with hidden input
setTimeout(() => {
const showHiddenCheckbox = document.querySelector(
"#flm-settings-opt-showhidden"
);
if (showHiddenCheckbox && showHiddenCheckbox.type === "checkbox") {
// Create hidden input to replace checkbox
const hiddenInput = document.createElement("input");
hiddenInput.type = "hidden";
hiddenInput.name = "flm-settings-opt-showhidden";
hiddenInput.id = "flm-settings-opt-showhidden";
hiddenInput.value = "0";
// Replace the checkbox with hidden input
showHiddenCheckbox.parentNode.replaceChild(
hiddenInput,
showHiddenCheckbox
);
// Hide the label
const label = document.querySelector(
'label[for="flm-settings-opt-showhidden"]'
);
if (label) {
label.style.display = "none";
}
debugLog("hide-dotpaths-debug-checkbox-replaced-with-hidden-input");
}
}, 100);
}
// Core filtering function
function filterDotItems() {
let count = 0;
// Target ALL elements that might contain dot-prefixed paths
$(".rmenuitem, .browse-item, li, option").each(function () {
const text = $(this).text().trim();
if (!text) return;
// Get the last part of the path
const last = text.endsWith("/")
? text.slice(0, -1).split("/").pop()
: text.split("/").pop();
// Filter if it starts with dot (but keep parent directory "..")
if (
last?.startsWith(".") &&
(config.preserveParentDirs ? last !== ".." : true)
) {
$(this).remove();
count++;
debugLog(
"hide-dotpaths-debug-filtered-item",
text,
" (last: ",
last,
")"
);
}
});
// Filter filemanager plugin table rows (if enabled)
if (config.filterFilemanager) {
$('#flm-browser-table tbody tr[id^="_flm_."]').each(function () {
const id = $(this).attr("id");
if (id) {
const name = id.replace("_flm_", "").replace("/", "");
if (
name.startsWith(".") &&
(config.preserveParentDirs ? name !== ".." : true)
) {
$(this).remove();
count++;
debugLog("hide-dotpaths-debug-filtered-filemanager", name);
}
}
});
}
if (count > 0) {
debugLog(
"hide-dotpaths-debug-filtered-count",
count,
theUILang["hide-dotpaths-debug-dot-prefixed-items"]
);
}
return count;
}
// Ultra-fast filtering for immediate response
function instantFilter() {
$(".rmenuitem").each(function () {
const text = $(this).text().trim();
if (!text) return;
const last = text.endsWith("/")
? text.slice(0, -1).split("/").pop()
: text.split("/").pop();
if (
last?.startsWith(".") &&
(config.preserveParentDirs ? last !== ".." : true)
) {
$(this).remove(); // Remove immediately, no hide/show cycle
debugLog("hide-dotpaths-debug-instant-filtered", text);
} else {
// Mark as filtered (visible) if it's not a dot-prefixed item
$(this).addClass("filtered");
}
});
// Instant filter filemanager rows (if enabled)
if (config.filterFilemanager) {
$('#flm-browser-table tbody tr[id^="_flm_."]').each(function () {
const id = $(this).attr("id");
if (id) {
const name = id.replace("_flm_", "").replace("/", "");
if (
name.startsWith(".") &&
(config.preserveParentDirs ? name !== ".." : true)
) {
$(this).remove();
debugLog("hide-dotpaths-debug-instant-filtered-filemanager", name);
}
}
});
}
}
// ULTRA-FAST MUTATION OBSERVER - Intercepts elements BEFORE they're visible
let observer = null;
// Helper function to check if element should be filtered
function shouldFilterElement(text) {
if (!text) return false;
const last = text.endsWith("/")
? text.slice(0, -1).split("/").pop()
: text.split("/").pop();
return (
last?.startsWith(".") && (config.preserveParentDirs ? last !== ".." : true)
);
}
// Ultra-fast filtering for immediate response
function filterRmenuitemElements(container) {
$(container)
.find(".rmenuitem")
.each(function () {
const text = $(this).text().trim();
if (shouldFilterElement(text)) {
$(this).remove();
debugLog("hide-dotpaths-debug-filtered-item", text);
}
});
}
// Helper function to handle individual nodes with ULTRA-FAST response
function handleAddedNode(node) {
if (node.nodeType !== 1) return; // Not an element node
// Handle rmenuitem elements - INSTANT removal
if (node.classList?.contains("rmenuitem")) {
const text = node.textContent.trim();
if (shouldFilterElement(text)) {
node.remove(); // Remove immediately before it's visible
debugLog("hide-dotpaths-debug-filtered-item", text);
} else {
// Ensure non-filtered items are immediately visible
node.classList.add("filtered");
}
return;
}
// Handle filemanager table rows - INSTANT removal
if (node.id?.startsWith("_flm_.")) {
const name = node.id.replace("_flm_", "").replace("/", "");
if (
name.startsWith(".") &&
(config.preserveParentDirs ? name !== ".." : true)
) {
node.remove(); // Remove immediately before it's visible
debugLog("hide-dotpaths-debug-filtered-filemanager", name);
}
return;
}
// Handle container elements with immediate filtering
if (
node.classList?.contains("browseFrame") ||
node.classList?.contains("rmenuobj")
) {
// Filter immediately, no delay
filterRmenuitemElements(node);
}
}
// Helper function to handle mutations with ULTRA-FAST response
function handleMutation(mutation) {
if (mutation.type !== "childList") return;
// Process each added node immediately
mutation.addedNodes.forEach(handleAddedNode);
}
function setupMutationObserver() {
observer = new MutationObserver(function (mutations) {
mutations.forEach(handleMutation);
});
observer.observe(document.body, {
childList: true,
subtree: true,
});
}
// Event listeners with ULTRA-FAST response - catch them before they're visible
function handleRmenuitemInsertion() {
// INSTANT removal for any new rmenuitem
if ($(this).hasClass("rmenuitem")) {
const text = $(this).text().trim();
if (text && shouldFilterElement(text)) {
$(this).remove(); // Remove immediately
debugLog("hide-dotpaths-debug-event-filtered-rmenuitem", text);
return; // Skip further processing
} else if (text) {
// Ensure non-filtered items (including ../) are immediately visible
$(this).addClass("filtered");
debugLog("hide-dotpaths-debug-event-visible-rmenuitem", text);
}
}
// Handle filemanager table rows (if enabled) - INSTANT removal
if (config.filterFilemanager && $(this).attr("id")?.startsWith("_flm_")) {
const id = $(this).attr("id");
const name = id.replace("_flm_", "").replace("/", "");
if (
name.startsWith(".") &&
(config.preserveParentDirs ? name !== ".." : true)
) {
$(this).remove(); // Remove immediately
debugLog("hide-dotpaths-debug-event-filtered-filemanager", name);
return; // Skip further processing
}
}
}
function handleSubtreeModification() {
// Ultra-fast filtering with immediate response
instantFilter();
// Also ensure all visible rmenuitem elements have the filtered class
$(".rmenuitem:not(.filtered)").each(function () {
const text = $(this).text().trim();
if (text && !shouldFilterElement(text)) {
$(this).addClass("filtered");
debugLog("hide-dotpaths-debug-subtree-visible-rmenuitem", text);
}
});
}
$(document).on(
"DOMNodeInserted",
".rmenuitem, .browseFrame, dialog, #flm-browser-table tbody tr",
handleRmenuitemInsertion
);
$(document).on(
"DOMSubtreeModified",
".rmenuobj, .browseFrame, #flm-browser-table",
handleSubtreeModification
);
// Periodic cleanup to catch any that slip through (less frequent to reduce spam)
setInterval(filterDotItems, 1000); // Every 1 second
// Plugin initialization
plugin.init = function () {
debugLog("hide-dotpaths-debug-plugin-init");
try {
plugin.loadLang();
// Add CSS to hide dot-prefixed elements immediately
const style = document.createElement("style");
style.textContent = `
/* Hide dot-prefixed elements immediately */
.rmenuitem { display: none; }
.rmenuitem.filtered { display: block; }
tr[id^="_flm_."] { display: none !important; }
`;
document.head.appendChild(style);
// Immediately make ../ elements visible
$(".rmenuitem").each(function () {
const text = $(this).text().trim();
if (text === "../" || text === "..") {
$(this).addClass("filtered");
debugLog("hide-dotpaths-debug-force-visible-parent", text);
} else if (text && !shouldFilterElement(text)) {
// Also make non-dot-prefixed items visible
$(this).addClass("filtered");
debugLog("hide-dotpaths-debug-force-visible-item", text);
}
});
// Set up a more aggressive observer for ../ elements
const parentObserver = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
mutation.addedNodes.forEach(function (node) {
if (node.nodeType === 1 && node.classList?.contains("rmenuitem")) {
const text = node.textContent.trim();
if (text === "../" || text === "..") {
node.classList.add("filtered");
debugLog("hide-dotpaths-debug-observer-visible-parent", text);
} else if (text && !shouldFilterElement(text)) {
// Also make non-dot-prefixed items visible
node.classList.add("filtered");
debugLog("hide-dotpaths-debug-observer-visible-item", text);
}
}
});
});
});
parentObserver.observe(document.body, {
childList: true,
subtree: true,
});
// Override jQuery's append/appendTo to process elements immediately
const originalAppend = $.fn.append;
$.fn.append = function () {
const result = originalAppend.apply(this, arguments);
// Process any rmenuitem elements immediately
$(this)
.find(".rmenuitem")
.each(function () {
const text = $(this).text().trim();
if (
text === "../" ||
text === ".." ||
(text && !shouldFilterElement(text))
) {
$(this).addClass("filtered");
}
});
return result;
};
// Also run a continuous check every 10ms to ensure elements are visible (ultra-fast)
setInterval(function () {
$(".rmenuitem:not(.filtered)").each(function () {
const text = $(this).text().trim();
if (text === "../" || text === "..") {
$(this).addClass("filtered");
debugLog("hide-dotpaths-debug-interval-visible-parent", text);
} else if (text && !shouldFilterElement(text)) {
// Also make non-dot-prefixed items visible
$(this).addClass("filtered");
debugLog("hide-dotpaths-debug-interval-visible-item", text);
}
});
}, 10);
// Load advanced debug utilities first (always load it)
$.getScript("plugins/hide-dotpaths/debug-utils.js", function () {
debugLog("hide-dotpaths-debug-advanced-utilities-loaded");
// Load legacy debug cache as fallback
$.getScript("plugins/hide-dotpaths/debug-cache.js", function () {
debugLog("hide-dotpaths-debug-legacy-cache-loaded");
// Load configuration
debugLog("hide-dotpaths-debug-loading-config");
$.getScript("plugins/hide-dotpaths/conf.php", function () {
debugLog("hide-dotpaths-debug-config-loaded", window.hide_dotpaths);
if (window.hide_dotpaths !== true) {
debugLog("hide-dotpaths-debug-plugin-disabled");
return;
}
// Update config with loaded values
if (window.hide_dotpaths_config) {
config = { ...config, ...window.hide_dotpaths_config };
// Make config available globally for debug system
window.hide_dotpaths_config = config;
debugLog("hide-dotpaths-debug-config-updated", config.debugMode);
// Configure advanced debug system
configureAdvancedDebug();
}
// Apply filemanager patch if enabled
if (config.applyFilemanagerPatch) {
applyFilemanagerPatch();
}
// Start filtering
instantFilter();
setTimeout(filterDotItems, 5);
plugin.markLoaded();
});
});
});
} catch (error) {
debugLog("hide-dotpaths-debug-plugin-error", error.message);
}
};
// Fallback initialization
setTimeout(function () {
if (plugin.enabled && !plugin.allStuffLoaded) {
debugLog("hide-dotpaths-debug-fallback-init");
plugin.init();
}
}, 1000);
// Manual test function (kept for debugging if needed)
window.testHideDotpaths = function () {
debugLog("hide-dotpaths-debug-manual-test-called");
const count = filterDotItems();
debugLog(
"hide-dotpaths-debug-manual-test-completed",
count,
theUILang["hide-dotpaths-debug-items"]
);
return count;
};
// Advanced debug test functions
window.testAdvancedDebug = function () {
if (!window.hideDotpathsAdvancedDebug) {
debugLog("hide-dotpaths-debug-advanced-system-unavailable");
return;
}
// Test deduplication
debugLog("hide-dotpaths-debug-testing-deduplication");
for (let i = 0; i < 5; i++) {
debugLog("hide-dotpaths-debug-test-duplicate", "iteration", i);
}
// Test rate limiting
debugLog("hide-dotpaths-debug-testing-rate-limiting");
for (let i = 0; i < 3; i++) {
debugLog("hide-dotpaths-debug-test-rate-limit", "test", i);
}
// Show stats
const stats = window.hideDotpathsAdvancedDebug.getStats();
debugLog("hide-dotpaths-debug-stats-display", stats);
return stats;
};
window.getDebugStats = function () {
if (window.hideDotpathsAdvancedDebug) {
return window.hideDotpathsAdvancedDebug.getStats();
}
return null;
};
window.clearDebugCache = function () {
if (window.hideDotpathsAdvancedDebug) {
window.hideDotpathsAdvancedDebug.clearCache();
debugLog("hide-dotpaths-debug-cache-cleared");
}
};
// Configure advanced debug system
function configureAdvancedDebug() {
if (window.hideDotpathsAdvancedDebug) {
debugLog("hide-dotpaths-debug-configuring-advanced-system");
// Set debug scopes
if (config.debugScopes) {
window.hideDotpathsAdvancedDebug.setScope(config.debugScopes);
debugLog("hide-dotpaths-debug-scopes-set", config.debugScopes);
}
// Set rate limit
if (config.debugRateLimit) {
window.hideDotpathsAdvancedDebug.setRateLimit(config.debugRateLimit);
debugLog("hide-dotpaths-debug-rate-limit-set", config.debugRateLimit);
}
// Set deduplication window
if (config.debugDeduplicationWindow) {
window.hideDotpathsAdvancedDebug.setDeduplicationWindow(
config.debugDeduplicationWindow
);
debugLog(
"hide-dotpaths-debug-deduplication-window-set",
config.debugDeduplicationWindow
);
}
// Enable internal debugging if configured
if (config.debugEnableInternal) {
window.hideDotpathsAdvancedDebug.enableInternalDebug(true);
debugLog("hide-dotpaths-debug-internal-debugging-enabled");
}
debugLog("hide-dotpaths-debug-advanced-config-applied");
// Test the debug system immediately
debugLog("hide-dotpaths-debug-testing-system");
debugLog(
"hide-dotpaths-debug-config-available",
!!window.hide_dotpaths_config
);
debugLog(
"hide-dotpaths-debug-test-configuration",
"config loaded successfully"
);
// Show initial stats
const stats = window.hideDotpathsAdvancedDebug.getStats();
debugLog("hide-dotpaths-debug-initial-stats", stats);
} else {
debugLog("hide-dotpaths-debug-advanced-system-unavailable-fallback");
}
}
// Simple test function for immediate testing
window.testDebugSystem = function () {
debugLog("hide-dotpaths-debug-testing-system");
// Test basic debug logging
debugLog("hide-dotpaths-debug-test-configuration", "manual test");
// Test advanced system if available
if (window.hideDotpathsAdvancedDebug) {
const stats = window.hideDotpathsAdvancedDebug.getStats();
debugLog("hide-dotpaths-debug-stats-display", stats);
// Test deduplication
for (let i = 0; i < 3; i++) {
debugLog("hide-dotpaths-debug-test-duplicate", "test", i);
}
} else {
debugLog("hide-dotpaths-debug-advanced-system-unavailable");
}
};