Action
Add Lines
UPDATES
22 days ago
This script is used to accumulate the numerical rows in the draft to obtain the result and insert it into the bottom row. At the same time, insert the symbol “—” to divide the rows that need to be accumulated into blocks. The accumulation between different blocks does not affect each other. Multiplication using “x” is supported inline.
23
98
12
result: 133
12x2
87
90x4x98
result: 35391
12
87
76
87
🥸
12
result: 274
Steps
-
script
let content = draft.content; let lines = content.split("\n"); let startLine = 0; for (let i = 0; i < lines.length; i++) { if (lines[i].indexOf("---") != -1) { startLine = i; } } lines = lines.slice(startLine); console.log(lines); const mathLine = (lines) => { let sum = 0; for (let line of lines) { let lineNum = 0; if (line.indexOf('x') != -1) { let sumNum = 1; const nums = line.split("x"); for (let numTmp of nums) { const numTmpNumber = Number(numTmp.trim()); if (isNaN(numTmpNumber)) { sumNum = 0; break; } else { sumNum *= numTmpNumber; } } lineNum = sumNum; } else { const numTmp = Number(line.trim()); if (!isNaN(numTmp)) { lineNum = numTmp; } } sum += lineNum; } return sum; }; const result = mathLine(lines); if (result != 0) { content = content + "\n" + "result: " + result + "\n" + "---"+"\n"; draft.content = content; }
Options
-
After Success Default Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.