Skip to content

Commit

Permalink
Better indicator for disabled; @homepageURL
Browse files Browse the repository at this point in the history
  • Loading branch information
PRO-2684 committed Jul 6, 2024
1 parent 962f1e5 commit bf48ffe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
30 changes: 23 additions & 7 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ async function onSettingWindowCreated(view) {
more.title = title;
return more;
}
const homepage = addTransitioMore("🔗", "打开样式主页", "transitio-homepage");
homepage.addEventListener("click", () => {
if (!details.hasAttribute("data-deleted") && !homepage.hasAttribute("disabled")) {
transitio.open("link", homepage.getAttribute("data-homepage-url"));
}
});
const remove = addTransitioMore("🗑️", "删除此样式", "transitio-remove");
remove.addEventListener("click", () => {
if (!details.hasAttribute("data-deleted")) {
Expand Down Expand Up @@ -127,7 +133,7 @@ async function onSettingWindowCreated(view) {
const { path, meta, enabled } = args;
const isDeleted = meta.name === " [已删除] ";
const details = $(`details[${configDataAttr}="${path}"]`) || addItem(path);
// Summary part
// Summary part - Name and Description
const item = details.querySelector("setting-item");
const itemName = item.querySelector("setting-text");
const optionalVersion = meta.version ? ` (v${meta.version})` : "";
Expand All @@ -136,21 +142,31 @@ async function onSettingWindowCreated(view) {
const itemDesc = item.querySelector("setting-text[data-type='secondary']");
itemDesc.textContent = meta.description || "此文件没有描述";
itemDesc.title = itemDesc.textContent;
// Summary part - More
const homepage = item.querySelector("span.transitio-homepage");
const url = meta.homepageURL;
if (url && (url.startsWith("https://") || url.startsWith("http://"))) {
homepage.setAttribute("data-homepage-url", url);
homepage.toggleAttribute("disabled", false);
} else {
homepage.removeAttribute("data-homepage-url");
homepage.toggleAttribute("disabled", true);
}
const configureBtn = item.querySelector("span.transitio-configure");
const noVariables = Object.keys(meta.variables).length === 0;
configureBtn.toggleAttribute("disabled", noVariables);
const switch_ = item.querySelector(`setting-switch[${switchDataAttr}="${path}"]`);
switch_.toggleAttribute("is-active", enabled);
switch_.parentNode.classList.toggle("is-loading", false);
if (isDeleted) {
details.toggleAttribute("data-deleted", true);
}
// Details part
for (const variable of Array.from(details.children)) { // Remove all existing variables
if (variable.tagName === "SETTING-ITEM") {
variable.remove();
for (const el of Array.from(details.children)) { // Remove all existing variables
if (el.tagName === "SETTING-ITEM") {
el.remove();
}
}
const configureBtn = item.querySelector("span.transitio-configure");
const noVariables = Object.keys(meta.variables).length === 0;
configureBtn.toggleAttribute("disabled", noVariables);
if (noVariables) { // Close the details if there are no variables
details.toggleAttribute("open", false);
}
Expand Down
1 change: 1 addition & 0 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
}

&[disabled] {
opacity: 0.3;
cursor: not-allowed;
}
}
Expand Down

0 comments on commit bf48ffe

Please sign in to comment.