Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/og/ortalama-hesaplama.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions public/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,41 @@ code {
overflow-wrap: anywhere;
}

.avg-list {
height: auto;
min-height: 9.5em;
padding: 10px 12px;
font-size: 16px;
line-height: 1.5;
resize: vertical;
}

.avg-rows {
display: grid;
gap: 8px;
}

.avg-row {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px;
gap: 8px;
align-items: center;
}

.avg-head span {
font-size: 14px;
font-weight: 600;
}

.avg-del {
width: 40px;
padding: 0;
}

.avg-del:disabled {
visibility: hidden;
}

/* word frequency counter: the table scrolls inside the output pane */
.pane-title {
font-size: 14px;
Expand Down
55 changes: 54 additions & 1 deletion scripts/browser-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const COMPARE = { en: "/text-compare/", tr: "/tr/metin-karsilastirma/" };
const KDV = "/tr/kdv-hesaplama/";
const YAS = "/tr/yas-hesaplama/";
const YUZDE = "/tr/yuzde-hesaplama/";
const ORTALAMA = "/tr/ortalama-hesaplama/";
const DAYS = "/days-between-dates/";
const LINES = "/remove-line-breaks/";
const HEX = "/hex-to-rgb/";
Expand Down Expand Up @@ -1034,12 +1035,63 @@ for (const width of [1440, 390]) {
await context.close();
}

for (const width of [1440, 390]) {
const label = `ortalama ${width}`;
const { context, page, errors } = await open(width, ORTALAMA, label);
await page.evaluate(() => localStorage.clear());
await page.reload({ waitUntil: "networkidle" });
const val = (id) => page.textContent(`#${id}`);
const row = (n, k) => page.locator(`.avg-row:not(.avg-head)`).nth(n).locator(`[data-k="${k}"]`);

await page.fill("#list", "10\n12\n11\n87");
expect((await val("aritmetik-out")) === "30" && (await val("aritmetik-median")) === "11,5" && (await val("aritmetik-range")) === "77", `${label}: mean gave ${await val("aritmetik-out")}`);
expect((await val("aritmetik-formula")).includes("(10 + 12 + 11 + 87) ÷ 4 = 30"), `${label}: mean formula ${await val("aritmetik-formula")}`);
await page.fill("#list", "1, 2, 2");
expect((await val("aritmetik-out")) === "1,67" && (await val("aritmetik-mode")).startsWith("2") && (await val("aritmetik-formula")).includes("≈"), `${label}: rounding gave ${await val("aritmetik-out")}`);
await page.fill("#list", "1,5 -2,5");
expect((await val("aritmetik-out")) === "-0,5" && (await val("aritmetik-formula")).includes("(1,5 + (-2,5))"), `${label}: negatives gave ${await val("aritmetik-out")}`);
await page.fill("#list", "3,4,5");
expect((await val("aritmetik-out")) === "-" && (await val("aritmetik-status")).includes("3,4,5"), `${label}: bad list not reported`);

await row(0, "value").fill("50");
await row(0, "weight").fill("40");
await row(1, "value").fill("80");
await row(1, "weight").fill("60");
expect((await val("agirlikli-out")) === "68" && (await val("agirlikli-plain")) === "65", `${label}: weighted gave ${await val("agirlikli-out")}`);
await page.click("#add-row");
expect((await page.locator(".avg-row:not(.avg-head)").count()) === 4, `${label}: row not added`);
await row(3, "value").fill("100");
expect((await val("agirlikli-status")).includes("4."), `${label}: half row not reported`);
await row(3, "weight").fill("0");
expect((await val("agirlikli-out")) === "68", `${label}: zero weight changed the mean`);
await page.locator(".avg-row:not(.avg-head)").nth(3).locator(".avg-del").click();
expect((await page.locator(".avg-row:not(.avg-head)").count()) === 3, `${label}: row not removed`);
await row(1, "weight").fill("-1");
expect((await val("agirlikli-out")) === "-" && (await val("agirlikli-status")).length > 5, `${label}: negative weight not reported`);
await row(1, "weight").fill("60");
await page.selectOption("#digits", "0");
await page.reload({ waitUntil: "networkidle" });
expect((await page.inputValue("#digits")) === "0", `${label}: digits not remembered`);
expect((await page.inputValue("#list")) === "", `${label}: list was kept`);

await page.selectOption("#digits", "2");
await page.fill("#list", "12\n15\n9\n14\n10");
await row(0, "value").fill("50");
await row(0, "weight").fill("40");
await row(1, "value").fill("80");
await row(1, "weight").fill("60");
await page.screenshot({ path: `${shots}/tr-ortalama-${width}.png`, fullPage: true });
await langMenu(page, label, "tr", { en: "/", tr: ORTALAMA }, null);
finish(errors, label);
await context.close();
}

for (const path of OTHER) {
for (const width of [1440, 390]) {
const label = `${path} ${width}`;
const { context, page, errors } = await open(width, path, label);
await page.screenshot({ path: `${shots}/page${path.replace(/\//g, "_")}-${width}.png`, fullPage: true });
if (path !== "/missing-page") expect((await page.locator(".tool-card").count()) === 18, `${label}: index does not list every tool`);
if (path !== "/missing-page") expect((await page.locator(".tool-card").count()) === 19, `${label}: index does not list every tool`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/kdv-hesaplama/"]').count()) === 1, `${label}: index does not link KDV`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/yas-hesaplama/"]').count()) === 1, `${label}: index does not link yaş hesaplama`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/days-between-dates/"]').count()) === 1, `${label}: index does not link days between dates`);
Expand All @@ -1054,6 +1106,7 @@ for (const path of OTHER) {
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/karakter-sayaci/"]').count()) === 1, `${label}: index does not link the counter`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/word-frequency-counter/"]').count()) === 1, `${label}: index does not link the word frequency counter`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/yuzde-hesaplama/"]').count()) === 1, `${label}: index does not link yüzde hesaplama`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/ortalama-hesaplama/"]').count()) === 1, `${label}: index does not link ortalama hesaplama`);
const lang = path === "/tr/" ? "tr" : "en";
await langMenu(page, label, lang, HOME, `${shots}/menu${path.replace(/\//g, "_")}-${width}.png`);
finish(errors, label);
Expand Down
45 changes: 43 additions & 2 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,48 @@ ${cards}
</section>`;
}

const TOOL_BODY = { paste: pasteTool, linebreaks: lineBreaksTool, case: caseTool, color: colorTool, invisible: invisibleTool, repeater: repeaterTool, chmod: chmodTool, slug: slugTool, special: specialTool, counter: counterTool, frequency: frequencyTool, reverse: caseTool, flip: pasteTool, compare: compareTool, kdv: kdvTool, yas: yasTool, dates: datesTool, yuzde: pctTool };
const REMOVE = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="m4.5 4.5 7 7M11.5 4.5l-7 7"/></svg>`;

