Skip to content

Commit

Permalink
feat: add clean alignment and color for all blockquote #154
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Aug 2, 2024
1 parent dfb3e53 commit e666bfe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
24 changes: 17 additions & 7 deletions modules/compose.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const positionBeforeBegin = 'beforebegin';
const positionAfterBegin = 'afterbegin';
const fwdHdrLookupString = '-------- ';
const plainTextFirstChars = '> ';
const cleanBlockQuoteStyle = 'border:none !important; padding-left:0px !important; margin-left:0px !important;';

export async function process(tab) {
rwhLogger.debug(`tab.id=${tab.id}, tab.type=${tab.type}, tab.mailTab=${tab.mailTab}`);
Expand Down Expand Up @@ -176,19 +177,24 @@ class ReplyWithHeader {
// put back the cleaned up <br> tags as-is
if (this.isReply) {
div.insertAdjacentElement(positionAfterBegin, this._createElement('br'));

// blockquote
if (await rwhSettings.isCleanAllBlockQuoteColor()) { // all
let bqs = this._getAllByTagName('blockquote');
for (let b of bqs) {
b.setAttribute('style', cleanBlockQuoteStyle);
}
} else if (await rwhSettings.isCleanBlockQuoteColor()) { // first level
let bq = this._getByTagName('blockquote');
bq.setAttribute('style', cleanBlockQuoteStyle);
}
}
if (this.isForward) {
let mozForwardContainer = this._getByClassName('moz-forward-container');
this._cleanNodesUpToClassName(mozForwardContainer, targetNodeClassName);
mozForwardContainer.insertAdjacentElement(positionAfterBegin, this._createElement('br'));
}

// blockquote
if (await rwhSettings.isCleanBlockQuoteColor() && this.isReply) {
let bq = this._getByTagName('blockquote');
bq.setAttribute('style', 'border:none !important;padding-left:0 !important;');
}

return {
body: new XMLSerializer().serializeToString(this.#document),
}
Expand Down Expand Up @@ -410,7 +416,11 @@ class ReplyWithHeader {
}

_getByTagName(tagName) {
return this.#document?.getElementsByTagName(tagName)?.[0];
return this._getAllByTagName(tagName)?.[0];
}

_getAllByTagName(tagName) {
return this.#document?.getElementsByTagName(tagName);
}

_createElement(tagName) {
Expand Down
6 changes: 6 additions & 0 deletions modules/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ let keyHeaderHtmlPrefixLine = 'header.html.prefix.line';
let keyHeaderHtmlPrefixLineColor = 'header.html.prefix.line.color';
let keyTransSubjectPrefix = 'trans.subject.prefix';
let keyCleanBlockQuoteColor = 'clean.blockquote.color';
let keyCleanAllBlockQuoteColor = 'clean.blockquote.all.color';
let keyCleanQuoteCharGreaterThan = 'clean.quote.char.greaterthan';

let rwhDefaultSettings = {
Expand All @@ -63,6 +64,7 @@ let rwhDefaultSettings = {
[keyHeaderTimeZone]: true,

[keyCleanBlockQuoteColor]: true,
[keyCleanAllBlockQuoteColor]: false,
[keyCleanQuoteCharGreaterThan]: true,
}

Expand Down Expand Up @@ -157,6 +159,10 @@ export async function isCleanBlockQuoteColor() {
return await get(keyCleanBlockQuoteColor, rwhDefaultSettings[keyCleanBlockQuoteColor]);
}

export async function isCleanAllBlockQuoteColor() {
return await get(keyCleanAllBlockQuoteColor, rwhDefaultSettings[keyCleanAllBlockQuoteColor]);
}

export async function isCleanQuoteCharGreaterThan() {
return await get(keyCleanQuoteCharGreaterThan, rwhDefaultSettings[keyCleanQuoteCharGreaterThan]);
}
8 changes: 7 additions & 1 deletion options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@
<div class="hbox">
<label>
<input type="checkbox" id="cleanBlockQuoteColor" data-preference="clean.blockquote.color" />
Cleanup first level blockquote color
Cleanup first level blockquote alignment and color
</label>
</div>
<div class="hbox" style="padding-left: 25px;">
<label>
<input type="checkbox" id="cleanAllBlockQuoteColor" data-preference="clean.blockquote.all.color" />
Cleanup all level blockquote alignment and color
</label>
</div>
<div class="hbox">
Expand Down

0 comments on commit e666bfe

Please sign in to comment.