Skip to content
This repository was archived by the owner on Aug 10, 2026. It is now read-only.

Commit a2d197a

Browse files
author
fct-ai
authored
Merge pull request #30 from readme-SVG/codex/add-percentage-filling-option/2026-03-13
Add configurable Fill % control for randomized Fill action
2 parents 064c169 + 3d31699 commit a2d197a

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

css/styles.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
.stat b { color: var(--text); font-weight: 600; }
7676

7777
/* BUTTONS */
78-
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
78+
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
79+
.fill-percent-control { display: inline-flex; align-items: center; gap: 6px; color: var(--text2); font-size: 12px; }
80+
.fill-percent-control input { width: 70px; height: 34px; }
7981
button { height: 34px; padding: 0 16px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--bg3); color: var(--text); transition: background .15s, opacity .15s; white-space: nowrap; }
8082
button:hover { background: #30363d; }
8183
button:disabled { opacity: .4; cursor: not-allowed; }

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ <h1>GitHub Contribution Painter</h1>
129129
<div class="btn-row">
130130
<button class="danger" id="clearBtn" data-i18n="btn_clear">Clear</button>
131131
<button id="fillBtn" data-i18n="btn_fill">Fill all</button>
132+
<label class="fill-percent-control" for="fillPercent">
133+
<span>Fill %</span>
134+
<input id="fillPercent" type="text" value="100%" inputmode="decimal" aria-label="Fill percentage" />
135+
</label>
132136
<button class="primary" id="pushBtn" data-i18n="btn_push">▶ Apply to GitHub</button>
133137
</div>
134138
<div class="progress" id="progress">

js/app.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ function paint(cell){
134134
updateStats();
135135
}
136136

137+
138+
function getFillPercent(){
139+
const input = document.getElementById('fillPercent');
140+
const parsed = Number.parseFloat(input.value.replace(',', '.'));
141+
const safe = Number.isFinite(parsed) ? Math.min(100, Math.max(0, parsed)) : 100;
142+
input.value = `${safe}%`;
143+
return safe;
144+
}
145+
146+
function pickRandomCells(cells, count){
147+
const pool = [...cells];
148+
for(let i = pool.length - 1; i > 0; i--){
149+
const j = Math.floor(Math.random() * (i + 1));
150+
[pool[i], pool[j]] = [pool[j], pool[i]];
151+
}
152+
return pool.slice(0, count);
153+
}
154+
137155
function updateStats(){
138156
const mult = +document.getElementById('multiplier').value;
139157
const isSpreadEnabled = document.getElementById('commitSpread').value === 'plus2';
@@ -171,11 +189,21 @@ document.getElementById('clearBtn').addEventListener('click', ()=>{
171189
updateStats(); setStatus('');
172190
});
173191
document.getElementById('fillBtn').addEventListener('click', ()=>{
174-
document.querySelectorAll('.cell:not(.out)').forEach(c=>{
192+
const fillPercent = getFillPercent();
193+
const activeCells = [...document.querySelectorAll('.cell:not(.out)')];
194+
const targetCount = Math.round(activeCells.length * (fillPercent / 100));
195+
const picked = new Set(pickRandomCells(activeCells, targetCount));
196+
197+
activeCells.forEach(c=>{
175198
const i = +c.dataset.i;
176-
const level = resolveLevel();
177-
grid[i] = level;
178-
c.style.background = COLORS[level];
199+
if(picked.has(c)){
200+
const level = resolveLevel();
201+
grid[i] = level;
202+
c.style.background = COLORS[level];
203+
return;
204+
}
205+
grid[i] = 0;
206+
c.style.background = COLORS[0];
179207
});
180208
updateStats();
181209
});

0 commit comments

Comments
 (0)