User:Thundercraft5/moveSection.js

const titles = [ "Vanilla_Objects", ]; const section = 3; let { query: { pages } } = await new mw.Api.get({	action: "query",	format: "json",	prop: "revisions",	titles,	rvprop: "content",	rvslots: "*",	rvsection: section, }); let [{ revisions: [{ slots: { main: { "*": content }}}]}] = Object.values(pages); let sectionTitle = content.split('\n')[0] let title = sectionTitle.match(/^\s*(=+)\s*(.+?)\s*\1\s*$/)[2];

console.log(content); await new mw.Api.create(titles[0] + '/' + title, {}, content); await new mw.Api.edit(wgPageName, => ({ section, summary: `Moving Section "${title}" to page /${title}`, text: `${sectionTitle}\n`, nocreate: false }));