/** One weighted-mean row; the page script clones the first one, so the labels carry a {n} the script fills in. */
function avgRow(u, n) {
const label = (tpl) => esc(tpl.replace("{n}", n));
return `<div class="avg-row"><input class="input" type="text" inputmode="text" autocomplete="off" spellcheck="false" data-k="value" aria-label="${label(u.messages.valueRow)}" placeholder="${esc(u.valuePh[n - 1] ?? "")}"><input class="input" type="text" inputmode="decimal" autocomplete="off" spellcheck="false" data-k="weight" aria-label="${label(u.messages.weightRow)}" placeholder="${esc(u.weightPh[n - 1] ?? "")}"><button type="button" class="btn btn-quiet avg-del" aria-label="${label(u.messages.removeRow)}">${REMOVE}</button></div>`;
}

function avgTool(page) {
const u = page.ui;
const row = (card, id) => `<div class="calc-row"><dt>${esc(u.rowLabels[id])}</dt><dd id="${card}-${id}">-</dd></div>`;
const out = (card, label, rows) => `<div class="calc-out">
<div class="age-main"><span>${esc(label)}</span><strong id="${card}-out">-</strong><p id="${card}-sub"></p></div>
<dl>${rows.map((r) => row(card, r)).join("")}</dl>
<p class="formula" id="${card}-formula" aria-label="${esc(u.formula)}"></p>
<p class="status calc-status" id="${card}-status" role="status" aria-live="polite"></p>
</div>`;
const digits = [0, 1, 2, 3, 4].map((n) => `<option value="${n}"${n === 2 ? " selected" : ""}>${n}</option>`).join("");
return `<section class="tool pct" aria-label="${esc(u.toolLabel)}">
<div class="pct-bar"><p>${esc(u.barHint)}</p><label for="digits">${esc(u.digits)}</label><select id="digits" class="input">${digits}</select></div>
<div class="calc pct-card" id="aritmetik">
<div class="calc-in">
<div class="pct-head"><h3 id="aritmetik-title">${esc(u.mean.title)}</h3><p>${esc(u.mean.question)}</p></div>
<div class="field"><label for="list">${esc(u.mean.label)}</label><textarea id="list" class="input avg-list" rows="6" autocomplete="off" spellcheck="false" placeholder="${esc(u.mean.ph)}" aria-describedby="list-hint"></textarea><small id="list-hint">${esc(u.mean.hint)}</small></div>
</div>
${out("aritmetik", u.mean.result, ["count", "sum", "median", "mode", "min", "max", "range"])}
</div>
<div class="calc pct-card" id="agirlikli">
<div class="calc-in">
<div class="pct-head"><h3>${esc(u.weighted.title)}</h3><p>${esc(u.weighted.question)}</p></div>
<div class="avg-rows" role="group" aria-label="${esc(u.weighted.title)}">
<div class="avg-row avg-head" aria-hidden="true"><span>${esc(u.valueHead)}</span><span>${esc(u.weightHead)}</span><span></span></div>
${[1, 2, 3].map((n) => avgRow(u, n)).join("\n")}
</div>
<div><button type="button" class="btn btn-outline" id="add-row">${PLUS}${esc(u.addRow)}</button></div>
</div>
${out("agirlikli", u.weighted.result, ["weights", "products", "plain"])}
</div>
</section>`;
}

