Skip to content

Commit

Permalink
Facebook improvements (#515)
Browse files Browse the repository at this point in the history
* Fix issues with inserting templates in the Facebook single message box.
* Use the universal editor template insert method in the Facebook plugin, to support textareas and other editors.
  • Loading branch information
ghinda committed Sep 25, 2023
1 parent 3048927 commit 411f706
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "briskine",
"version": "7.9.12",
"version": "7.9.13",
"description": "Write everything faster.",
"private": true,
"type": "module",
Expand Down
65 changes: 32 additions & 33 deletions src/content/plugins/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import parseTemplate from '../utils/parse-template.js'
import createContact from '../utils/create-contact.js'
import {insertPasteTemplate} from '../editors/editor-paste.js'
import {insertTemplate} from '../editors/editor-universal.js'
import {addAttachments} from '../attachments/attachments.js'

function getFromDetails () {
Expand All @@ -21,15 +21,15 @@ function getFromDetails () {
var fromName = ''
try {
var parsedUserObject = JSON.parse(`{${plainUserObject}}`)
fromName = parsedUserObject.NAME || '';
fromName = parsedUserObject.NAME || ''
} catch(err) {
// can't parse the user object
}

return createContact({
name: fromName,
email: ''
})
name: fromName,
email: ''
})
}

function getToDetails (editor) {
Expand Down Expand Up @@ -65,41 +65,40 @@ function getData (params) {
}
}

var activeCache = null;
let activeCache = null
function isActive () {
if (activeCache !== null) {
return activeCache;
}
if (activeCache !== null) {
return activeCache
}

activeCache = false;
var facebookUrl = '.facebook.com/';
var messengerUrl = '.messenger.com/';
activeCache = false
const urls = [
'.facebook.com/',
'.messenger.com/',
]

// trigger the extension based on url
if (
window.location.href.indexOf(facebookUrl) !== -1 ||
window.location.href.indexOf(messengerUrl) !== -1
) {
activeCache = true;
}
// trigger the extension based on url
if (urls.find((url) => window.location.href.includes(url))) {
activeCache = true
}

return activeCache;
return activeCache
}

export default async (params = {}) => {
if (!isActive()) {
return false;
}
if (!isActive()) {
return false
}

var data = getData(params);
const parsedTemplate = addAttachments(
await parseTemplate(params.quicktext.body, data),
params.quicktext.attachments,
)
var data = getData(params)
const parsedTemplate = addAttachments(
await parseTemplate(params.quicktext.body, data),
params.quicktext.attachments,
)

insertPasteTemplate(Object.assign({
text: parsedTemplate
}, params));
insertTemplate(Object.assign({
text: parsedTemplate
}, params))

return true;
};
return true
}

0 comments on commit 411f706

Please sign in to comment.