Looks like that would override all the master page items. If you are OK with that, you can do it via the UI by selecting all the pages in the Pages panel and select override master page items from the Pages fly out menu.
Limiting the overrides to the auto page numbers could be scripted.
This would override master page text frames containing an auto number. Note that if the page number is not on its own layer its stacking order might change.
//an array ids for masterpage textframes containing auto page numbers
var nid = getPageNumberID("^#")
var p = app.documents[0].pages.everyItem().getElements();
var mpi;
for (var i = 0; i < p.length; i++){
mpi = p[i].masterPageItems;
for (var j = 0; j < mpi.length; j++){
if (mpi[j].constructor.name == "TextFrame" ) {
if (checkItem(nid, mpi[j].id)) {
mpi[j].override(p[i])
}
}
}
};
/**
* Gets the ID of the found text’s parent frame
* @ param text to search for
* @ return an array of text franme ids
*/
function getPageNumberID(fp){
app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
app.findChangeTextOptions.properties = {
includeMasterPages:true}
app.findTextPreferences.findWhat = fp;
var res = app.activeDocument.findText()
var ids=[]
for (var i = 0; i < res.length; i++){
ids.push(res[i].parentTextFrames[0].id)
};
return ids
}
/**
* Checks if an item is in an array
* @ param the array to check
* @ param the item to look for
* @ return true if the item is in the array
*
*/
function checkItem(a, obj) {
for (var i = 0; i < a.length; i++) {
if (a[i] === obj) {
return true;
}
}
return false;
}