|
38 | 38 | */
|
39 | 39 | let isOldReddit = false;
|
40 | 40 |
|
| 41 | + /** |
| 42 | + * Whether or not we are on compact mode. |
| 43 | + * This will be set in the "load" event listener. |
| 44 | + * @type {boolean} |
| 45 | + */ |
| 46 | + let isCompact = false; |
| 47 | + |
41 | 48 | /**
|
42 | 49 | * Timeout to check for new edited comments on page.
|
43 | 50 | * This will be updated when scrolling.
|
|
170 | 177 | }
|
171 | 178 | }
|
172 | 179 | // old reddit
|
173 |
| - else { |
| 180 | + else if (!isCompact) { |
174 | 181 | // old reddit comment
|
175 | 182 | postId = innerEl?.closest(".thing")?.id.replace("thing_", "");
|
176 | 183 | // old reddit submission
|
|
198 | 205 | postId = "";
|
199 | 206 | }
|
200 | 207 | }
|
| 208 | + // compact |
| 209 | + else { |
| 210 | + const thing = innerEl?.closest(".thing"); |
| 211 | + if (thing) { |
| 212 | + const idClass = [...thing.classList].find((c) => c.startsWith("id-")); |
| 213 | + postId = idClass ? idClass.replace("id-", "") : ""; |
| 214 | + } |
| 215 | + // if not found, check the url |
| 216 | + if (!postId) { |
| 217 | + const parsedURL = parseURL(); |
| 218 | + postId = parsedURL.commentId || parsedURL.submissionId || postId; |
| 219 | + } |
| 220 | + } |
201 | 221 | // if the post appears on the page after the last 3 characters are removed, remove them
|
202 | 222 | const reMatch = postId.match(/(t1_\w+)\w{3}/) || postId.match(/(t3_\w+)\w{3}/);
|
203 | 223 | if (reMatch && document.querySelector(`.${reMatch[1]}, #thing_${reMatch[1]}`)) {
|
|
248 | 268 | }
|
249 | 269 | }
|
250 | 270 | // old reddit
|
251 |
| - else { |
| 271 | + else if (!isCompact) { |
252 | 272 | // old reddit comments
|
253 | 273 | baseEl = document.querySelector(`form[id*='${postId}'] .md`);
|
254 | 274 | if (baseEl?.closest(".entry")) {
|
|
271 | 291 | bodyEl = document.querySelector(`.id-${postId}`);
|
272 | 292 | }
|
273 | 293 | }
|
| 294 | + // compact view |
| 295 | + else { |
| 296 | + bodyEl = document.querySelector(`.id-${postId} .md, .id-${postId} form.usertext`); |
| 297 | + // if not found, check for the .usertext element containing it as part of its id |
| 298 | + if (!bodyEl) { |
| 299 | + bodyEl = document.querySelector(".showOriginal")?.parentElement; |
| 300 | + } |
| 301 | + } |
274 | 302 | return bodyEl;
|
275 | 303 | }
|
276 | 304 |
|
|
285 | 313 | "div[data-url]", // old reddit on submission page
|
286 | 314 | ".Post", // redesign
|
287 | 315 | ];
|
| 316 | + // class list of .thing contains id-t3_... |
| 317 | + const thing = innerEl?.closest(".thing"); |
| 318 | + if (thing) { |
| 319 | + const idClass = [...thing.classList].find((c) => c.startsWith("id-")); |
| 320 | + if (idClass) { |
| 321 | + return idClass.startsWith("id-t3_"); |
| 322 | + } |
| 323 | + } |
288 | 324 | return Boolean(innerEl.closest(selectors.join(", ")));
|
289 | 325 | }
|
290 | 326 |
|
|
434 | 470 | const postId = getPostId(showLinkEl);
|
435 | 471 | showLinkEl.alt = `View original post for ID ${postId}`;
|
436 | 472 | if (!postId) {
|
437 |
| - showLinkEl.style.color = "#dd2c00"; |
| 473 | + showLinkEl.parentElement.removeChild(showLinkEl); |
438 | 474 | }
|
439 | 475 | // click event
|
440 | 476 | showLinkEl.addEventListener(
|
|
679 | 715 | checkForEditedSubmissions();
|
680 | 716 | }
|
681 | 717 | }
|
682 |
| - // old Reddit |
| 718 | + // old Reddit and compact Reddit |
683 | 719 | else {
|
684 | 720 | selectors = [
|
685 | 721 | ".entry p.tagline time:not(.found)", // Comment or Submission "last edited" timestamp
|
686 |
| - ".entry p.tagline em:not(.found), .entry p.tagline span:first-of-type:not(.found)", // Comment "[deleted]" author |
| 722 | + ".entry p.tagline em:not(.found), .entry .tagline span:first-of-type:not(.found)", // Comment "[deleted]" author |
687 | 723 | "div[data-url] p.tagline span:first-of-type:not(.found)", // Submission "[deleted]" author
|
688 |
| - "div[data-url] .usertext-body em:not(.found)", // Submission "[removed]" body |
| 724 | + "div[data-url] .usertext-body em:not(.found), form.usertext em:not(.found)", // Submission "[removed]" body |
689 | 725 | ".entry .usertext .usertext-body > div.md > p:only-child:not(.found)", // Comment "[unavailable]" body
|
690 | 726 | "p#noresults", // "there doesn't seem to be anything here" page
|
691 | 727 | ];
|
|
796 | 832 | function init() {
|
797 | 833 | // determine if reddit is old or redesign
|
798 | 834 | isOldReddit = /old\.reddit/.test(window.location.href) || !!document.querySelector("#header-img");
|
| 835 | + isCompact = document.querySelector("#header-img-a")?.href?.endsWith(".compact") || false; |
799 | 836 | // Reddit redesign
|
800 | 837 | if (!isOldReddit) {
|
801 | 838 | // fix styling of created paragraphs in new reddit
|
|
0 commit comments