Skip to content

Page Citation

Page Citation turns the current page's collected metadata into a plain-text or Markdown reference. It is useful when a lookup leads to a fact or quotation you want to record with its source.

Page Citation showing plain-text and Markdown output for the Script guide

Setup

  1. Add or open a Script source in Definer Options.
  2. Replace the code in its editor with the script below.
  3. Run a lookup from a regular webpage.
  4. Select the output format and copy the rendered text normally.

Script

js
const title = definer.lookup.getVariable('page_title') || 'Untitled page'
const url = definer.lookup.getVariable('url') || 'URL unavailable'
const site = definer.lookup.getVariable('page_og_site_name')
const modified = definer.lookup.getVariable('page_last_modified')
const accessed = new Intl.DateTimeFormat('en', { dateStyle: 'medium' }).format(new Date())
const source = site ? `${title}. ${site}.` : `${title}.`
const detail = modified ? `Last modified ${modified}.` : `Accessed ${accessed}.`
const formats = {
	plain: `${source} ${detail} ${url}`,
	markdown: `[${title.replaceAll('[', '\\[').replaceAll(']', '\\]')}](${url})`,
}

definer.output.setHtml(`
	<section class="citation-builder">
		<div>
			<button type="button" data-format="plain">Plain text</button>
			<button type="button" data-format="markdown">Markdown</button>
		</div>
		<pre></pre>
	</section>
`)
definer.output.setCss(`
	.citation-builder { padding: 18px; }
	.citation-builder div { display: flex; gap: 8px; }
	.citation-builder button { padding: 7px 12px; cursor: pointer; }
	.citation-builder pre {
		padding: 12px; white-space: pre-wrap; user-select: text;
		border-radius: 8px; background: ${definer.theme.rgba('text', 0.06)};
	}
`)

const output = document.querySelector('.citation-builder pre')
const showFormat = (format) => {
	output.textContent = formats[format]
}

for (const button of document.querySelectorAll('.citation-builder button')) {
	button.addEventListener('click', () => showFormat(button.dataset.format))
}

showFormat('plain')

How it works

The script explicitly requests page_title, url, page_og_site_name, and page_last_modified. It builds both formats from those snapshots, falls back to the access date when no modification value exists, and switches the visible text without rerunning the source.

The generated citation is assigned through textContent, so page metadata is displayed as text. Using literal variable names keeps those values available when the lookup is reopened from History.

Customize it

  • Add a house style tailored to your own notes or bibliography.
  • Include the selected sentence or paragraph as a quotation.
  • Prefer a site's canonical Open Graph URL when your workflow trusts that metadata.
  • Add author metadata only when you have a reliable source for it; Definer does not currently expose a normalized page-author variable.

Limitations

This is a practical source reference, not a complete MLA, APA, or Chicago citation generator. Websites can omit, mislabel, or localize metadata, and page_last_modified may be an unnormalized page value. Review citations used in formal work.

Return to the Script Catalog.