This code loads a webpage into the browser's viewport using the $TS
object, specifying a URL and initial rendering settings, including zoom, width, and height. The initial settings are set to 50% zoom, 680 pixels in width, and 400 pixels in height, with content cropping if necessary.
$TS.screen('act.com/de-de', {zoom: .5, width: 680, 'crop-h': 400});
/**
* Util function to open a URL with specific screen settings.
*
* @param url - The URL to open.
* @param screenSettings - An object containing zoom and width settings.
*/
const openUrlWithScreenSettings = (
url: string,
screenSettings: { zoom: number; width: number; 'crop-h': number }
) => {
// Set default values for screen settings
const defaultScreenSettings: { zoom: number; width: number; 'crop-h': number } = {
zoom: 1,
width: 1920,
'crop-h': 1080,
};
// Merge user-provided settings with default settings
const mergedSettings = {...defaultScreenSettings,...screenSettings };
// Check for invalid settings
if (mergedSettings.zoom < 0) {
throw new Error("Zoom cannot be a negative number");
}
if (mergedSettings.width <= 0) {
throw new Error("Width must be a positive number");
}
if (mergedSettings['crop-h'] <= 0) {
throw new Error("Crop height must be a positive number");
}
// Create the command string
const command = `TS.screen(${url}, { zoom: ${mergedSettings.zoom}, width: ${mergedSettings.width}, 'crop-h': ${mergedSettings['crop-h']} })`;
// Execute the command (this would be the actual browser or system command to open the URL)
// Here, we'll just return the command string for now
return command;
};
// Example usage:
const url = "act.com/de-de";
const screenSettings = { zoom: 0.5, width: 680, 'crop-h': 400 };
const command = openUrlWithScreenSettings(url, screenSettings);
console.log(command);
This code uses the $TS
object to load a webpage into the browser's viewport.
act.com/de-de
: The URL of the webpage to load.{zoom:.5, width: 680, 'crop-h': 400}
: An options object that defines the initial rendering settings:
zoom:.5
: Zooms the webpage to 50% of its original size.width: 680
: Sets the width of the rendered webpage to 680 pixels.'crop-h': 400
: Sets the height of the rendered webpage to 400 pixels, cropping the content if necessary.