|
2 | 2 | // @name /mjg/ Emote Replacer |
3 | 3 | // @namespace http://repo.riichi.moe/ |
4 | 4 | // @namespace http://repo.riichi.moe/ |
5 | | -// @version 1.3.11 |
6 | | -// @description Detects emote strings in imageless posts in /mjg/ threads, and displays them as fake images posts. |
| 5 | +// @version 1.3.12 |
| 6 | +// @description Detects emote strings in imageless posts in /mjg/ threads, and displays them as fake image posts. |
7 | 7 | // @icon https://files.catbox.moe/3sh459.png |
8 | 8 | // @author Ling and Anon |
9 | 9 | // @match *://boards.4chan.org/vg/thread/* |
|
16 | 16 | (function () { |
17 | 17 | 'use strict'; |
18 | 18 |
|
19 | | - const IMAGE_LIMIT = 0; // Change this to 375 if you want the script to only work after the thread has hit the image limit |
| 19 | + const IMAGE_LIMIT = 0; // Change this to 375 if you want the script to only work after the thread has hit the image limit. |
| 20 | + const MULTI_FILE_MODE = true; // Allow fake emotes to be shown alongside real images if an emote string was detected in a real image post. |
20 | 21 |
|
21 | 22 | // Sources for MJS and RC emotes |
22 | 23 | const EMOTE_BASE_URLS = [ |
|
103 | 104 | // Already processed, has file, no message, emote not found, or currently checking |
104 | 105 | if (currentState && currentState !== 'limit-not-reached') return; |
105 | 106 |
|
106 | | - // Check if it already has a *real* file attachment |
107 | | - if (postElement.querySelector('.file')) { postElement.setAttribute(PROCESSED_MARKER, 'has-file'); return; } |
| 107 | + // Check if it already has a *real* file attachment if multi file mode is disabled |
| 108 | + if (postElement.querySelector('.file') && !MULTI_FILE_MODE) { postElement.setAttribute(PROCESSED_MARKER, 'has-file'); return; } |
108 | 109 |
|
109 | 110 | // Check if image limit is reached *now* |
110 | 111 | const currentImageCount = getImageCount(); |
|
224 | 225 | console.warn("/mjg/ Emote Replacer: Could not get post ID for", postElement); |
225 | 226 | return; // Should not happen if called after check |
226 | 227 | } |
227 | | - // Double check file doesn't exist (in case of race condition) |
228 | | - if (postElement.querySelector('.file')) return; |
| 228 | + // Double check file doesn't exist (in case of race condition) in case multi file mode is disabled |
| 229 | + if (postElement.querySelector('.file') && !MULTI_FILE_MODE) return; |
229 | 230 |
|
230 | 231 | const uniqueFileId = `f${postId}-emote`; |
231 | 232 | const uniqueFileTextId = `fT${postId}-emote`; |
| 233 | + let existingFile = true; |
| 234 | + let fileDiv = postElement.querySelector('.file'); |
| 235 | + let fileTextSeparator = 'File: '; |
232 | 236 |
|
233 | | - const fileDiv = document.createElement('div'); |
234 | | - fileDiv.className = 'file'; |
235 | | - fileDiv.id = uniqueFileId; |
| 237 | + if (fileDiv) { |
| 238 | + existingFile = true; |
| 239 | + fileTextSeparator = ', '; |
| 240 | + } else { |
| 241 | + existingFile = false; |
| 242 | + fileDiv = document.createElement('div'); |
| 243 | + fileDiv.className = 'file'; |
| 244 | + fileDiv.id = uniqueFileId; |
| 245 | + } |
236 | 246 |
|
237 | 247 | const fileTextDiv = document.createElement('div'); |
238 | 248 | fileTextDiv.className = 'fileText'; |
239 | 249 | fileTextDiv.id = uniqueFileTextId; |
240 | 250 | fileTextDiv.innerHTML = ` |
241 | 251 | <span class="file-info"> |
242 | | - File: <a href="${fullImageUrl}" target="_blank">${emoteString}</a> (Emote) |
| 252 | + ${fileTextSeparator}<a href="${fullImageUrl}" target="_blank">${emoteString}</a> (Emote) |
243 | 253 | </span> |
244 | 254 | <span class="fileText-original" style="display: none;"> |
245 | | - File: <a href="${fullImageUrl}" target="_blank">${emoteString}</a> (Emote) |
| 255 | + ${fileTextSeparator}<a href="${fullImageUrl}" target="_blank">${emoteString}</a> (Emote) |
246 | 256 | </span>`; |
247 | 257 |
|
248 | 258 | const fileThumbLink = document.createElement('a'); |
|
274 | 284 | const insertionPoint = postInfoDesktop || postInfoMobile; |
275 | 285 | const blockquote = postElement.querySelector('blockquote.postMessage'); |
276 | 286 |
|
277 | | - if (insertionPoint && insertionPoint.nextSibling) { |
278 | | - postElement.insertBefore(fileDiv, insertionPoint.nextSibling); |
279 | | - } else if (blockquote) { |
280 | | - postElement.insertBefore(fileDiv, blockquote); |
281 | | - } else if (insertionPoint) { |
282 | | - insertionPoint.parentNode.appendChild(fileDiv); |
| 287 | + if (existingFile) { |
| 288 | + fileThumbLink.style.marginLeft = "-15px"; |
| 289 | + postElement.querySelector('.fileText').style.display = "flex"; |
| 290 | + postElement.querySelector('.fileText').appendChild(fileTextDiv); |
| 291 | + postElement.querySelector('.fileThumb').after(fileThumbLink); |
283 | 292 | } else { |
284 | | - postElement.appendChild(fileDiv); |
| 293 | + if (insertionPoint && insertionPoint.nextSibling) { |
| 294 | + postElement.insertBefore(fileDiv, insertionPoint.nextSibling); |
| 295 | + } else if (blockquote) { |
| 296 | + postElement.insertBefore(fileDiv, blockquote); |
| 297 | + } else if (insertionPoint) { |
| 298 | + insertionPoint.parentNode.appendChild(fileDiv); |
| 299 | + } else { |
| 300 | + postElement.appendChild(fileDiv); |
| 301 | + } |
285 | 302 | } |
286 | 303 | } |
287 | 304 |
|
|
0 commit comments