Skip to content

Commit

Permalink
release: 1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
HananoshikaYomaru committed Dec 15, 2023
1 parent 8c43131 commit 50237ec
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 79 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "better-plugins-page",
"name": "Better Plugins Page",
"version": "1.0.9",
"version": "1.0.10",
"minAppVersion": "0.15.0",
"description": "Better Plugins Page for Obsidian, add filtering and hiding to the page",
"author": "HananoshikaYomaru",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-better-plugins-page",
"version": "1.0.9",
"version": "1.0.10",
"description": "Better Plugins Page for Obsidian, add filtering and hiding to the page",
"main": "main.js",
"scripts": {
Expand Down
122 changes: 46 additions & 76 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,84 +94,66 @@ export default class BetterPluginsPagePlugin extends Plugin {

debouncedFilterPlugins = debounce(
() => {
const that = this;
const communityItems = $(".community-item");
// Get all community items and store them in an array
const communityItems = Array.from(
document.querySelectorAll(".community-item")
);
try {
this.lock = true;
// console.log("debouncedFilterHiddenPlugins");

// Get filter options from localStorage
const downloadCountCompare =
localStorage.getItem("download-count-compare") ??
DownloadCountCompareOption.greater;
const downloadCount =
localStorage.getItem("download-count") ?? "";
const downloadCountValue = parseInt(downloadCount, 10);

const downloadCount = parseInt(
localStorage.getItem("download-count") ?? "0",
10
);
const updatedWithinCompare =
localStorage.getItem("updated-within-compare") ??
UpdatedFilterOption.Within;
const updatedWithin =
localStorage.getItem("updated-within") ??
UpdatedTimeRangeOption.none;

const onlyShowSavedPlugins =
localStorage.getItem("show-saved-plugins") === "true";
const showHiddenPlugins =
localStorage.getItem("show-hidden-plugins") === "true";

if (
this.settingManager.getSettings().hiddenPluginsArray
.length === 0 &&
!downloadCount &&
!updatedWithin &&
!onlyShowSavedPlugins
) {
communityItems
.removeClass(
"better-plugins-page-hidden-community-item"
)
.show();

// add the data-saved attribute to the card
communityItems.each(function () {
// if the setting saved plugin contains the plugin name, then we set the data-saved attribute to true
const itemName = getName(this);
const savedPluginsArr =
that.settingManager.getSettings().savedPluginsArray;
const isSaved = savedPluginsArr.includes(itemName);
this.setAttribute("data-saved", isSaved.toString());
});
return;
}
// Get settings from the setting manager
const settings = this.settingManager.getSettings();

const showHiddenPlugins = localStorage.getItem(
"show-hidden-plugins"
);
const shouldShowHiddenPlugins = showHiddenPlugins === "true";
communityItems.forEach((element) => {
const jElement = $(element);
const itemName = getName(element as HTMLElement);

communityItems.each(function () {
if (downloadCountValue) {
const downloadsText = $(this)
// Check if the plugin is saved
const isSaved =
settings.savedPluginsArray.includes(itemName);
element.setAttribute("data-saved", isSaved.toString());

if (downloadCount > 0) {
const downloadsText = jElement
.find(".community-item-downloads-text")
.text()
.replace(/,/g, "");
const itemDownloads = parseInt(downloadsText, 10);

if (
(downloadCountCompare === "greater" &&
itemDownloads <= downloadCountValue) ||
itemDownloads <= downloadCount) ||
(downloadCountCompare === "less" &&
itemDownloads >= downloadCountValue)
itemDownloads >= downloadCount)
) {
$(this).hide();
jElement.hide();
return;
} else {
$(this).show();
}
}

if (updatedWithin !== UpdatedTimeRangeOption.none) {
const updatedWithinMilliseconds =
getUpdatedWithinMilliseconds(updatedWithin);

const updatedText = $(this)
const updatedText = jElement
.find(".community-item-updated")
.text()
.replace("Updated ", "");
Expand All @@ -191,50 +173,34 @@ export default class BetterPluginsPagePlugin extends Plugin {
UpdatedFilterOption.Before &&
timeDifference > updatedWithinMilliseconds)
) {
$(this).show();
jElement.show();
} else {
$(this).hide();
jElement.hide();
return;
}
}
}

const itemName = getName(this);

const savedPluginsArr =
that.settingManager.getSettings().savedPluginsArray;
const isSaved = savedPluginsArr.includes(itemName);

// add the data-saved attribute to the card
this.setAttribute("data-saved", isSaved.toString());

if (onlyShowSavedPlugins && !isSaved) {
$(this).hide();
jElement.hide();
return;
} else {
$(this).show();
}

// now we passed the filtering

const isHidden = that.settingManager
.getSettings()
.hiddenPluginsArray.includes(itemName);
const isHidden =
settings.hiddenPluginsArray.includes(itemName);

if (!isHidden) {
$(this)
jElement
.removeClass(
"better-plugins-page-hidden-community-item"
)
.show();
} else {
$(this).toggleClass(
jElement.toggleClass(
"better-plugins-page-hidden-community-item",
shouldShowHiddenPlugins
showHiddenPlugins
);
shouldShowHiddenPlugins
? $(this).show()
: $(this).hide();
showHiddenPlugins ? jElement.show() : jElement.hide();
}
});
} catch (e) {
Expand All @@ -245,9 +211,13 @@ export default class BetterPluginsPagePlugin extends Plugin {
const summaryText = document.querySelector(
".community-modal-search-summary"
);
this.addButtons(communityItems);
// get the number of visible plugins
const visiblePlugins = $(".community-item:visible").length;
this.addButtons(communityItems as HTMLElement[]);
const visiblePlugins = communityItems.filter(
(element) =>
!element.classList.contains(
"better-plugins-page-hidden-community-item"
)
).length;
summaryText?.setText(`Showing ${visiblePlugins} plugins:`);
}
},
Expand All @@ -256,8 +226,8 @@ export default class BetterPluginsPagePlugin extends Plugin {
);

// Function to add the "Hide" and "Show" buttons to all community item cards
addButtons(cards: JQuery<HTMLElement>) {
cards.each((index, element) => {
addButtons(cards: HTMLElement[]) {
cards.forEach((element) => {
const card = element;
const isInstalledPlugin =
$(element).find(
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"1.0.6": "0.15.0",
"1.0.7": "0.15.0",
"1.0.8": "0.15.0",
"1.0.9": "0.15.0"
"1.0.9": "0.15.0",
"1.0.10": "0.15.0"
}

0 comments on commit 50237ec

Please sign in to comment.