### Cloudflare Configuration Error Alert in JavaScript Source: https://docs.tmc.bj/v2/get-started This JavaScript snippet executes on DOMContentLoaded to check for 'rocket-loader.min.js', which indicates a potential Cloudflare misconfiguration. If detected, it dynamically creates an alert div with a warning message and prepends it to the document body, guiding site owners to GitBook's documentation for resolution. ```JavaScript \n document.addEventListener(\"DOMContentLoaded\", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n \u003cstrong\u003eError in site configuration:\u003c/strong\u003e\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to \u003ca href=\"https://gitbook.com/docs/published-documentation/custom-domain/configure-dns#are-you-using-cloudflare\" class=\"underline\"\u003eGitBook's documentation\u003c/a\u003e for steps to fix the problem.\n `;\n\n document.body.prepend(alert);\n }\n }); ``` -------------------------------- ### Registering a New Command in Lua Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/commands This snippet demonstrates how to register a new command using `TMC.Commands.Add`. It defines a command named 'example' with a help text, specifies an argument 'arg', sets it as required, and provides a callback function that receives the player's server ID and argument values. The command requires 'helper' permission. ```Lua TMC.Commands.Add("example", "Example Command", {{name="arg", help="An Argument"}}, true, function(source, args) -- source: player's server id -- args: values set for arguments end, "helper") ``` -------------------------------- ### Adding a New Command with TMC.Commands.Add in Lua Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/commands This snippet demonstrates how to register a new command using `TMC.Commands.Add`. It defines a command named 'example' with a description, an optional argument 'arg', specifies that arguments are required, provides a callback function to handle command execution, and sets a 'helper' permission level. The callback function receives the player's server ID (`source`) and a table of argument values (`args`). ```Lua TMC.Commands.Add("example", "Example Command", {{name="arg", help="An Argument"}}, true, function(source, args) -- source: player's server id -- args: values set for arguments end, "helper") ``` -------------------------------- ### Creating a Bank Account - Banking API (Lua) Source: https://docs.tmc.bj/v2/other-resources/banking Forcibly creates a new bank account with specified parameters such as account type, name, owner's CSN, primary status, and an optional starting balance. The function returns the unique bank account number generated for the new account. ```Lua -- bankType: The type of bank to create (`personal` or `business`) -- name: The name of the account -- owner: The CSN for the owner of the bank -- primary: Is this a primary account (cannot be deleted) (default: false if not provided) -- balance: The starting balance for the account (default: 0 if not provided) -- Returns the generated bank account number exports.banking:CreateAccount(bankType, name, owner, primary, balance) ``` -------------------------------- ### Detecting Cloudflare Rocket Loader Configuration Error - JavaScript Source: https://docs.tmc.bj/v2/other-resources/banking This client-side JavaScript snippet listens for the `DOMContentLoaded` event to check for potential misconfigurations with Cloudflare's Rocket Loader. If `rocket-loader.min.js` is detected, it dynamically creates and prepends an error alert to the document body, guiding the site owner to GitBook's documentation for resolution. This helps diagnose and inform users about issues that might affect page loading or behavior. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = ` Error in site configuration: It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem. `; document.body.prepend(alert); } }); ``` -------------------------------- ### Displaying Cloudflare Configuration Error in JavaScript Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions This JavaScript snippet listens for the DOMContentLoaded event and checks if 'rocket-loader.min.js' is present, indicating a potential Cloudflare configuration issue. If detected, it dynamically creates and prepends an alert message to the document body, guiding the site owner to GitBook's documentation for a fix. ```JavaScript \n document.addEventListener(\"DOMContentLoaded\", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n Error in site configuration:\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem.\n `;\n\n document.body.prepend(alert);\n }\n }); ``` -------------------------------- ### Cloudflare Rocket Loader Configuration Alert in JavaScript Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/general-functions This JavaScript snippet executes upon DOMContentLoaded to check for the presence of 'rocket-loader.min.js', a script often used by Cloudflare. If detected, it dynamically creates and prepends an alert message to the document body, warning site owners about potential Cloudflare misconfigurations that could lead to page loading issues and provides a link to GitBook's documentation for troubleshooting. ```JavaScript \n document.addEventListener(\"DOMContentLoaded\", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n \u003cstrong\u003eError in site configuration:\u003c/strong\u003e\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to \u003ca href=\"https://gitbook.com/docs/published-documentation/custom-domain/configure-dns#are-you-using-cloudflare\" class=\"underline\"\u003eGitBook's documentation\u003c/a\u003e for steps to fix the problem.\n `;\n\n document.body.prepend(alert);\n }\n }); ``` -------------------------------- ### Adding a Dispatch Call (Server & Client) Source: https://docs.tmc.bj/v2/other-resources/dispatch This snippet demonstrates how to add a new dispatch call using the TMC.Functions API. It includes examples for both server-side and client-side initiation. The callObj parameter defines the call's details, such as title, description, job type, position, urgency, and optional zone-based limits. ```Lua -- Server TMC.Functions.TriggerEvent('dispatch:server:addCall', { title = \"A title!\", description = \"Some longer description\", jobType = 'jobType', position = vector3(0, 0, 0), urgency = 1, limits = {} }) ``` ```Lua -- Client TMC.Functions.TriggerServerEvent('dispatch:server:addCall', { title = \"A title!\", description = \"Some longer description\", jobType = 'jobType', position = vector3(0, 0, 0), urgency = 1, limits = {} }) ``` -------------------------------- ### Displaying Cloudflare Configuration Error Alert (JavaScript) Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/commands This JavaScript snippet listens for the DOMContentLoaded event and checks if Cloudflare's rocket-loader.min.js script is present. If found, it dynamically creates and prepends an alert message to the document body, informing the user about a potential Cloudflare configuration error and directing site owners to GitBook's documentation for a fix. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = ` Error in site configuration: It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem. `; document.body.prepend(alert); } }); ``` -------------------------------- ### Displaying Cloudflare Configuration Error Alert (JavaScript) Source: https://docs.tmc.bj/v2/tmc-core-object/events/server This JavaScript snippet listens for the DOMContentLoaded event. If it detects that 'rocket-loader.min.js' is being used, indicating a potential Cloudflare misconfiguration, it dynamically creates and prepends an alert div to the document body. The alert informs the user about the error and provides a link to GitBook's documentation for resolution. ```JavaScript \n document.addEventListener(\"DOMContentLoaded\", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n \u003cstrong\u003eError in site configuration:\u003c/strong\u003e\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to \u003ca href=\"https://gitbook.com/docs/published-documentation/custom-domain/configure-dns#are-you-using-cloudflare\" class=\"underline\"\u003eGitBook's documentation\u003c/a\u003e for steps to fix the problem.\n `;\n\n document.body.prepend(alert);\n }\n }); ``` -------------------------------- ### Configuring Multiple Vehicle and Brand Names - Lua Source: https://docs.tmc.bj/v2/tmc-core-object/vehicle-names This expanded Lua example illustrates how to configure multiple vehicle model names ('testcar', 'fiestast', 'mstgt500') and brand names ('TESTBRAND', 'FORD') within a single Citizen.CreateThread block. It highlights that a brand entry only needs to be added once, even if multiple vehicles share the same brand, streamlining the configuration process. ```Lua Citizen.CreateThread(function() -- gameNames AddTextEntry('testcar', 'Model Name') AddTextEntry('fiestast', 'Fiesta ST') AddTextEntry('mstgt500', 'Mustang GT500 Fastback') -- makeNames/brand names AddTextEntry('TESTBRAND', 'Brand Name') AddTextEntry('FORD', 'Ford') end) ``` -------------------------------- ### Displaying Cloudflare Configuration Error - JavaScript Source: https://docs.tmc.bj/v2/object-models/job This script listens for the `DOMContentLoaded` event and checks if `rocket-loader.min.js` (a Cloudflare script) is present. If found, it indicates a potential Cloudflare configuration error, dynamically creates an alert `div`, populates it with an error message and a link to GitBook's documentation, and prepends it to the document body to notify the user or site owner. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = ` Error in site configuration: It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem. `; document.body.prepend(alert); } }); ``` -------------------------------- ### Handle Cloudflare Rocket Loader Configuration Error in JavaScript Source: https://docs.tmc.bj/v2/tmc-core-object/client-functions/interaction-ped-functions This JavaScript snippet adds an event listener to the DOMContentLoaded event. It checks if Cloudflare's 'rocket-loader.min.js' script is present on the page. If found, it dynamically creates and prepends an alert div to the document body, informing the user about a potential site configuration error related to Cloudflare and provides a link to GitBook's documentation for resolution. ```JavaScript \n document.addEventListener(\"DOMContentLoaded\", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n Error in site configuration:\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem.\n `;\n\n document.body.prepend(alert);\n }\n }); ``` -------------------------------- ### Detecting Cloudflare Rocket Loader and Displaying Configuration Error in JavaScript Source: https://docs.tmc.bj/v2/other-resources/banking This JavaScript snippet runs on DOMContentLoaded to check if Cloudflare's 'rocket-loader.min.js' script is present on the page. If detected, it dynamically creates and prepends an alert div to the document body, informing the user about a potential Cloudflare configuration error and providing a link to GitBook's documentation for troubleshooting. This helps site owners identify and resolve issues that might cause unexpected page behavior. ```JavaScript \n document.addEventListener(\"DOMContentLoaded\", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n Error in site configuration:\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem.\n `;\n\n document.body.prepend(alert);\n }\n }); ``` -------------------------------- ### Creating Useable Items with Callback in Lua Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions This Lua code demonstrates the use of `TMC.Functions.CreateUseableItem` to define a new useable item. It takes two primary parameters: `name` (a string representing the item's identifier, e.g., 'tmc_giftcard') and `callback` (a function that executes when the item is used, receiving `source`, `item`, and `index` as arguments). ```Lua TMC.Functions.CreateUseableItem('tmc_giftcard', function(source, item, index) -- end) ``` -------------------------------- ### Display Cloudflare Configuration Error Alert - JavaScript Source: https://docs.tmc.bj/v2/other-resources/dispatch This script listens for the DOMContentLoaded event and checks if 'rocket-loader.min.js' (a Cloudflare script) is present. If found, it dynamically creates and prepends an error alert to the document body, informing the user about a potential Cloudflare configuration issue and linking to GitBook's documentation for a fix. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = ` Error in site configuration: It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem. `; document.body.prepend(alert); } }); ``` -------------------------------- ### Displaying Cloudflare Configuration Error in JavaScript Source: https://docs.tmc.bj/v2/tmc-core-object/client-functions/interaction-object-functions This script listens for the DOMContentLoaded event and checks if the rocket-loader.min.js script is present. If detected, it dynamically creates and prepends an alert message to the document body, warning the site owner about potential Cloudflare configuration issues and providing a link to GitBook's documentation for a fix. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = ` Error in site configuration: It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem. `; document.body.prepend(alert); } }); ``` -------------------------------- ### Next.js Framework Internal Data Initialization (JavaScript) Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/commands This snippet represents internal JavaScript logic, likely part of a Next.js application. It initializes and pushes data into self.__next_f, which is used by the framework for client-side routing, asset loading (CSS files), and managing the component tree and initial page data. This is crucial for the application's hydration and navigation. ```JavaScript (self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])self.__next_f.push([1,"1:HC[\"https://static.gitbook.com\",\"\"]\n2:HL[\"https://static.gitbook.com/_next/static/css/51d34edee75a6bda.css\",\"style\"]\n3:HL[\"https://static.gitbook.com/_next/static/css/ce80118b5e9525b5.css\",\"style\"]\n4:HL[\"https://static.gitbook.com/_next/static/css/3fabe74bb705cbb5.css\",\"style\"]\n5:HL[\"https://static.gitbook.com/_next/static/css/95b358fb5c9305a3.css\",\"style\"]\n6:HL[\"https://static.gitbook.com/_next/static/css/bc859a4cd35f3fe5.css\",\"style\"]\n7:HL[\"https://static.gitbook.com/_next/static/css/44b2f92f2be025d7.css\",\"style\"]\n8:HL[\"https://static.gitbook.com/_next/static/css/89f0191abc1ad313.css\",\"style\"]\n9:HL[\"https://static.gitbook.com/_next/static/css/ebd5a08666f5847b.css\",\"style\"]\na:HL[\"https://static.gitbook.com/_next/static/css/7aa73a37ce5b6ac5.css\",\"style\"]\nb:HL[\"https://static.gitbook.com/_next/static/css/7ca4b41b4535decf.css\",\"style\"]\nc:HL[\"https://static.gitbook.com/_next/static/css/011becb3969a7abe.css\",\"style\"]\nd:HL[\"https://static.gitbook.com/_next/static/css/4af9aafd612346fe.css\",\"style\"]\ne:I[11815,[],\"default\"]\n11:I[55092,[],\"default\"]\n13:I[82023,[],\"default\"]\n18:I[44622,[\"6470\",\"static/chunks/app/global-error-53091e9566f77828.js\"],\"default\"]\n12:[\"pathname\",\"tmc-core-object/server-functions/commands\",\"oc\"]\n19:[]\n0:[\"$\",\"$Le\",null,{\"buildId\":\"v0rvY9MgLPuP2OBmZXVls\",\"assetPrefix\":\"https://static.gitbook.com\",\"urlParts\":[\"\",\"v2\",\"tmc-core-object\",\"server-functions\",\"commands\"],\"initialTree\":[\"\",{\"children\":[\"middleware\",{\"children\":[\"(site)\",{\"children\":[\"(content)\",{\"children\":[[\"pathname\",\"tmc-core-object/server-functions/commands\",\"oc\"],{\"children\":[\"__PAGE__?{\\\"pathname\\\":[\\\"tmc-core-object\\\",\\\"server-functions\\\",\\\"commands\\\"]}\",{}]}]}]},\"$undefined\",\"$undefined\",true]}]}],\"initialSeedData\":[\"\",{\"children\":[\"middleware\",{\"children\":[\"(site)\",{\"children\":[\"(content)\",{\"children\":[[\"pathname\",\"tmc-core-object/server-functions/commands\",\"oc\"],{\"children\":[\"__PAGE__\",{},[[\"$Lf\",\"$L10\",[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/44b2f92f2be025d7.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/89f0191abc1ad313.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"2\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/ebd5a08666f5847b.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"3\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/7aa73a37ce5b6ac5.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"4\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/7ca4b41b4535decf.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"5\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/011becb3969a7abe.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"6\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/4af9aafd612346fe.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]]],null],null]]},[[null,[[\"$\",\"$L11\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"middleware\",\"children\",\"(site)\",\"children\",\"(content)\",\"children\",\"$12\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L13\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$L14\",\"notFoundStyles\":[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/44b2f92f2be025d7.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/89f0191abc1ad313.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"2\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/ebd5a08666f5847b.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"3\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/7aa73a37ce5b6ac5.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"4\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/7ca4b41b4535decf.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"5\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/011becb3969a7abe.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[[\"$\",\"link\",\"6\",{\"rel\":\"stylesheet\",\"href\":\"https://static.gitbook.com/_next/static/css/4af9aafd612346fe.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]]}]]],[[null,[[\"$\",\"div\",null,{\"className\":\"flex flex-row flex-1 relative py-8 lg:px-16 xl:mr-56 items-center lg:items-start\",\"children\":[[\"$\",\"div\",null,{\"className\":\"flex-1 max-w-3xl mx-auto page-full-width:mx-0\",\"children\":[[[\"$\",\"div\",null,{\"id\":\"$undefined\",\"role\":\"status\",\"aria-busy\":true,\"className\":\"mb-8\",\"children\":[[\"$\",\"div\",null,{\"className\":\"ring-1 ring-tint-subtle overflow-hidden relative grid rounded-\"}]]]}]]}]]}]] ``` -------------------------------- ### Detecting Cloudflare Rocket Loader and Displaying Configuration Error (JavaScript) Source: https://docs.tmc.bj/v2/other-resources/dispatch This JavaScript snippet listens for the DOMContentLoaded event. It checks if 'rocket-loader.min.js' is present among the loaded scripts, which indicates a potential Cloudflare misconfiguration. If detected, it dynamically creates and prepends an alert div to the document body, informing the user about the issue and providing a link to GitBook's documentation for troubleshooting. ```JavaScript \n document.addEventListener(\"DOMContentLoaded\", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n \u003cstrong\u003eError in site configuration:\u003c/strong\u003e\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to \u003ca href=\"https://gitbook.com/docs/published-documentation/custom-domain/configure-dns#are-you-using-cloudflare\" class=\"underline\">GitBook's documentation\u003c/a\u003e for steps to fix the problem.\n `; \n document.body.prepend(alert);\n }\n }); ``` -------------------------------- ### Display Cloudflare Configuration Error Alert on DOM Load in JavaScript Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/general-functions This JavaScript code listens for the `DOMContentLoaded` event. If it detects that 'rocket-loader.min.js' is present among the document's scripts, it dynamically creates and prepends an alert div to the body, informing the user about a potential Cloudflare configuration error and providing a link to GitBook's documentation for a fix. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = ` Error in site configuration: It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem. `; document.body.prepend(alert); } }); ``` -------------------------------- ### Defining Light and Dark Theme CSS Variables Source: https://docs.tmc.bj/v2/other-resources/banking This CSS snippet defines a comprehensive set of custom properties (CSS variables) for managing the application's color scheme. It includes a default light theme defined under ':root' and a dark theme defined under the '.dark' class, providing distinct color palettes for various UI elements and states. ```CSS :root { --primary-1: 255 255 255; --contrast-primary-1: 29 29 29; --primary-2: 246 250 255; --contrast-primary-2: 29 29 29; --primary-3: 240 249 255; --contrast-primary-3: 29 29 29; --primary-4: 231 244 255; --contrast-primary-4: 29 29 29; --primary-5: 223 239 255; --contrast-primary-5: 29 29 29; --primary-6: 211 232 253; --contrast-primary-6: 29 29 29; --primary-7: 195 220 245; --contrast-primary-7: 29 29 29; --primary-8: 179 208 237; --contrast-primary-8: 29 29 29; --primary-9: 0 113 188; --contrast-primary-9: 255 255 255; --primary-10: 28 126 202; --contrast-primary-10: 255 255 255; --primary-11: 83 113 143; --contrast-primary-11: 255 255 255; --primary-12: 24 30 36; --contrast-primary-12: 255 255 255; --primary-original: 0 113 188; --contrast-primary-original: 255 255 255; --tint-1: 255 255 255; --contrast-tint-1: 29 29 29; --tint-2: 249 250 251; --contrast-tint-2: 29 29 29; --tint-3: 246 248 249; --contrast-tint-3: 29 29 29; --tint-4: 240 243 245; --contrast-tint-4: 29 29 29; --tint-5: 234 238 241; --contrast-tint-5: 29 29 29; --tint-6: 226 230 234; --contrast-tint-6: 29 29 29; --tint-7: 213 218 222; --contrast-tint-7: 29 29 29; --tint-8: 199 205 211; --contrast-tint-8: 29 29 29; --tint-9: 120 135 150; --contrast-tint-9: 255 255 255; --tint-10: 108 123 138; --contrast-tint-10: 255 255 255; --tint-11: 105 111 117; --contrast-tint-11: 255 255 255; --tint-12: 28 29 30; --contrast-tint-12: 255 255 255; --tint-original: 120 120 120; --contrast-tint-original: 255 255 255; --neutral-1: 255 255 255; --contrast-neutral-1: 29 29 29; --neutral-2: 250 250 250; --contrast-neutral-2: 29 29 29; --neutral-3: 247 247 2 ``` -------------------------------- ### Detecting Cloudflare Rocket Loader and Displaying Error (JavaScript) Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/commands This JavaScript snippet executes upon the DOMContentLoaded event. It identifies if Cloudflare's 'rocket-loader.min.js' script is loaded on the page. If detected, it dynamically creates an alert message as a div element and prepends it to the document body. The alert informs the user about a potential Cloudflare configuration error and provides a direct link to GitBook's documentation for resolution, aiding in diagnosing and fixing issues related to Cloudflare's optimization features. ```JavaScript document.addEventListener("DOMContentLoaded", () => {\n if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) {\n const alert = document.createElement('div');\n alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8';\n alert.innerHTML = `\n Error in site configuration:\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem.\n `;\n\n document.body.prepend(alert);\n }\n}); ``` -------------------------------- ### Displaying Cloudflare Configuration Error Alert in JavaScript Source: https://docs.tmc.bj/v2/tmc-core-object/events This JavaScript snippet listens for the DOMContentLoaded event to ensure the page is fully loaded before execution. It then checks if Cloudflare's 'rocket-loader.min.js' script is present in the document. If found, it dynamically creates a styled HTML div element containing an error message and a link to GitBook's documentation, prepending this alert to the document body. This helps site owners diagnose and resolve issues related to Cloudflare's Rocket Loader interfering with page loading. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = `\n Error in site configuration:\n It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem.\n `; document.body.prepend(alert); } }); ``` -------------------------------- ### Handling TMC:Server:OnPlayerLoaded in Lua Source: https://docs.tmc.bj/v2/tmc-core-object/events/server This event is triggered once a player's data has been completely loaded and is accessible. It provides the source of the player whose data has been loaded. ```Lua -- source: players' source ``` -------------------------------- ### Defining Global CSS Color Variables in Root Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/commands This CSS snippet defines a comprehensive set of custom properties (CSS variables) within the `:root` pseudo-class. These variables are used to establish a consistent color palette across the application, including primary, tint, neutral, info, and warning color schemes, each with corresponding contrast colors. It also specifies header background and link colors. These variables allow for easy theme customization and dynamic styling. ```CSS :root { --primary-1: 255 255 255; --contrast-primary-1: 29 29 29; --primary-2: 246 250 255; --contrast-primary-2: 29 29 29; --primary-3: 240 249 255; --contrast-primary-3: 29 29 29; --primary-4: 231 244 255; --contrast-primary-4: 29 29 29; --primary-5: 223 239 255; --contrast-primary-5: 29 29 29; --primary-6: 211 232 253; --contrast-primary-6: 29 29 29; --primary-7: 195 220 245; --contrast-primary-7: 29 29 29; --primary-8: 179 208 237; --contrast-primary-8: 29 29 29; --primary-9: 0 113 188; --contrast-primary-9: 255 255 255; --primary-10: 28 126 202; --contrast-primary-10: 255 255 255; --primary-11: 83 113 143; --contrast-primary-11: 255 255 255; --primary-12: 24 30 36; --contrast-primary-12: 255 255 255; --primary-original: 0 113 188; --contrast-primary-original: 255 255 255; --tint-1: 255 255 255; --contrast-tint-1: 29 29 29; --tint-2: 249 250 251; --contrast-tint-2: 29 29 29; --tint-3: 246 248 249; --contrast-tint-3: 29 29 29; --tint-4: 240 243 245; --contrast-tint-4: 29 29 29; --tint-5: 234 238 241; --contrast-tint-5: 29 29 29; --tint-6: 226 230 234; --contrast-tint-6: 29 29 29; --tint-7: 213 218 222; --contrast-tint-7: 29 29 29; --tint-8: 199 205 211; --contrast-tint-8: 29 29 29; --tint-9: 120 135 150; --contrast-tint-9: 255 255 255; --tint-10: 108 123 138; --contrast-tint-10: 255 255 255; --tint-11: 105 111 117; --contrast-tint-11: 255 255 255; --tint-12: 28 29 30; --contrast-tint-12: 255 255 255; --tint-original: 120 120 120; --contrast-tint-original: 255 255 255; --neutral-1: 255 255 255; --contrast-neutral-1: 29 29 29; --neutral-2: 250 250 250; --contrast-neutral-2: 29 29 29; --neutral-3: 247 247 247; --contrast-neutral-3: 29 29 29; --neutral-4: 242 242 242; --contrast-neutral-4: 29 29 29; --neutral-5: 237 237 237; --contrast-neutral-5: 29 29 29; --neutral-6: 229 229 229; --contrast-neutral-6: 29 29 29; --neutral-7: 217 217 217; --contrast-neutral-7: 29 29 29; --neutral-8: 204 204 204; --contrast-neutral-8: 29 29 29; --neutral-9: 120 120 120; --contrast-neutral-9: 255 255 255; --neutral-10: 121 121 121; --contrast-neutral-10: 255 255 255; --neutral-11: 110 110 110; --contrast-neutral-11: 255 255 255; --neutral-12: 29 29 29; --contrast-neutral-12: 255 255 255; --neutral-original: 120 120 120; --contrast-neutral-original: 255 255 255; --header-background: 0 113 188; --header-link: 255 255 255; --info-1: 255 255 255; --contrast-info-1: 29 29 29; --info-2: 250 250 250; --contrast-info-2: 29 29 29; --info-3: 247 247 247; --contrast-info-3: 29 29 29; --info-4: 242 242 242; --contrast-info-4: 29 29 29; --info-5: 237 237 237; --contrast-info-5: 29 29 29; --info-6: 229 229 229; --contrast-info-6: 29 29 29; --info-7: 217 217 217; --contrast-info-7: 29 29 29; --info-8: 204 204 204; --contrast-info-8: 29 29 29; --info-9: 120 120 120; --contrast-info-9: 255 255 255; --info-10: 121 121 121; --contrast-info-10: 255 255 255; --info-11: 110 110 110; --contrast-info-11: 255 255 255; --info-12: 29 29 29; --contrast-info-12: 255 255 255; --info-original: 120 120 120; --contrast-info-original: 255 255 255; --warning-1: 255 255 255; --contrast-warning-1: 29 29 29; --warning-2: 254 249 244; --contrast-warning-2: 29 29 29; --warning-3: 255 245 236; --contrast-warning-3: 29 29 29; --warning-4: 255 239 225; --contrast-warning-4: 29 29 29; --warning-5: 254 233 214; --contrast-warning-5: 29 29 29; --warning-6: 250 224 200; --contrast-warning-6: 29 29 29; --warning-7: 242 211 182; --contrast-warning-7: 29 29 29; --warning-8: 233 197 164; --contrast-warning-8: 29 29 29; --warning-9: 254 154 0; --contrast-warning-9: 29 29 29; --warning-10: 187 92 0; --contrast-warning-10: 255 255 255; --warning-11: 138 102 66; --contrast-warning-11: 255 255 255; --warning-12: 35 28 21; } ``` -------------------------------- ### Initializing Dark Mode on Page Load (JavaScript) Source: https://docs.tmc.bj/v2/tmc-core-object/server-functions/commands This self-executing JavaScript function runs immediately on page load to ensure the site's dark mode is activated. It removes 'light' and 'dark' classes from the document's root element, sets the colorScheme to 'dark', and then adds the 'dark' class, effectively forcing a dark theme. ```JavaScript !function(){var d=document.documentElement,c=d.classList;c.remove('light','dark');d.style.colorScheme = 'dark';c.add('dark')}() ``` -------------------------------- ### Detecting Cloudflare Rocket Loader and Displaying Alert (JavaScript) Source: https://docs.tmc.bj/v2/object-models/job This JavaScript snippet listens for the DOMContentLoaded event to check if Cloudflare's 'rocket-loader.min.js' script is present on the page. If detected, it dynamically creates and prepends an alert message to the document body, informing the user about potential Cloudflare configuration issues and directing them to GitBook's documentation for a fix. This helps diagnose and resolve common deployment problems related to Cloudflare. ```JavaScript document.addEventListener("DOMContentLoaded", () => { if (Array.from(document.scripts).find(script => script.src.includes('rocket-loader.min.js'))) { const alert = document.createElement('div'); alert.className = 'p-4 mb-4 text-sm text-red-800 rounded-lg bg-red-50 mt-8 mx-8'; alert.innerHTML = ` Error in site configuration: It looks like ${window.location.hostname} has been incorrectly configured in Cloudflare. This may lead to unexpected behavior or issues with the page loading. If you are the owner of this site, please refer to GitBook's documentation for steps to fix the problem. `; document.body.prepend(alert); } }); ```