Skip to content

Commit

Permalink
port: Catch errors due to "Restricted" selection. ccd0#2905
Browse files Browse the repository at this point in the history
from 2a47dfd
  • Loading branch information
TuxedoTako committed Mar 5, 2023
1 parent a132751 commit 567417f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The 4chan XT project is a migration of 4chan X from coffeescript to TypeScript/J
- [x] c68a8afbdf30e3cbb35f0834b364f20600151adf Switch Google image search back to old version, thanks to https://boards.4channel.org/g/thread/91737566#p91789527
- [x] aef984da1a6af4d0003b51e7f03bce252ac71dff Remove empty space from ads if they don't load. https://kissu.moe/b/res/7155#11052
- [x] 19268975ea2d49a753624315b0928f27496aac02 Update Randomize Filename to match current 4chan format. https://boards.4channel.org/g/thread/91737566#p91784238
- [ ] 2a47dfd8ba724b17f5bc5f9214bea8ce8b469398 Catch errors due to "Restricted" selection. #2905
- [x] 2a47dfd8ba724b17f5bc5f9214bea8ce8b469398 Catch errors due to "Restricted" selection. #2905
- [ ] 27957c25af5d182adc38f1e67a098ab338631ccd Release 4chan X v1.14.22.2.
- [ ] eb25d6e797a1673fd7cddb257fce04055383ec9b Update chrome-webstore-upload.
- [ ] 14e67e9a958633e37b4e4a6293cfa3a921c1eab0 Release 4chan X v1.14.22.3.
Expand Down
74 changes: 38 additions & 36 deletions src/Posting/QR.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,44 +384,46 @@ var QR = {
postRange.selectNode(root);
let text = post.board.ID === g.BOARD.ID ? `>>${post}\n` : `>>>/${post.board}/${post}\n`;
for (let i = 0, end = sel.rangeCount, asc = 0 <= end; asc ? i < end : i > end; asc ? i++ : i--) {
var insideCode, node;
range = sel.getRangeAt(i);
// Trim range to be fully inside post
if (range.compareBoundaryPoints(Range.START_TO_START, postRange) < 0) {
range.setStartBefore(root);
}
if (range.compareBoundaryPoints(Range.END_TO_END, postRange) > 0) {
range.setEndAfter(root);
}
try {
var insideCode, node;
range = sel.getRangeAt(i);
// Trim range to be fully inside post
if (range.compareBoundaryPoints(Range.START_TO_START, postRange) < 0) {
range.setStartBefore(root);
}
if (range.compareBoundaryPoints(Range.END_TO_END, postRange) > 0) {
range.setEndAfter(root);
}

if (!range.toString().trim()) { continue; }
if (!range.toString().trim()) { continue; }

var frag = range.cloneContents();
var ancestor = range.commonAncestorContainer;
// Quoting the insides of a spoiler/code tag.
if ($.x('ancestor-or-self::*[self::s or contains(@class,"removed-spoiler")]', ancestor)) {
$.prepend(frag, $.tn('[spoiler]'));
$.add(frag, $.tn('[/spoiler]'));
}
if (insideCode = $.x('ancestor-or-self::pre[contains(@class,"prettyprint")]', ancestor)) {
$.prepend(frag, $.tn('[code]'));
$.add(frag, $.tn('[/code]'));
}
for (node of $$((insideCode ? 'br' : '.prettyprint br'), frag)) {
$.replace(node, $.tn('\n'));
}
for (node of $$('br', frag)) {
if (node !== frag.lastChild) { $.replace(node, $.tn('\n>')); }
}
g.SITE.insertTags?.(frag);
for (node of $$('.linkify[data-original]', frag)) {
$.replace(node, $.tn(node.dataset.original));
}
for (node of $$('.embedder', frag)) {
if (node.previousSibling?.nodeValue === ' ') { $.rm(node.previousSibling); }
$.rm(node);
}
text += `>${frag.textContent.trim()}\n`;
var frag = range.cloneContents();
var ancestor = range.commonAncestorContainer;
// Quoting the insides of a spoiler/code tag.
if ($.x('ancestor-or-self::*[self::s or contains(@class,"removed-spoiler")]', ancestor)) {
$.prepend(frag, $.tn('[spoiler]'));
$.add(frag, $.tn('[/spoiler]'));
}
if (insideCode = $.x('ancestor-or-self::pre[contains(@class,"prettyprint")]', ancestor)) {
$.prepend(frag, $.tn('[code]'));
$.add(frag, $.tn('[/code]'));
}
for (node of $$((insideCode ? 'br' : '.prettyprint br'), frag)) {
$.replace(node, $.tn('\n'));
}
for (node of $$('br', frag)) {
if (node !== frag.lastChild) { $.replace(node, $.tn('\n>')); }
}
g.SITE.insertTags?.(frag);
for (node of $$('.linkify[data-original]', frag)) {
$.replace(node, $.tn(node.dataset.original));
}
for (node of $$('.embedder', frag)) {
if (node.previousSibling?.nodeValue === ' ') { $.rm(node.previousSibling); }
$.rm(node);
}
text += `>${frag.textContent.trim()}\n`;
} catch (error) { }
}

QR.openPost();
Expand Down

0 comments on commit 567417f

Please sign in to comment.