improved browser sort selection
This commit is contained in:
BuildTools committed 2024-10-29 01:52:11 -04:00
1 parent 992aeb6896
commit 2279b54360
5 files changed
+135 -44

No files matched your search

+12 -3
View File
@@ -96,10 +96,18 @@ h2 {margin-top: 20px;font-weight:600}
.theme-button:hover {background-size: 120%; background-position:center;} .theme-button:hover {background-size: 120%; background-position:center;}
.theme-button-creator {font-size:10px;white-space:nowrap} .theme-button-creator {font-size:10px;white-space:nowrap}
.theme-button-title {font-weight: 600;font-size:12px;white-space:nowrap;} .theme-button-title {font-weight: 600;font-size:12px;white-space:nowrap;}
.theme-sort-btn {padding:8px 16px;border-radius:7px;background:none;border:none;color: #9d9d9d;font-size:12px;font-weight:600;} .theme-sort-btn {padding:10px 30px 10px 20px;border-radius:7px;background:none;border:none;color: #9d9d9d;font-size:12px;font-weight:600;text-align: left;cursor: pointer;transition:.18s color}
.theme-sort-btn:hover {color: #fff;}
.theme-header {display:flex;justify-content: space-between;margin-bottom:10px;align-items:center} .theme-header {display:flex;justify-content: space-between;margin-bottom:10px;align-items:center}
.theme-controls {display:flex;justify-content: space-between;margin-bottom:6px;gap: 4px;} .theme-controls {display:flex;justify-content: space-between;margin-bottom:6px;gap: 4px;}
#theme-sorts {display:flex;align-items:center;background:var(--inputbg);border-radius: 7px;padding:10px 16px;gap:10px;color: #fff;border:none;font-weight: 600;} #theme-sorts {display:flex;align-items:center;background:var(--inputbg);border-radius: 7px;padding:10px 16px;gap:10px;color: #fff;border:none;font-weight: 600;}
#theme-sort-selector {display: none; position: absolute; top: 5px; right: -10px; transform: translateX(100%); z-index: 1000;background: #0e0e0edb;backdrop-filter:blur(3px);border-radius: 7px;padding:5px 0;}
#theme-sort-selector.open {display: block;}
#submit-popup {display: none;position: fixed;top:0;left:0;width:100%;height:100%;z-index:1000;background:#0e0e0eed;backdrop-filter:blur(3px)}
#submit-popup.open {display: flex;align-items:center;justify-content: center;}
#theme-sorts-container {position: relative;}
#themes-empty {grid-row: span 6; grid-column: span 4;display: flex;align-items:center;justify-content: center;}
.color-line {background:linear-gradient(115deg, rgb(255, 53, 88), rgb(255, 131, 73), rgb(255, 103, 187));width:100%;height:2px;border-radius:10px;}
#premade-themes-pagenum {font-size:13px;margin-right: 6px;font-weight:600} #premade-themes-pagenum {font-size:13px;margin-right: 6px;font-weight:600}
.color-options .card-input { flex: 1;margin: 0;} .color-options .card-input { flex: 1;margin: 0;}
.error-message {margin: 20px;font-size: 14px; color: red;} .error-message {margin: 20px;font-size: 14px; color: red;}
@@ -108,7 +116,7 @@ textarea {resize: vertical}
#premade-themes, #premade-darkmodes {display:grid;grid-template-columns: repeat(4, 1fr);gap: 3px;} #premade-themes, #premade-darkmodes {display:grid;grid-template-columns: repeat(4, 1fr);gap: 3px;}
#error_log_output, #rk_output {min-height: 100px;} #error_log_output, #rk_output {min-height: 100px;}
#image-tester {display: none;} #image-tester {display: none;}
#alert {font-size:13px;background: #e7495ebd; backdrop-filter: blur(1px); border-radius: 8px; padding: 15px; margin: 20px;position: fixed; transition: .3s bottom; bottom: -400px; left: 0;z-index:1000;} #alert {font-size:13px;background: #e7495ebd; backdrop-filter: blur(1px); border-radius: 8px; padding: 15px; margin: 20px;position: fixed; transition: .3s bottom; bottom: -400px; left: 0;z-index:100000;}
#alert:hover {cursor:pointer;} #alert:hover {cursor:pointer;}
.custom-card-header {display: flex; justify-content: space-between;gap: 20px;} .custom-card-header {display: flex; justify-content: space-between;gap: 20px;}
.sidebar-changer {display: flex;gap: 10px;} .sidebar-changer {display: flex;gap: 10px;}
@@ -162,7 +170,8 @@ input[type="checkbox"]:checked {background: #8dd28d;}
#opt-in a {color: inherit; text-decoration: underline;} #opt-in a {color: inherit; text-decoration: underline;}
#theme-search {flex: 1;border:none;background:none;height:100%;color:inherit;font-family:inherit;font-weight:600;width:100%;} #theme-search {flex: 1;border:none;background:none;height:100%;color:inherit;font-family:inherit;font-weight:600;width:100%;}
#theme-search-container {flex: 1;display:flex;gap:10px;box-sizing: border-box;width: 100%;margin:0;align-items:center;padding-left:10px;color:#818181;} #theme-search-container {flex: 1;display:flex;gap:10px;box-sizing: border-box;width: 100%;margin:0;align-items:center;padding-left:10px;color:#818181;}
#submit-theme-btn {width: 50%;margin-top:10px;} #submit-theme-btn, #cancel-theme-btn {flex: 1;}
#submit-theme-btn-1 {width: 50%;margin-top: 10px;}
::-webkit-scrollbar {width: 8px;} ::-webkit-scrollbar {width: 8px;}
::-webkit-scrollbar-track {background: #161616;} ::-webkit-scrollbar-track {background: #161616;}
+28 -13
View File
@@ -314,6 +314,19 @@
</div> </div>
<div class="import-export tab" style="display: none"> <div class="import-export tab" style="display: none">
<div id="submit-popup">
<div style="max-width: 75%;">
<h3 class="header-small">Submission confirmation</h3>
<div class="color-line"></div>
<p style="margin-top: 10px;color: #a7a7a7">Make sure everything is correct before submitting! You won't be able to edit it later unless you contact me.</p>
<p style="margin-top: 10px;color: #a7a7a7">Your submission will include your current thematic settings, such as your card images, dark mode, and font.</p>
<a style="color: #fff;display:block;margin-top:10px;" target="_blank" href="https://diditupe.dev/bettercanvas/questions/?highlight=2">Find theme guidelines here</a>
<div style="display: flex; gap: 5px;margin-top:10px;">
<button id="submit-theme-btn" class="big-button" style="width: 50%;">Submit</button>
<button id="cancel-theme-btn" class="big-button" style="width: 50%;">Cancel</button>
</div>
</div>
</div>
<div class="tab-header"> <div class="tab-header">
<h2 style="margin-top: 0" data-i18n="themes">Themes</h2> <h2 style="margin-top: 0" data-i18n="themes">Themes</h2>
<button class="big-button back-btn" data-i18n="back">Back</button> <button class="big-button back-btn" data-i18n="back">Back</button>
@@ -343,8 +356,7 @@
<input type="text" class="card-input" id="submit-credits"> <input type="text" class="card-input" id="submit-credits">
</div> </div>
<p style="margin-top:10px;color: #818181;">This will submit your current thematic settings, such as your card images, dark mode, and font.</p> <button id="submit-theme-btn-1" class="big-button">Submit</button>
<button id="submit-theme-btn" class="big-button" style="width: 50%;">Submit</button>
</div> </div>
<div style="min-width: 25%;"> <div style="min-width: 25%;">
<button id="theme-button-img" class="theme-button customization-button" <button id="theme-button-img" class="theme-button customization-button"
@@ -361,18 +373,21 @@
<span id="premade-themes-pagenum"></span> <span id="premade-themes-pagenum"></span>
</div> </div>
<div class="theme-controls"> <div class="theme-controls">
<button id="theme-sorts"> <div id="theme-sorts-container">
<div> <button id="theme-sorts">
<svg style="display: block" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-arrows-up-down"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 3l0 18" /><path d="M10 6l-3 -3l-3 3" /><path d="M20 18l-3 3l-3 -3" /><path d="M17 21l0 -18" /></svg> <div>
<svg style="display: block" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-arrows-up-down"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 3l0 18" /><path d="M10 6l-3 -3l-3 3" /><path d="M20 18l-3 3l-3 -3" /><path d="M17 21l0 -18" /></svg>
</div>
<span id="theme-current-sort"></span>
</button>
<div id="theme-sort-selector">
<div id="theme-sort-score" class="theme-sort-btn">Popular</div>
<div id="theme-sort-liked" class="theme-sort-btn">Liked</div>
<div id="theme-sort-new" class="theme-sort-btn">New</div>
<div id="theme-sort-old" class="theme-sort-btn">Old</div>
<div id="theme-sort-abc" class="theme-sort-btn">ABC</div>
</div> </div>
<span id="theme-current-sort"></span> </div>
<!--
<button id="theme-sort-score" class="theme-sort-btn">Rating</button>
<button id="theme-sort-color" class="theme-sort-btn">Color</button>
<button id="theme-sort-new" class="theme-sort-btn">New</button>
<button id="theme-sort-old" class="theme-sort-btn">Old</button>
-->
</button>
<div class="card-input" id="theme-search-container"> <div class="card-input" id="theme-search-container">
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-search"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" /><path d="M21 21l-6 -6" /></svg> <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-search"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" /><path d="M21 21l-6 -6" /></svg>
<input type="text" id="theme-search" placeholder="Search"> <input type="text" id="theme-search" placeholder="Search">
-15
View File
@@ -107,21 +107,6 @@ chrome.runtime.onInstalled.addListener(function () {
newLocalOptions[option] = default_options["local"][option]; newLocalOptions[option] = default_options["local"][option];
}) })
/*
// generates a unique id for the themes backend
if (sync["identifier"] === undefined) {
try {
await fetch("https://localhost:3000/api/identity")
.then(res => res.json())
.then(data => {
newSyncOptions["identifier"] = data.message;
})
} catch (e) {
}
}
*/
if (Object.keys(newLocalOptions).length > 0) { if (Object.keys(newLocalOptions).length > 0) {
chrome.storage.local.set(newLocalOptions); chrome.storage.local.set(newLocalOptions);
} }
+94 -12
View File
@@ -469,9 +469,19 @@ function setup() {
}); });
// theme browser controls // theme browser controls
document.getElementById("premade-themes-left").addEventListener("click", () => displayThemeList(-1)); document.getElementById("premade-themes-left").addEventListener("click", () => changePage(-1));
document.getElementById("premade-themes-right").addEventListener("click", () => displayThemeList(1)); document.getElementById("premade-themes-right").addEventListener("click", () => changePage(1));
document.getElementById("theme-sorts").addEventListener("click", () => sortThemes(current_sort)); document.getElementById("theme-sorts").addEventListener("click", () => {
const el = document.getElementById("theme-sort-selector");
if (el.classList.contains("open")) {
clickout();
} else {
el.classList.add("open");
setTimeout(() => {
document.addEventListener("click", clickout);
}, 10);
}
});
document.getElementById("theme-search").addEventListener("change", async (e) => { document.getElementById("theme-search").addEventListener("change", async (e) => {
searchFor = e.target.value; searchFor = e.target.value;
current_page_num = 1; current_page_num = 1;
@@ -484,6 +494,14 @@ function setup() {
// activate submit theme button // activate submit theme button
document.getElementById("submit-theme-btn").addEventListener("click", submitTheme); document.getElementById("submit-theme-btn").addEventListener("click", submitTheme);
document.getElementById("submit-theme-btn-1").addEventListener("click", () => {
document.getElementById("submit-popup").classList.add("open");
});
document.getElementById("cancel-theme-btn").addEventListener("click", () => {
document.getElementById("submit-popup").classList.remove("open");
})
// update theme button preview on input // update theme button preview on input
document.getElementById("submit-title").addEventListener("input", (e) => { document.getElementById("submit-title").addEventListener("input", (e) => {
document.getElementById("theme-button-title-preview").textContent = e.target.value.replaceAll(" ", ""); document.getElementById("theme-button-title-preview").textContent = e.target.value.replaceAll(" ", "");
@@ -517,6 +535,12 @@ function setup() {
// activate theme browser opt in // activate theme browser opt in
document.getElementById("new_browser_in").addEventListener("click", registerUser); document.getElementById("new_browser_in").addEventListener("click", registerUser);
document.querySelectorAll(".theme-sort-btn").forEach(btn => {
btn.addEventListener("click", (e) => {
themeSort(e.target.textContent);
});
});
} }
async function getExport(storage, options) { async function getExport(storage, options) {
@@ -548,6 +572,17 @@ async function getExport(storage, options) {
return final; return final;
} }
let pageTimeout = false;
function changePage(direction) {
if (pageTimeout) return;
pageTimeout = true;
displayThemeList(direction);
setTimeout(() => {
pageTimeout = false;
}, 500);
}
const colorValues = { const colorValues = {
"red": 1, "red": 1,
"pink": 2, "pink": 2,
@@ -597,6 +632,22 @@ function themeSortFn(method) {
let cache = {}; let cache = {};
// new theme sort button
function themeSort(sort) {
current_sort = sort;
current_page_num = 1;
allThemes = themeSortFn(current_sort);
displayThemeList(0);
}
function clickout() {
setTimeout(() => {
document.getElementById("theme-sort-selector").classList.remove("open");
document.removeEventListener("click", clickout);
}, 10);
}
/*
function sortThemes(method) { function sortThemes(method) {
const sortMethods = ["Popular", "ABC", "New", "Old"]; const sortMethods = ["Popular", "ABC", "New", "Old"];
const index = sortMethods.indexOf(method); const index = sortMethods.indexOf(method);
@@ -616,6 +667,7 @@ function sortThemes(method) {
displayThemeList(0); displayThemeList(0);
//cache = {}; //cache = {};
} }
*/
// shuffle function for the score sorting so theres no order bias // shuffle function for the score sorting so theres no order bias
function shuffle (arr) { function shuffle (arr) {
@@ -686,6 +738,7 @@ async function submitTheme() {
console.log(data); console.log(data);
if (data.errors === false) { if (data.errors === false) {
displayAlert(false, "Thanks for submitting your theme! I will try to approve it soon, but not every theme may be accepted."); displayAlert(false, "Thanks for submitting your theme! I will try to approve it soon, but not every theme may be accepted.");
document.getElementById("submit-popup").classList.remove("open");
} else { } else {
displayAlert(true, `There was an error submitting your theme. (${data.message}) Please send an email to ksucpea@gmail.com if this issue persists!`); displayAlert(true, `There was an error submitting your theme. (${data.message}) Please send an email to ksucpea@gmail.com if this issue persists!`);
} }
@@ -696,11 +749,25 @@ async function registerUser() {
try { try {
const res = await fetch(`${apiurl}/api/register`); const res = await fetch(`${apiurl}/api/register`);
const data = await res.json(); const data = await res.json();
await chrome.storage.sync.set({ "new_browser": true, "id": data.id });
document.getElementById("opt-in").remove(); chrome.storage.sync.set({ "id": data.id }).then(async () => {
current_page_num = 1; // test to see if the id was set correctly
displayThemeList(0); // don't know why this is happening ??
displayAlert(false, "Success! You should be able to see the new themes browser now. Enjoy!"); const test = await chrome.storage.sync.get("id");
if (test["id"] === undefined || test["id"] === "") throw new Error();
// show the new browser
chrome.storage.sync.set({ "new_browser": true }).then(() => {
document.getElementById("opt-in").remove();
current_page_num = 1;
displayThemeList(0);
displayAlert(false, "Success! You should be able to see the new themes browser now. Enjoy!");
});
}).catch(e => {
displayAlert(true, "There was an error connecting an ID to your account. Please try again, and if this error persists, contact ksucpea@gmail.com!");
});
} catch (e) { } catch (e) {
displayAlert(true, "There was an error opting in. Please contact ksucpea@gmail.com if this error persists!"); displayAlert(true, "There was an error opting in. Please contact ksucpea@gmail.com if this error persists!");
} }
@@ -838,12 +905,23 @@ async function displayThemeListNew(direction) {
if (direction === 1 && current_page_num < maxPage) current_page_num++; if (direction === 1 && current_page_num < maxPage) current_page_num++;
let themes = []; let themes = [];
const apiLink = `${current_sort.toLowerCase()}?page=${current_page_num}` + (searchFor === "" ? "" : `&searchFor=${searchFor}`); let apiLink = `${current_sort.toLowerCase()}?page=${current_page_num}` + (searchFor === "" ? "" : `&searchFor=${searchFor}`);
if (current_sort === "Liked") {
const sync = await chrome.storage.sync.get("id");
const local = await chrome.storage.local.get("liked_themes");
if (sync["id"] && sync["id"] !== "") {
apiLink += `&id=${sync["id"]}`;
maxPage = Math.ceil(local["liked_themes"].length / 28);
} else { // fallback if there is no id
current_page_num = 1;
apiLink = `popular?page=${current_page_num}` + (searchFor === "" ? "" : `&searchFor=${searchFor}`);
}
}
// fetch api, fallback if necessary // fetch api, fallback if necessary
if (cache[apiLink]) { if (cache[apiLink]) {
themes = cache[apiLink]; themes = cache[apiLink]["themes"];
maxPage = cache[apiLink]["pages"] || maxPage;
} else { } else {
try { try {
const res = await fetch(`${apiurl}/api/themes/${apiLink}`, { const res = await fetch(`${apiurl}/api/themes/${apiLink}`, {
@@ -855,7 +933,7 @@ async function displayThemeListNew(direction) {
const data = await res.json(); const data = await res.json();
if (data.errors === true) throw new Error(data.message); if (data.errors === true) throw new Error(data.message);
themes = data.message.themes; themes = data.message.themes;
cache[apiLink] = themes; cache[apiLink] = data.message;
if (data?.message?.pages) { if (data?.message?.pages) {
maxPage = data.message.pages; maxPage = data.message.pages;
} }
@@ -887,6 +965,10 @@ async function displayThemeListNew(direction) {
}); });
if (themes.length === 0) {
container.innerHTML = `<div id="themes-empty">Nothing here</div>`;
}
document.getElementById("premade-themes-pagenum").textContent = current_page_num + " of " + maxPage; document.getElementById("premade-themes-pagenum").textContent = current_page_num + " of " + maxPage;
// set the submit theme button to the first custom card image // set the submit theme button to the first custom card image
+1 -1
View File
@@ -2,7 +2,7 @@
"manifest_version": 3, "manifest_version": 3,
"name": "Better Canvas", "name": "Better Canvas",
"description": "Feature packed extension for Canvas.", "description": "Feature packed extension for Canvas.",
"version": "5.12.1", "version": "5.12.4",
"icons": { "icons": {
"16": "icon/icon-16.png", "16": "icon/icon-16.png",
"32": "icon/icon-32.png", "32": "icon/icon-32.png",