You can use the following scripts to get the title of the current list/library that the user is working on:
function getListName(){ SP.SOD.executeFunc("sp.js", "SP.ClientContext", function () { SP.SOD.executeFunc("sp.core.js", "SP.ListOperation.Selection", function () { var listId = SP.ListOperation.Selection.getSelectedList(); console.log(listId); if (typeof (listId) == "undefined" || listId == null || listId == "") { return; } var ctx = SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getById(listId); ctx.load(list); ctx.executeQueryAsync( Function.createDelegate(this, function (sender, args) { console.log("current list/library name: "+list.get_title()); alert(list.get_title()); }), Function.createDelegate(this, function (sender, args) { console.log(args.get_message()); }) ); }); }); }
Refer to: http://sadomovalex.blogspot.com/2016/08/get-title-of-current-list-in-sharepoint.html