FEMDOMCULT Thumbnail Viewer

Display torrent thumbnails directly in the browse page

Size

5.6 KB

Version

1.1.3

Created

Jan 17, 2026

Updated

about 2 months ago

1// ==UserScript==
2// @name		FEMDOMCULT Thumbnail Viewer
3// @description		Display torrent thumbnails directly in the browse page
4// @version		1.1.3
5// @match		https://*.femdomcult.org/*
6// @icon		https://femdomcult.org/favicon.ico?v=1755620483
7// ==/UserScript==
8(function() {
9    'use strict';
10
11    console.log('FEMDOMCULT Thumbnail Viewer: Starting...');
12
13    // Add custom styles for thumbnails
14    TM_addStyle(`
15        .thumbnail-container {
16            display: inline-block;
17            margin-right: 10px;
18            vertical-align: middle;
19        }
20        .thumbnail-container img {
21            max-width: 250px;
22            max-height: 250px;
23            border: 2px solid #444;
24            border-radius: 4px;
25            cursor: pointer;
26            transition: transform 0.2s, border-color 0.2s;
27        }
28        .thumbnail-container img:hover {
29            transform: scale(1.05);
30            border-color: #888;
31        }
32        .torrent-name-with-thumb {
33            display: flex;
34            align-items: center;
35            gap: 10px;
36        }
37    `);
38
39    function extractImageFromOverlay(scriptElement) {
40        if (!scriptElement) return null;
41        
42        const scriptContent = scriptElement.textContent;
43        // Extract image URL from the overlay variable - look for src=" or src=\"
44        const imgMatch = scriptContent.match(/src=\\"([^"]+)\\"/);
45        
46        if (imgMatch && imgMatch[1]) {
47            // Unescape the URL - handle both \/ and / patterns
48            return imgMatch[1].replace(/\\\//g, '/');
49        }
50        
51        return null;
52    }
53
54    function addThumbnails() {
55        console.log('FEMDOMCULT Thumbnail Viewer: Adding thumbnails...');
56        
57        const torrentRows = document.querySelectorAll('#torrent_table tr.torrent');
58        console.log(`Found ${torrentRows.length} torrent rows`);
59        
60        let thumbnailsAdded = 0;
61        
62        torrentRows.forEach((row, index) => {
63            // Check if thumbnail already added
64            if (row.querySelector('.thumbnail-container')) {
65                return;
66            }
67            
68            // Find the script element containing overlay data
69            const scriptElement = row.querySelector('script');
70            const imageUrl = extractImageFromOverlay(scriptElement);
71            
72            if (imageUrl) {
73                // Find the name cell (second td)
74                const nameCell = row.querySelector('td:nth-child(2)');
75                
76                if (nameCell) {
77                    // Create thumbnail container
78                    const thumbnailDiv = document.createElement('div');
79                    thumbnailDiv.className = 'thumbnail-container';
80                    
81                    const img = document.createElement('img');
82                    img.src = imageUrl;
83                    img.alt = 'Torrent thumbnail';
84                    img.loading = 'lazy';
85                    
86                    // Click to open full size in new tab
87                    img.addEventListener('click', (e) => {
88                        e.preventDefault();
89                        e.stopPropagation();
90                        GM.openInTab(imageUrl, false);
91                    });
92                    
93                    thumbnailDiv.appendChild(img);
94                    
95                    // Insert thumbnail at the beginning of the name cell
96                    nameCell.insertBefore(thumbnailDiv, nameCell.firstChild);
97                    thumbnailsAdded++;
98                    
99                    console.log(`Added thumbnail ${thumbnailsAdded}: ${imageUrl}`);
100                }
101            }
102        });
103        
104        console.log(`FEMDOMCULT Thumbnail Viewer: Added ${thumbnailsAdded} thumbnails`);
105    }
106
107    function init() {
108        // Check if we're on the torrents page
109        if (!window.location.href.includes('torrents.php')) {
110            console.log('FEMDOMCULT Thumbnail Viewer: Not on torrents page, skipping');
111            return;
112        }
113        
114        // Wait for the torrent table to be ready
115        TM_runBody(() => {
116            const torrentTable = document.querySelector('#torrent_table');
117            
118            if (torrentTable) {
119                console.log('FEMDOMCULT Thumbnail Viewer: Torrent table found');
120                addThumbnails();
121                
122                // Watch for dynamic content changes (pagination, filtering, etc.)
123                const observer = new MutationObserver((mutations) => {
124                    let shouldUpdate = false;
125                    
126                    mutations.forEach((mutation) => {
127                        if (mutation.addedNodes.length > 0) {
128                            mutation.addedNodes.forEach((node) => {
129                                if (node.nodeType === 1 && (node.matches('tr.torrent') || node.querySelector('tr.torrent'))) {
130                                    shouldUpdate = true;
131                                }
132                            });
133                        }
134                    });
135                    
136                    if (shouldUpdate) {
137                        console.log('FEMDOMCULT Thumbnail Viewer: New torrents detected, updating...');
138                        setTimeout(addThumbnails, 100);
139                    }
140                });
141                
142                observer.observe(torrentTable, {
143                    childList: true,
144                    subtree: true
145                });
146                
147                console.log('FEMDOMCULT Thumbnail Viewer: Observer set up');
148            } else {
149                console.log('FEMDOMCULT Thumbnail Viewer: Torrent table not found');
150            }
151        });
152    }
153
154    // Start the extension
155    init();
156})();