Access Pageitems from Pulic JS code

So i have lots of functions where i work with the items on my page. For example this little function:
const cH = “channelfield”;
export function setOutputs($w) {
$w(cH).src = “http://search.ai/” + appid + “/outputs”;
$w(cH).expand();
}

I would like to create a function like this so i can use it on multiple pages:
export function setOutputs(fieldid, appid) {
$w(fieldid).src = “http://search.ai/” + appid + “/outputs”;
$w(fieldid).expand();
}

How could i achieve this? I got lots of code ( like 5000 lines ) and it’s the same code on multiple pages… I wanted to refactor the methods so it would be more maintainable.