google sheets – Button that creates a new line and copies functions / format

I'm trying to create a script in a button that, once pressed, will create a new line under the active cell and will copy all the formats and formulas of the selected line.

I could find a version of this issue that uses getLastRow. As a result, a line is added at the end of my worksheet instead of being below my active line.

I have tried the following which does not use the getLastRow function. I hope this clarifies my intention, but I do not know how to make it work properly.

function addRow () {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var sheet = ss.getSheets ()[0];
var range = ss.getActiveRange ();
var R = range.getRowIndex ();

sheet.insertRowsAfter (R, 1);
sheet.copyTo (sheet.insertRowsAfter (R, 1), {contentOnly: false});
}

Here is the other code that I found that only adds to the last line:

var ss = SpreadsheetApp.getActive ();

onOpen function () {
var menu = [{name:"Add New Last Row", functionName:"addRow"}];
ss.addMenu ("AM FUNCTIONS", menu);
}

function addRow () {
var sh = ss.getActiveSheet (), lRow = sh.getLastRow ();
var lCol = sh.getLastColumn (), range = sh.getRange (lRow, 1,1, lCol);
sh.insertRowsAfter (lRow, 1);
var formulas = range.getFormulas ();
var newRange = sh.getRange (lRow + 1,1,1, lCol);
newRange.setFormulas (formulas);
}