removed makeParagraphs, using an html string directly
This commit is contained in:
parent
0daeded711
commit
2e076d7b7b
1 changed files with 4 additions and 21 deletions
|
|
@ -16,24 +16,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Some methods are a modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js
|
|
||||||
|
|
||||||
const makeParagraphs = (text, func) => {
|
|
||||||
const chunks = text.split(/\n{2,}/);
|
|
||||||
if (chunks.length == 1) {
|
|
||||||
return func(document.createTextNode(text));
|
|
||||||
}
|
|
||||||
const paragraphs = chunks.map((t) => {
|
|
||||||
const p = document.createElement("p");
|
|
||||||
p.innerText = t;
|
|
||||||
return p;
|
|
||||||
});
|
|
||||||
for (let i = paragraphs.length - 1; i >= 0; i--) {
|
|
||||||
func(paragraphs[i]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(async (message) => {
|
browser.runtime.onMessage.addListener(async (message) => {
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
case "getSelectedText":
|
case "getSelectedText":
|
||||||
|
|
@ -50,9 +32,10 @@ switch (message.command) {
|
||||||
}
|
}
|
||||||
const r = sel.getRangeAt(0);
|
const r = sel.getRangeAt(0);
|
||||||
r.deleteContents();
|
r.deleteContents();
|
||||||
makeParagraphs(message.text, function (p) {
|
const parser = new DOMParser();
|
||||||
r.insertNode(p);
|
const doc = parser.parseFromString(message.text, 'text/html');
|
||||||
});
|
console.log(JSON.stringify(doc));
|
||||||
|
r.insertNode(doc.body);
|
||||||
browser.runtime.sendMessage({command: "compose_reloadBody", tabId: message.tabId});
|
browser.runtime.sendMessage({command: "compose_reloadBody", tabId: message.tabId});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue