ATTHEMEEDITOR Telegram 11
You already know that you can run scripts in the editor to simplify a lot of work (and if you don't — surpise! It's a really awesome feature). You can, for example, make a dark theme basing on a light one in a second. Let's see how.

First, you might think of a script that just inverts all the colors in the theme, like this one:
const variables = activeTheme.getVariables();

for (const variable of variables) {
const color = activeTheme.getVariable(variable);

color.red = 255 - color.red;
color.green = 255 - color.green;
color.blue = 255 - color.blue;

activeTheme.setVariable(variable, color);
}
But there are two downsides of this script:
1. The most obvious, it turns colors into negated one, e.g. red to cyan. We would like to expect to change only white to black and vice versa;
2. The least obvious, it won't change unadded variables and the theme will look uglier.
So let's try to fix these issues.

The second one is the easiest to fix, here's what you need to change:
- for (const variable of variables) {
+ for (const variable of allVariablesList) {
- const color = activeTheme.getVariable(variable);
+ const color = variables.indexOf(variable) !== -1
+ ? activeTheme.getVariable(variable)
+ : allVariablesDefaultValues[variable];
(Note: we can't use neither `Object.assign` nor `variables.includes` until the interpreter supports them. You should also copy the color if it's not in the theme just if you'll have to use it once more in the same script — do it on your own.)
(Don't forget to remove the `+` and `-` on the line starts — they denote what you should change and they're not a part of the script)

But what about the first issue? We need to change the lightness of the color, not inverse its RGB channel. And we need to use HSL! Let's do that. Here's the final script:
const variables = activeTheme.getVariables();

for (const variable of allVariablesList) {
const color = Color.rgbToHsl(
variables.indexOf(variable) !== -1
? activeTheme.getVariable(variable)
: allVariablesDefaultValues[variable],
);

color.lightness = 1 - color.lightness;

activeTheme.setVariable(
variable,
Color.hslToRgb(color),
);
}
(Note: activeTheme.setVariable requires an RGB color.)

Now try running the script on some of the light themes you'd like to turn to dark (or vice versa)! Here's an example on Green Lightened:



tgoop.com/atthemeeditor/11
Create:
Last Update:

You already know that you can run scripts in the editor to simplify a lot of work (and if you don't — surpise! It's a really awesome feature). You can, for example, make a dark theme basing on a light one in a second. Let's see how.

First, you might think of a script that just inverts all the colors in the theme, like this one:

const variables = activeTheme.getVariables();

for (const variable of variables) {
const color = activeTheme.getVariable(variable);

color.red = 255 - color.red;
color.green = 255 - color.green;
color.blue = 255 - color.blue;

activeTheme.setVariable(variable, color);
}
But there are two downsides of this script:
1. The most obvious, it turns colors into negated one, e.g. red to cyan. We would like to expect to change only white to black and vice versa;
2. The least obvious, it won't change unadded variables and the theme will look uglier.
So let's try to fix these issues.

The second one is the easiest to fix, here's what you need to change:
- for (const variable of variables) {
+ for (const variable of allVariablesList) {
- const color = activeTheme.getVariable(variable);
+ const color = variables.indexOf(variable) !== -1
+ ? activeTheme.getVariable(variable)
+ : allVariablesDefaultValues[variable];
(Note: we can't use neither `Object.assign` nor `variables.includes` until the interpreter supports them. You should also copy the color if it's not in the theme just if you'll have to use it once more in the same script — do it on your own.)
(Don't forget to remove the `+` and `-` on the line starts — they denote what you should change and they're not a part of the script)

But what about the first issue? We need to change the lightness of the color, not inverse its RGB channel. And we need to use HSL! Let's do that. Here's the final script:
const variables = activeTheme.getVariables();

for (const variable of allVariablesList) {
const color = Color.rgbToHsl(
variables.indexOf(variable) !== -1
? activeTheme.getVariable(variable)
: allVariablesDefaultValues[variable],
);

color.lightness = 1 - color.lightness;

activeTheme.setVariable(
variable,
Color.hslToRgb(color),
);
}
(Note: activeTheme.setVariable requires an RGB color.)

Now try running the script on some of the light themes you'd like to turn to dark (or vice versa)! Here's an example on Green Lightened:

BY .attheme editor blog


Share with your friend now:
tgoop.com/atthemeeditor/11

View MORE
Open in Telegram


Telegram News

Date: |

Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. The court said the defendant had also incited people to commit public nuisance, with messages calling on them to take part in rallies and demonstrations including at Hong Kong International Airport, to block roads and to paralyse the public transportation system. Various forms of protest promoted on the messaging platform included general strikes, lunchtime protests and silent sit-ins. The creator of the channel becomes its administrator by default. If you need help managing your channel, you can add more administrators from your subscriber base. You can provide each admin with limited or full rights to manage the channel. For example, you can allow an administrator to publish and edit content while withholding the right to add new subscribers. To view your bio, click the Menu icon and select “View channel info.” The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar.
from us


Telegram .attheme editor blog
FROM American