const TOOL_BODY = { paste: pasteTool, linebreaks: lineBreaksTool, case: caseTool, color: colorTool, invisible: invisibleTool, repeater: repeaterTool, chmod: chmodTool, slug: slugTool, special: specialTool, counter: counterTool, frequency: frequencyTool, reverse: caseTool, flip: pasteTool, compare: compareTool, kdv: kdvTool, yas: yasTool, dates: datesTool, yuzde: pctTool, ortalama: avgTool };

/** Prose, a list of titled rows with sources, and a dated note; the paste and compare pages build theirs from why and shortcuts. */
function infoSection(page, sec) {
Expand Down Expand Up @@ -913,7 +954,7 @@ function manifest(lang) {
};
}

const SCRIPTS = ["clean.js", "plain-text.js", "diff.js", "text-compare.js", "kdv.js", "kdv-hesaplama.js", "yas.js", "yas-hesaplama.js", "date-diff.js", "days-between-dates.js", "line-breaks.js", "remove-line-breaks.js", "case.js", "case-converter.js", "color.js", "hex-to-rgb.js", "invisible.js", "invisible-character.js", "repeat.js", "text-repeater.js", "reverse.js", "reverse-text.js", "flip.js", "upside-down-text.js", "chmod.js", "chmod-calculator.js", "slug.js", "slug-generator.js", "special.js", "remove-special-characters.js", "count.js", "karakter-sayaci.js", "frequency.js", "word-frequency-counter.js", "sayi.js", "yuzde.js", "yuzde-hesaplama.js", "nav.js"];
const SCRIPTS = ["clean.js", "plain-text.js", "diff.js", "text-compare.js", "kdv.js", "kdv-hesaplama.js", "yas.js", "yas-hesaplama.js", "date-diff.js", "days-between-dates.js", "line-breaks.js", "remove-line-breaks.js", "case.js", "case-converter.js", "color.js", "hex-to-rgb.js", "invisible.js", "invisible-character.js", "repeat.js", "text-repeater.js", "reverse.js", "reverse-text.js", "flip.js", "upside-down-text.js", "chmod.js", "chmod-calculator.js", "slug.js", "slug-generator.js", "special.js", "remove-special-characters.js", "count.js", "karakter-sayaci.js", "frequency.js", "word-frequency-counter.js", "sayi.js", "yuzde.js", "yuzde-hesaplama.js", "ortalama.js", "ortalama-hesaplama.js", "nav.js"];
const sha = (...parts) => {
const h = createHash("sha256");
for (const p of parts) h.update(p);
Expand Down
Loading