diff --git a/lang/en.json b/lang/en.json index 169abdf..1d4d98b 100644 --- a/lang/en.json +++ b/lang/en.json @@ -46,6 +46,10 @@ "Name": "Show Sidebar Directory Ids?", "Hint": "Places a clickable chip on sidebar directory entries to copy the id or print the document to the console. Requires Reload" }, + "show-compendium-ids": { + "Name": "Show Compendium Document Ids?", + "Hint": "Places a clickable chip on compendium directory entries to copy the id or print the document to the console." + }, "suppress-too-small": { "Name": "Suppress Window Size Warning", "Hint": "Suppresses the window size warning on startup." diff --git a/module/classes/DevMode.mjs b/module/classes/DevMode.mjs index af8670f..1c3d48e 100644 --- a/module/classes/DevMode.mjs +++ b/module/classes/DevMode.mjs @@ -26,6 +26,7 @@ export class DevMode { packageSpecificDebug: 'package-specific-debug', suppressTooSmall: 'suppress-too-small', showDirectoryIds: 'show-directory-ids', + showCompendiumIds: 'show-compendium-ids', appHeaderButton: 'app-header-button', showChatIds: 'show-chat-ids', disableTemplateCache: 'disable-template-cache', diff --git a/module/classes/DevModeSettings.mjs b/module/classes/DevModeSettings.mjs index 040e3d8..a5c80d9 100644 --- a/module/classes/DevModeSettings.mjs +++ b/module/classes/DevModeSettings.mjs @@ -35,6 +35,10 @@ export class DevModeSettings { return; }, }, + { + key: DevMode.SETTINGS.showCompendiumIds, + default: true, + }, { key: DevMode.SETTINGS.appHeaderButton, default: true, diff --git a/module/hooks/dev-mode-anchor.mjs b/module/hooks/dev-mode-anchor.mjs index def958f..ce6d7e5 100644 --- a/module/hooks/dev-mode-anchor.mjs +++ b/module/hooks/dev-mode-anchor.mjs @@ -16,9 +16,11 @@ export default function setupDevModeAnchor() { const devModeTag = (relevantId, collection) => `
${relevantId} -
+
- + ${collection ? '' : ''}
`; @@ -50,6 +52,23 @@ export default function setupDevModeAnchor() { html.addClass('dev-mode-anchor'); }); + Hooks.on('renderCompendium', async (compendium, html) => { + if (!game.settings.get(DevMode.MODULE_ID, DevMode.SETTINGS.showCompendiumIds)) { + return; + } + + DevMode.log(false, 'renderCompendium', compendium, { + idAttribute, + }); + + html.find(`.directory-item[${idAttribute}]`).each(function () { + const relevantId = $(this).data()?.[idKey]; + + $(this).addClass('dev-mode-anchor'); + $(this).append(devModeTag(relevantId)); + }); + }); + /** * Any DOM element with the `.dev-mode-copy` class will look up the tree for an element * with `${idAttribute}` attribute and copy that attribute's value when clicked.