Skip to content

Instantly share code, notes, and snippets.

@vantezzen
Created November 6, 2018 14:45
Show Gist options
  • Save vantezzen/f477bfb87222ad50084530c6edd52123 to your computer and use it in GitHub Desktop.
Save vantezzen/f477bfb87222ad50084530c6edd52123 to your computer and use it in GitHub Desktop.
Search domains on porkbun.com that are under a given price
/**
* Porkbun.com: Search domain names under certain price
*
* by vantezzen (https://github.com/vantezzen)
*
* Instructions:
* 1. Go to https://porkbun.com/products/domains
* 2. Open JavaScript Console
* 3. Copy and paste this code into the console
* 4. Before executing, customize the `config` object to your needs
* 5. Execute the code. You will now see a table in your console with the filtered domains
*/
let config = {
maxPrice: 10, // Maximum price for a domain (in $)
usePrice: 'price', // Price to use ('firstYear' to use registration price/price for first year or 'price' to use renewal price)
sortByPrice: true // Sort domains by price (lowest first) before outputting
};
// Initialize variables
let domainElements = $('.domainsPricingAllExtensionsItem');
let domains = [];
let domain = {};
// Get price for all domains and add to domains array
domainElements.each((key, element) => {
element = $(element);
domain = {};
domain.extension = element.find('a').eq(0).text();
domain.price = element.find('.renewal').find('.sortValue').text();
domain.firstYear = element.find('.registration').find('.sortValue').text();
domains.push(domain);
});
// Search domains with lower or equal given price
let domainsUnderPrice = [];
for (let domain of domains) {
if (domain[config.usePrice] <= config.maxPrice) {
domainsUnderPrice.push(domain);
}
}
// Sort by price if enabled
if (config.sortByPrice) {
domainsUnderPrice.sort(function(a,b) {
return a[config.usePrice] - b[config.usePrice];
});
}
// Output to console
console.clear();
console.log("These domains are under $" + config.maxPrice + " (" + domainsUnderPrice.length + " of " + domains.length + " domains)");
console.table(domainsUnderPrice);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment