mirror of
https://github.com/GuySandler/CanvasRefined.git
synced 2026-11-25 07:07:14 +01:00
some UI changes
This commit is contained in:
1 parent
2c65b5ab17
commit
433ff17f65
15 files changed
+118
No files matched your search
@@ -72,6 +72,7 @@ chrome.runtime.onInstalled.addListener(function () {
|
||||
// "todo_overdues": false,
|
||||
"card_overdues": false,
|
||||
"relative_dues": false,
|
||||
"equal_height_cards": false,
|
||||
"hide_feedback": false,
|
||||
"dark_mode_fix": [],
|
||||
"assignment_states": {},
|
||||
|
||||
@@ -663,6 +663,11 @@ function applyOptionsChanges(changes) {
|
||||
cardAssignments = preloadAssignmentEls();
|
||||
loadCardAssignments();
|
||||
break;
|
||||
case "equal_height_cards":
|
||||
// No need to rebuild the assignment rows — just stretch (or reset)
|
||||
// the card heights in place for a snappy toggle.
|
||||
equalizeCardHeights();
|
||||
break;
|
||||
case "custom_cards":
|
||||
case "custom_cards_2":
|
||||
case "custom_cards_3":
|
||||
@@ -3537,6 +3542,51 @@ function createCardAssignment(assignment) {
|
||||
|
||||
let cardAssignments;
|
||||
|
||||
/*
|
||||
Equal Height Cards — when enabled, every dashboard card's assignment area is
|
||||
stretched to match the tallest one so cards with fewer assignments don't end
|
||||
up shorter than the rest. Uses min-height (never a fixed height) so cards can
|
||||
still grow if their content exceeds the tallest card.
|
||||
*/
|
||||
let equalHeightResizeTimer = null;
|
||||
|
||||
function equalizeCardHeights() {
|
||||
const cards = document.querySelectorAll(".ic-DashboardCard");
|
||||
if (cards.length === 0) return;
|
||||
|
||||
const enabled = options.equal_height_cards === true && options.assignments_due === true;
|
||||
|
||||
// Always clear any previously applied min-height first so we can either
|
||||
// measure natural heights (when enabling) or fully reset (when disabling).
|
||||
cards.forEach(card => {
|
||||
const area = card.querySelector(".canvasrefined-card-assignment");
|
||||
if (area) area.style.removeProperty("min-height");
|
||||
});
|
||||
|
||||
if (!enabled) return;
|
||||
|
||||
// Measure the natural height of each card's assignment area, then stretch
|
||||
// every area to the tallest one. Card headers are uniform, so equalizing
|
||||
// the assignment area makes all cards the same total height.
|
||||
let maxHeight = 0;
|
||||
cards.forEach(card => {
|
||||
const area = card.querySelector(".canvasrefined-card-assignment");
|
||||
if (area) maxHeight = Math.max(maxHeight, area.offsetHeight);
|
||||
});
|
||||
|
||||
if (maxHeight > 0) {
|
||||
cards.forEach(card => {
|
||||
const area = card.querySelector(".canvasrefined-card-assignment");
|
||||
if (area) area.style.minHeight = maxHeight + "px";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("resize", () => {
|
||||
if (equalHeightResizeTimer) clearTimeout(equalHeightResizeTimer);
|
||||
equalHeightResizeTimer = setTimeout(equalizeCardHeights, 150);
|
||||
});
|
||||
|
||||
function preloadAssignmentEls() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let assignmentEls = {};
|
||||
@@ -3569,6 +3619,7 @@ function loadCardAssignments() {
|
||||
document.querySelectorAll(".canvasrefined-card-assignment").forEach(card => {
|
||||
card.style.display = "none";
|
||||
});
|
||||
equalizeCardHeights();
|
||||
return;
|
||||
}
|
||||
setupCardAssignments();
|
||||
@@ -3608,6 +3659,9 @@ function loadCardAssignments() {
|
||||
let assignmentDivLink = makeElement("a", assignmentContainer, { "className": "canvasrefined-assignment-link", "textContent": "None" });
|
||||
}
|
||||
});
|
||||
// Wait one frame so the browser lays out the freshly appended
|
||||
// assignment rows before measuring/equalizing card heights.
|
||||
requestAnimationFrame(equalizeCardHeights);
|
||||
} catch (e) {
|
||||
logError(e);
|
||||
}
|
||||
|
||||
+26
@@ -6,6 +6,7 @@ const syncedSubOptions = [
|
||||
"device_dark",
|
||||
"relative_dues",
|
||||
"card_overdues",
|
||||
"equal_height_cards",
|
||||
// "todo_overdues",
|
||||
"gpa_calc_prepend",
|
||||
"auto_dark",
|
||||
@@ -112,6 +113,7 @@ const defaultOptions = {
|
||||
// "todo_overdues": false,
|
||||
"card_overdues": false,
|
||||
"relative_dues": false,
|
||||
"equal_height_cards": false,
|
||||
"hide_feedback": false,
|
||||
"dark_mode_fix": [],
|
||||
"assignment_states": {},
|
||||
@@ -412,6 +414,25 @@ function toggleBetterTodoSubOptions(betterTodoOn) {
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the sub-options of a big toggle when it is turned off.
|
||||
// For gpa_calc / assignments_due / better_todo the whole .sub-options block is
|
||||
// hidden. For auto_dark ("schedule dark mode") only the start/end time clocks
|
||||
// (.timesets) are hidden, leaving the device-dark checkbox visible.
|
||||
function toggleSubOptionsVisibility(option, isOn) {
|
||||
const togglesWithSubOptions = ["gpa_calc", "assignments_due", "better_todo", "auto_dark"];
|
||||
if (!togglesWithSubOptions.includes(option)) return;
|
||||
const optionEl = document.getElementById(option);
|
||||
if (!optionEl) return;
|
||||
const subOptions = optionEl.parentElement.querySelector(":scope > .sub-options");
|
||||
if (!subOptions) return;
|
||||
if (option === "auto_dark") {
|
||||
const timesets = subOptions.querySelector(".timesets");
|
||||
if (timesets) timesets.style.display = isOn ? "" : "none";
|
||||
} else {
|
||||
subOptions.style.display = isOn ? "" : "none";
|
||||
}
|
||||
}
|
||||
|
||||
function setup() {
|
||||
|
||||
const menu = {
|
||||
@@ -428,6 +449,7 @@ function setup() {
|
||||
"device_dark",
|
||||
"relative_dues",
|
||||
"card_overdues",
|
||||
"equal_height_cards",
|
||||
// "todo_overdues",
|
||||
"gpa_calc_prepend",
|
||||
"auto_dark",
|
||||
@@ -563,10 +585,14 @@ function setup() {
|
||||
if (option === "better_todo") {
|
||||
toggleBetterTodoSubOptions(status);
|
||||
}
|
||||
toggleSubOptionsVisibility(option, status);
|
||||
});
|
||||
});
|
||||
toggleBetterSidebarSubOptions(sync["better_sidebar"] === true);
|
||||
toggleBetterTodoSubOptions(sync["better_todo"] === true);
|
||||
["gpa_calc", "assignments_due", "better_todo", "auto_dark"].forEach(opt => {
|
||||
toggleSubOptionsVisibility(opt, sync[opt] === true);
|
||||
});
|
||||
});
|
||||
|
||||
chrome.storage.sync.get(menu.checkboxes, sync => {
|
||||
|
||||
Reference in new issue
Block a user