Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge my personal messages #62

Closed
wants to merge 9 commits into from
25 changes: 20 additions & 5 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,30 @@ $("#copybutton").click(function () {

const message = dropdownMap.get(id);
let messageBody = getStringValue(message.message);

// Replace predefined variables in the message body
for (const variable in variables) {
for (const { project: expected, value } of variables[variable]) {
if (isExpectedProject(expected, project)) {
messageBody = messageBody.replace(new RegExp(`%${variable}%`, 'g'), getStringValue(value));
function resolveVariables(text, limit) {
var varExpanded = false;
for (var variable in variables) {
if (text.includes(variable)) {
for (const { project: expected, value } of variables[variable]) {
if (isExpectedProject(expected, project)) {
varExpanded = true;
text = text.replace(new RegExp(`%${variable}%`, 'g'), getStringValue(value));
}
}
}
}

if (varExpanded && limit > 0) {
return resolveVariables(text, limit - 1);
} else {
return text;
}
}
// TODO: Allow more than one variable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just a small note: the comment here is actually for the message.fillname part)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, whoops, i thought it was about what I implemented.
Anyway, if that's really needed, it should probably be an issue at this point, but I don't really see the need for multiple inputs as of right now.


messageBody = resolveVariables(messageBody, 10);

if (message.fillname.length >= 1) {
if (!$("#fill").val()) {
wiggle($("#fill"));
Expand Down
Loading