Created
September 20, 2023 12:28
-
-
Save MrMoshkovitz/1cbb1a68e1aa676638dc12b595db1851 to your computer and use it in GitHub Desktop.
Obsidian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Obsidian Plugin Sorter by Downloads: | |
// This script will sort the plugins by downloads amount and print them in the console. | |
// The script should be able to run in the browser console. | |
// The Obsidian Plugin List Sorter by Downloads Amount script will sort the plugins by downloads amount in your browser html view and print them in the console. | |
// The obsidian Plugins URL: https://obsidian.md/plugins | |
// Solution: | |
// 1. Get all the plugins divs | |
const plugins = document.querySelectorAll('body > div > div.plugins-container.container.grid.grid-cols-1.sm\\:grid-cols-2.lg\\:grid-cols-3.gap-4 > div'); | |
// 2. Create an array of objects with the plugin name and downloads amount | |
// Plugin name is in body > div > div.plugins-container.container.grid.grid-cols-1.sm\:grid-cols-2.lg\:grid-cols-3.gap-4 > div:nth-child(1) > div.text-lg.mb-1.font-semibold.leading-tight | |
const pluginsArray = []; | |
plugins.forEach(plugin => { | |
const name = plugin.querySelector('div:nth-child(1)').innerText; | |
const downloads = plugin.querySelector('p:nth-child(3)').innerText; | |
pluginsArray.push({name, downloads}); | |
}); | |
// 3.1 remove the word downloads from the downloads amount and change it to a number | |
pluginsArray.forEach(plugin => { | |
plugin.downloads = plugin.downloads.replace(' downloads', ''); | |
// 3.3 remove the comma from the downloads amount | |
plugin.downloads = plugin.downloads.replace(',', ''); | |
}); | |
// 3.2 Sort the array by downloads amount | |
pluginsArray.sort((a, b) => { | |
return parseInt(b.downloads) - parseInt(a.downloads); | |
}); | |
// print the plugins list to the console with name and downlaods amount order by downloads amount asc | |
pluginsArray.forEach((plugin, index) => { | |
console.log(`Number ${index + 1}: ${plugin.name} - ${plugin.downloads}`); | |
console.log(`Number ${index + 1}: ${plugin.description}`); | |
console.log('------------------------'); | |
}); | |
// 4. Print the plugins in the html | |
pluginsArray.forEach((plugin, index) => { | |
const pluginDiv = document.querySelector(`body > div > div.plugins-container.container.grid.grid-cols-1.sm\\:grid-cols-2.lg\\:grid-cols-3.gap-4 > div:nth-child(${index + 1})`); | |
pluginDiv.querySelector('div:nth-child(1)').innerText = `${index + 1}: ${plugin.name} - ${plugin.downloads}`; | |
pluginDiv.querySelector('p:nth-child(3)').innerText = `${index + 1}: ${plugin.downloads}`; | |
console.log('------------------------'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment