Add setting to add a global _doc reference (closes #4)

This commit is contained in:
Oliver 2025-12-07 17:56:56 -07:00
parent 5573a5b674
commit ee99ab15dd
3 changed files with 45 additions and 2 deletions

View file

@ -1,6 +1,10 @@
{
"OFT": {
"setting": {
"addGlobalDocReferrer": {
"name": "Add Global \"_doc\"",
"hint": "(v13+) This adds a header control to document sheets that sets the _doc globalThis variable. Until the header control is triggered, the \"_doc\" variable is undefined."
},
"autoUnpauseOnLoad": {
"name": "Auto Unpause On Load",
"hint": "(v13+, GM-Only) Automatically unpauses the game when you load into the world. This will happen EVERY time you load into the world, including if you reload the website."
@ -45,7 +49,8 @@
}
},
"apps": {
"no-settings-to-display": "No settings to display"
"no-settings-to-display": "No settings to display",
"make-global-reference": "Make Global Reference"
}
}
}

View file

@ -2,6 +2,8 @@
import "./hooks/renderSettingsConfig.mjs";
// Settings
import { addGlobalDocReferrer } from "./settings/addGlobalDocReferrer.mjs";
import { autoUnpauseOnLoad } from "./settings/autoUnpauseOnLoad.mjs";
import { chatSidebarBackground } from "./settings/chatSidebarBackground.mjs";
import { hotbarButtonGap } from "./settings/hotbarButtonGap.mjs";
import { hotbarButtonSize } from "./settings/hotbarButtonSize.mjs";
@ -15,7 +17,6 @@ import { DevSettingsMenu } from "./apps/DevSettingsMenu.mjs";
// Misc
import { __ID__ } from "./consts.mjs";
import { autoUnpauseOnLoad } from "./settings/autoUnpauseOnLoad.mjs";
Hooks.on(`setup`, () => {
@ -26,6 +27,7 @@ Hooks.on(`setup`, () => {
restricted: false,
type: DevSettingsMenu,
});
addGlobalDocReferrer();
autoUnpauseOnLoad();
chatSidebarBackground();

View file

@ -0,0 +1,36 @@
import { __ID__ } from "../consts.mjs";
import { Logger } from "../utils/Logger.mjs";
import { registerDevSetting } from "../utils/DevSettings.mjs";
const key = `addGlobalDocReferrer`;
export function addGlobalDocReferrer() {
// #region Registration
Logger.log(`Registering setting: ${key}`);
registerDevSetting(__ID__, key, {
name: `OFT.setting.${key}.name`,
hint: `OFT.setting.${key}.hint`,
scope: `user`,
type: Boolean,
default: false,
config: true,
requiresReload: false,
});
// #endregion Registration
// #region Implementation
Hooks.on(`getHeaderControlsDocumentSheetV2`, (app, controls) => {
if (!game.settings.get(__ID__, key)) { return };
controls.push({
icon: `fa-solid fa-file`,
label: `OFT.apps.make-global-reference`,
onClick: () => {
globalThis._doc = app.document;
},
});
});
// #endregion Implementation
};