diff --git a/langs/en-ca.json b/langs/en-ca.json index 7f94af9..fc4f428 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -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" } } } diff --git a/module/oft.mjs b/module/oft.mjs index da43fac..5765c9d 100644 --- a/module/oft.mjs +++ b/module/oft.mjs @@ -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(); diff --git a/module/settings/addGlobalDocReferrer.mjs b/module/settings/addGlobalDocReferrer.mjs new file mode 100644 index 0000000..0700606 --- /dev/null +++ b/module/settings/addGlobalDocReferrer.mjs @@ -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 + +};