Improve randomize button and fix behaviour without JS

parent 4d615b10
Pipeline #1481 passed with stage
in 40 seconds
......@@ -21,6 +21,17 @@ app.use(function(req, res, next) {
});
app.use(function(req, res, next) {
let _ = req.i18n._;
let bgColors = ['#f54358', '#ee0088', '#ff9146', '#ffd201', '#39d0b7', '#2f5189', '#000'];
let fgColors = ['#f54358', '#ee0088', '#ff9146', '#ffd201', '#39d0b7', '#2f5189', '#000', '#fff'];
let sampleTexts = ["arachnides", "bicyclette", "bidule", "bilboquet", "biscuit", "bitcoins", "bitte", "bollard", "cantine", "casserole", "chausse-pied", "chaloupe", "chalutier", "champignons", "chignon", "chouchen", "couleurs moches", "coton-tige", "cucurbitacée", "culotte", "démocratie", "élastique", "enzyme", "fonte", "frigogidaire", "germanium", "gousse", "gousset", "hurluberlu", "hypocondrie", "loquet", "mammouth", "marmite", "Michel Sardou", "musaraigne", "narcotype", "ornythorinque", "palette", "parc de stationnement", "pelle à tarte", "perpendicularité", "plat à tarte", "poêle", "pogne", "poireau", "polochon", "pop-corn", "poulpe", "poutrelle", "prolétariat", "protozoaire", "rateau", "sabot", "sabre laser", "semi-remorque", "soulier", "taquet", "tartenpion", "tartignol", "téléportation", "tentacules", "tractopelle", "trou noir", "vérité", "zeste"];
let sampleSignatures = ["\t", "moi\t", "les gens sympas\t", "les gens biens\t"];
let _fonts = [];
for (let i in fonts) {
_fonts.push(i);
}
req.args = {
bgColor: req.query.bgColor || '#f54358',
fgColor: req.query.fgColor || '#ffd201',
......@@ -29,6 +40,18 @@ app.use(function(req, res, next) {
icon: req.query.icon || 1,
signature: req.query.signature ? req.query.signature.trim() : ''
};
if (req.query.target === 'randomize') {
req.args.bgColor = bgColors[Math.floor(Math.random() * bgColors.length)];
do {
req.args.fgColor = bgColors[Math.floor(Math.random() * fgColors.length)];
} while (req.args.fgColor === req.args.bgColor);
req.args.text = _(sampleTexts[Math.floor(Math.random() * sampleTexts.length)]);
req.args.font = _fonts[Math.floor(Math.random() * _fonts.length)];
req.args.icon = Math.floor(Math.random() * 36);
req.args.signature = _(sampleSignatures[Math.floor(Math.random() * sampleSignatures.length)]);
}
next();
});
......@@ -61,28 +84,6 @@ function buildUrl(req) {
+ querystring.stringify(req.query);
}
function randomize(req, _) {
let bgColors = ['#f54358', '#ee0088', '#ff9146', '#ffd201', '#39d0b7', '#2f5189', '#000'];
let fgColors = ['#f54358', '#ee0088', '#ff9146', '#ffd201', '#39d0b7', '#2f5189', '#000', '#fff'];
let sampleTexts = ["arachnides", "bicyclette", "bidule", "bilboquet", "biscuit", "bitcoins", "bitte", "bollard", "cantine", "casserole", "chausse-pied", "chaloupe", "chalutier", "champignons", "chignon", "chouchen", "couleurs moches", "coton-tige", "cucurbitacée", "culotte", "démocratie", "élastique", "enzyme", "fonte", "frigogidaire", "germanium", "gousse", "gousset", "hurluberlu", "hypocondrie", "loquet", "mammouth", "marmite", "Michel Sardou", "musaraigne", "narcotype", "ornythorinque", "palette", "parc de stationnement", "pelle à tarte", "perpendicularité", "plat à tarte", "poêle", "pogne", "poireau", "polochon", "pop-corn", "poulpe", "poutrelle", "prolétariat", "protozoaire", "rateau", "sabot", "sabre laser", "semi-remorque", "soulier", "taquet", "tartenpion", "tartignol", "téléportation", "tentacules", "tractopelle", "trou noir", "vérité", "zeste"];
let sampleSignatures = ["\t", "moi\t", "les gens sympas\t", "les gens biens\t"];
let _fonts = [];
for (let i in fonts) {
_fonts.push(i);
}
req.args.bgColor = bgColors[Math.floor(Math.random() * bgColors.length)];
do {
req.args.fgColor = bgColors[Math.floor(Math.random() * fgColors.length)];
} while (req.args.fgColor === req.args.bgColor);
req.args.text = _(sampleTexts[Math.floor(Math.random() * sampleTexts.length)]);
req.args.font = _fonts[Math.floor(Math.random() * _fonts.length)];
req.args.icon = Math.floor(Math.random() * 36);
req.args.signature = _(sampleSignatures[Math.floor(Math.random() * sampleSignatures.length)]);
return req;
}
app.get('/generate.png', function (req, res) {
let _ = req.i18n._;
......@@ -92,9 +93,6 @@ app.get('/generate.png', function (req, res) {
else if (req.query.target === 'twitter') {
return res.redirect('https://twitter.com/intent/tweet?text=Soutenez La Quadrature du Net ! ' + encodeURIComponent(buildUrl(req)));
}
else if (req.query.target === 'randomize') {
req = randomize(req, _);
}
else if (req.query.target === 'download') {
res.set("Content-Disposition", "attachment;filename=lqdn_slogan.png");
}
......
mixin randomButtonContainer
.randomize-button-container
button(type="submit" name="target" value="randomize" class="randomize white-button")
button(type="submit" name="target" value="randomize" formaction="" formtarget="_self").randomize.white-button
=_('CHOISIR AU HASARD') + ' '
span.fa.fa-random
doctype html
......@@ -114,7 +114,7 @@ html(lang=locale)
span.text
=_('Actualiser') + ' '
span.fa.fa-refresh
button(type="submit" name="target" value="randomize").randomize.white-button
button(type="submit" name="target" value="randomize" formaction="" formtarget="_self").randomize.white-button
span.fa.fa-random
button(type="submit" name="target" value="twitter")#tweet-button.blue-button
span.text
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment