note: It would help anyone answering your question if you supplied an example of the usage of the set of custom macros, otherwise that person needs to determine for themselves the valid property definition of an inventory object. eg. That the object must have an ID, a NAME and a COUNT property.
So assuming the TwineScript is going to look something like the following:
<<set $apple to {id: "apple", name: "Apple", count: 2}>>
<<set $orange to {id: "orange", name: "Orange", count: 3}>>
<<set $pear to {id: "pear", name: "Pear", count: 1}>>
<<addToInv $apple>>
<<addToInv $orange>>
<<addToInv $pear>>
<<set $Inventory_Items to "Postit">>
<<listInv>>
Then replacing the listInv macro related Javascript code in your Story Javascript area with the following example should achieve what you want.
Macro.add('listInv', {
handler : function () {
/* Check that the required variable exists then retrieve it's value. */
var variable = 'Inventory_Items';
if (! state.variables.hasOwnProperty(variable)) {
return this.error(variable + ' variable not set');
}
var target = state.variables[variable];
var $list = $(document.createDocumentFragment());
if (State.variables.inventory.length === 0) {
$list.text('nothing');
}
else {
State.variables.inventory.forEach(function (item) {
$list
.wiki('[[' + item.name +
'|' + target + ']' +
'[$' + variable + ' to "' + item.name + '"]]')
.append('\u00A0\u00D7' + item.count)
.append('<br>');
});
}
$list.appendTo(this.output);
}
});
WARNING: You are using the $Inventory_Items story variable to represent two different things at the same time: the name of the Target Passage of the link; and the name of the Selected Inventory Item. Using a variable in this way is generally not a good idea because it can lead to confusion about what it's value is currently representing, It would make more sense to use two different named variables instead, each named based on it's purpose.
eg. like $InventoryTargetPassage and $SelectedInventoryItem or something similar that has meaning to you.