From 2279b54360c0246c317d6ee397df5c955c37b8b1 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 29 Oct 2024 01:52:11 -0400 Subject: [PATCH] 5.12.4 improved browser sort selection --- css/popup.css | 15 +++++-- html/popup.html | 43 ++++++++++++------- js/background.js | 15 ------- js/popup.js | 106 +++++++++++++++++++++++++++++++++++++++++------ manifest.json | 2 +- 5 files changed, 136 insertions(+), 45 deletions(-) diff --git a/css/popup.css b/css/popup.css index 9f0bcdb..6e04185 100644 --- a/css/popup.css +++ b/css/popup.css @@ -96,10 +96,18 @@ h2 {margin-top: 20px;font-weight:600} .theme-button:hover {background-size: 120%; background-position:center;} .theme-button-creator {font-size:10px;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-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-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} .color-options .card-input { flex: 1;margin: 0;} .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;} #error_log_output, #rk_output {min-height: 100px;} #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;} .custom-card-header {display: flex; justify-content: space-between;gap: 20px;} .sidebar-changer {display: flex;gap: 10px;} @@ -162,7 +170,8 @@ input[type="checkbox"]:checked {background: #8dd28d;} #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-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-track {background: #161616;} diff --git a/html/popup.html b/html/popup.html index f6ba536..c6a9983 100644 --- a/html/popup.html +++ b/html/popup.html @@ -314,6 +314,19 @@
- +
+
Popular
+
Liked
+
New
+
Old
+
ABC
- - - +
@@ -1023,4 +1038,4 @@ - + \ No newline at end of file diff --git a/js/background.js b/js/background.js index 7ab7906..f3f14e0 100644 --- a/js/background.js +++ b/js/background.js @@ -107,21 +107,6 @@ chrome.runtime.onInstalled.addListener(function () { 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) { chrome.storage.local.set(newLocalOptions); } diff --git a/js/popup.js b/js/popup.js index 650d139..43a473e 100644 --- a/js/popup.js +++ b/js/popup.js @@ -469,9 +469,19 @@ function setup() { }); // theme browser controls - document.getElementById("premade-themes-left").addEventListener("click", () => displayThemeList(-1)); - document.getElementById("premade-themes-right").addEventListener("click", () => displayThemeList(1)); - document.getElementById("theme-sorts").addEventListener("click", () => sortThemes(current_sort)); + document.getElementById("premade-themes-left").addEventListener("click", () => changePage(-1)); + document.getElementById("premade-themes-right").addEventListener("click", () => changePage(1)); + 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) => { searchFor = e.target.value; current_page_num = 1; @@ -484,6 +494,14 @@ function setup() { // activate submit theme button 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 document.getElementById("submit-title").addEventListener("input", (e) => { document.getElementById("theme-button-title-preview").textContent = e.target.value.replaceAll(" ", ""); @@ -517,6 +535,12 @@ function setup() { // activate theme browser opt in 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) { @@ -548,6 +572,17 @@ async function getExport(storage, options) { return final; } +let pageTimeout = false; + +function changePage(direction) { + if (pageTimeout) return; + pageTimeout = true; + displayThemeList(direction); + setTimeout(() => { + pageTimeout = false; + }, 500); +} + const colorValues = { "red": 1, "pink": 2, @@ -597,6 +632,22 @@ function themeSortFn(method) { 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) { const sortMethods = ["Popular", "ABC", "New", "Old"]; const index = sortMethods.indexOf(method); @@ -616,6 +667,7 @@ function sortThemes(method) { displayThemeList(0); //cache = {}; } + */ // shuffle function for the score sorting so theres no order bias function shuffle (arr) { @@ -686,6 +738,7 @@ async function submitTheme() { console.log(data); 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."); + document.getElementById("submit-popup").classList.remove("open"); } else { 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 { const res = await fetch(`${apiurl}/api/register`); const data = await res.json(); - await chrome.storage.sync.set({ "new_browser": true, "id": data.id }); - 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!"); + + chrome.storage.sync.set({ "id": data.id }).then(async () => { + // test to see if the id was set correctly + // don't know why this is happening ?? + 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) { 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++; 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 - if (cache[apiLink]) { - themes = cache[apiLink]; + themes = cache[apiLink]["themes"]; + maxPage = cache[apiLink]["pages"] || maxPage; } else { try { const res = await fetch(`${apiurl}/api/themes/${apiLink}`, { @@ -855,7 +933,7 @@ async function displayThemeListNew(direction) { const data = await res.json(); if (data.errors === true) throw new Error(data.message); themes = data.message.themes; - cache[apiLink] = themes; + cache[apiLink] = data.message; if (data?.message?.pages) { maxPage = data.message.pages; } @@ -887,6 +965,10 @@ async function displayThemeListNew(direction) { }); + if (themes.length === 0) { + container.innerHTML = `
Nothing here
`; + } + document.getElementById("premade-themes-pagenum").textContent = current_page_num + " of " + maxPage; // set the submit theme button to the first custom card image diff --git a/manifest.json b/manifest.json index 56e9ffe..7ff402b 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Better Canvas", "description": "Feature packed extension for Canvas.", - "version": "5.12.1", + "version": "5.12.4", "icons": { "16": "icon/icon-16.png", "32": "icon/icon-32.png",