Skip to content

Instantly share code, notes, and snippets.

@vantezzen
Last active April 18, 2020 19:22
Show Gist options
  • Save vantezzen/e514369f9dec6bc0171c8d9182f40936 to your computer and use it in GitHub Desktop.
Save vantezzen/e514369f9dec6bc0171c8d9182f40936 to your computer and use it in GitHub Desktop.
Filter Porkbun domain search results
/**
* Porkbun search filter
*
* by vantezzen(https://github.com/vantezzen)
*
* Instructions:
* 1. Go to https://porkbun.com/checkout/search?q=[ Name ]&all=1 - replacing "[ Name ]" with the name you want for your domain
* 2. Open JavaScript Console
* 3. Copy and paste this code into the console
* 4. Before executing, customize the `filterConfig` object to your needs
* 5. Execute the code. The code will filter the results on the page and remove domains that don't match your criteria
*/
(() => {
const filterConfig = {
maxPrice: 20.00, // Maximum price for your domain for first year registration (max be more expensive, e.g. due to premium registration)
removeUnavailible: true, // Remove unavailible domains
maxDomainLength: 0, // Maximum number of letters in the TLD, 0 to disable
removeSecondLevelDomains: true, // Remove domains that are second level (e.g ".gr.com")
}
// Remove unavailible domains
if (filterConfig.removeUnavailible) {
$('.unavailableDomain').parent().parent().parent().remove()
}
// Get search parameter to find out TLD length
const url = new URL(window.location.href);
// Only use parameter until first "." as we might be searching with TLD already appended
const search = url.searchParams.get("q").split('.')[0];
// Remove prices that are over limit
const getPrice = /\$\d+.\d+ \/ year/
$('.searchResultRowPrice').each(function() {
const priceText = $(this).find('.childContent').text();
const price = Number(getPrice.exec(priceText)[0].replace(/[^\d\.]+/g, ''));
const domain = $(this).parent().find('.searchResultRowDomain').text();
const tld = domain.replace(search, '').replace(/[\s\n]/g, '').replace('.', '');
if (
// Check price
price > filterConfig.maxPrice ||
// Check maximum length
(filterConfig.maxDomainLength !== 0 && tld.length > filterConfig.maxDomainLength) ||
// Check if second level domain
(filterConfig.removeSecondLevelDomains && tld.includes('.'))
) {
$(this).parent().parent().parent().remove();
}
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment