Skip to content

Commit 883b0b1

Browse files
authored
Add multi file mode (shows fake emotes alongside real images if detected)
1 parent c5ecd2b commit 883b0b1

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

others/userscripts/4chan/mjg Emote Replacer.user.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// @name /mjg/ Emote Replacer
33
// @namespace http://repo.riichi.moe/
44
// @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.
77
// @icon https://files.catbox.moe/3sh459.png
88
// @author Ling and Anon
99
// @match *://boards.4chan.org/vg/thread/*
@@ -16,7 +16,8 @@
1616
(function () {
1717
'use strict';
1818

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.
2021

2122
// Sources for MJS and RC emotes
2223
const EMOTE_BASE_URLS = [
@@ -103,8 +104,8 @@
103104
// Already processed, has file, no message, emote not found, or currently checking
104105
if (currentState && currentState !== 'limit-not-reached') return;
105106

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; }
108109

109110
// Check if image limit is reached *now*
110111
const currentImageCount = getImageCount();
@@ -224,25 +225,34 @@
224225
console.warn("/mjg/ Emote Replacer: Could not get post ID for", postElement);
225226
return; // Should not happen if called after check
226227
}
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;
229230

230231
const uniqueFileId = `f${postId}-emote`;
231232
const uniqueFileTextId = `fT${postId}-emote`;
233+
let existingFile = true;
234+
let fileDiv = postElement.querySelector('.file');
235+
let fileTextSeparator = 'File: ';
232236

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+
}
236246

237247
const fileTextDiv = document.createElement('div');
238248
fileTextDiv.className = 'fileText';
239249
fileTextDiv.id = uniqueFileTextId;
240250
fileTextDiv.innerHTML = `
241251
<span class="file-info">
242-
File: <a href="${fullImageUrl}" target="_blank">${emoteString}</a> (Emote)
252+
${fileTextSeparator}<a href="${fullImageUrl}" target="_blank">${emoteString}</a> (Emote)
243253
</span>
244254
<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)
246256
</span>`;
247257

248258
const fileThumbLink = document.createElement('a');
@@ -274,14 +284,21 @@
274284
const insertionPoint = postInfoDesktop || postInfoMobile;
275285
const blockquote = postElement.querySelector('blockquote.postMessage');
276286

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);
283292
} 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+
}
285302
}
286303
}
287304

0 commit comments

Comments
 (0)