mirror of
https://github.com/GuySandler/CanvasRefined.git
synced 2026-06-22 10:19:53 +02:00
5.12.1
efficiency fixes + theme like ID was set to my personal id instead of the user's ID
This commit is contained in:
parent
9aa394127c
commit
c8021504e5
72
js/popup.js
72
js/popup.js
@ -614,7 +614,7 @@ function sortThemes(method) {
|
|||||||
});
|
});
|
||||||
current_page_num = 1;
|
current_page_num = 1;
|
||||||
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
|
||||||
@ -761,44 +761,74 @@ function createThemeLikeBtn(location, initial, score) {
|
|||||||
return likeBtn;
|
return likeBtn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let likeThemeTimeout = false;
|
||||||
|
|
||||||
async function likeTheme(location, code, score) {
|
async function likeTheme(location, code, score) {
|
||||||
|
|
||||||
|
if (likeThemeTimeout === true) return;
|
||||||
|
|
||||||
const sync = await chrome.storage.sync.get("id");
|
const sync = await chrome.storage.sync.get("id");
|
||||||
const local = await chrome.storage.local.get("liked_themes");
|
const local = await chrome.storage.local.get("liked_themes");
|
||||||
|
|
||||||
|
const setLikeStatus = (direction) => {
|
||||||
|
|
||||||
|
let output = local;
|
||||||
|
|
||||||
|
if (direction === -1) {
|
||||||
|
const index = local["liked_themes"].indexOf(code);
|
||||||
|
location.classList.remove("theme-liked");
|
||||||
|
location.querySelector(".theme-button-like-amount").textContent = shortScore(score);
|
||||||
|
if (index !== -1) output = local["liked_themes"].filter(x => x !== code);
|
||||||
|
} else if (direction === 1) {
|
||||||
|
location.classList += (" theme-liked animate-like");
|
||||||
|
location.querySelector(".theme-button-like-amount").textContent = shortScore(score + 1);
|
||||||
|
output = [...local["liked_themes"], code];
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// show the updated like status immediately
|
||||||
|
setLikeStatus(location.classList.contains("theme-liked") ? -1 : 1);
|
||||||
|
|
||||||
const res = await fetch(`${apiurl}/api/themes/theme/${code}/like`, {
|
const res = await fetch(`${apiurl}/api/themes/theme/${code}/like`, {
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"body": JSON.stringify({"id": "2hkJkfJhwffc7cCC4os49vGfss2"}),
|
"body": JSON.stringify({ "id": sync["id"] }),
|
||||||
"headers": {
|
"headers": {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const direction = parseInt(data.message);
|
|
||||||
const likeBtn = location;
|
|
||||||
|
|
||||||
let output;
|
if (data.errors === false) {
|
||||||
|
const direction = parseInt(data.message);
|
||||||
if (data.errors === true) {
|
// update the like status just in case there is some disagreement with the server
|
||||||
|
chrome.storage.local.set({ "liked_themes": setLikeStatus(direction) });
|
||||||
} else if (direction === -1) {
|
}
|
||||||
const index = local["liked_themes"].indexOf(code);
|
|
||||||
likeBtn.classList.remove("theme-liked");
|
|
||||||
likeBtn.querySelector(".theme-button-like-amount").textContent = shortScore(score);
|
if (likeThemeTimeout === false) {
|
||||||
if (index !== -1) output = local["liked_themes"].filter(x => x !== code);
|
likeThemeTimeout = true;
|
||||||
} else if (direction === 1) {
|
setTimeout(() => {
|
||||||
likeBtn.classList += (" theme-liked animate-like");
|
likeThemeTimeout = false;
|
||||||
likeBtn.querySelector(".theme-button-like-amount").textContent = shortScore(score + 1);
|
}, 1000);
|
||||||
output = [...local["liked_themes"], code];
|
|
||||||
}
|
}
|
||||||
chrome.storage.local.set({ "liked_themes": output });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAndLoadTheme(code) {
|
async function getAndLoadTheme(code) {
|
||||||
const res = await fetch(`${apiurl}/api/themes/theme/${code}`);
|
const key = `themes/${code}`;
|
||||||
const data = await res.json();
|
let output = {};
|
||||||
importTheme(JSON.parse(data.message.exports));
|
if (cache[key]) {
|
||||||
|
output = cache[key];
|
||||||
|
console.log("got this theme from the cache.");
|
||||||
|
} else {
|
||||||
|
const res = await fetch(`${apiurl}/api/themes/theme/${code}`);
|
||||||
|
const data = await res.json();
|
||||||
|
output = JSON.parse(data.message.exports);
|
||||||
|
cache[key] = output;
|
||||||
|
}
|
||||||
|
importTheme(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function displayThemeListNew(direction) {
|
async function displayThemeListNew(direction) {
|
||||||
|
|||||||
@ -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.0",
|
"version": "5.12.1",
|
||||||
"icons": {
|
"icons": {
|
||||||
"16": "icon/icon-16.png",
|
"16": "icon/icon-16.png",
|
||||||
"32": "icon/icon-32.png",
|
"32": "icon/icon-32.png",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user