function onEdit(e)
{
const range = e.range,
ss = e.source,
sheet = ss.getActiveSheet(),
col = range.getColumn(),
row = range.getRow(),
bool = Boolean(range.getValue()),
boolTop = Boolean(sheet.getRange(row-1, col).getValue()),
boolBot = Boolean(sheet.getRange(row+1, col).getValue());
range.setBorder(bool||boolTop /*top*/, bool /*left*/, bool||boolBot /*bottom*/, bool /*right*/, false /*vertical*/, false /*horizontal*/, "black" /*default color*/, SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
if (!bool) /* range is empty */
range.setBorder(null /*top*/, true /*left*/, null /*bottom*/, null /*right*/, false /*vertical*/, false /*horizontal*/, "green" /*color*/, SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
range.setBorder(null /*top*/, null /*left*/, null /*bottom*/, true /*right*/, false /*vertical*/, false /*horizontal*/, "red" /*color*/, SpreadsheetApp.BorderStyle.SOLID_MEDIUM);
}