Skip to content

Instantly share code, notes, and snippets.

@SamadiPour
Last active May 27, 2024 07:23
Show Gist options
  • Save SamadiPour/44f9dfe9ec8918c04dd86b2c055baa4c to your computer and use it in GitHub Desktop.
Save SamadiPour/44f9dfe9ec8918c04dd86b2c055baa4c to your computer and use it in GitHub Desktop.
ADSL TCI plan sorter
const planCards = document.querySelectorAll('#service-list .uk-card');
const cardDetails = [];
function convertPersianNumbersToEnglish(text) {
return text.replace(/[۰-۹]/g, (char) => String.fromCharCode(char.charCodeAt(0) - '۰'.charCodeAt(0) + '0'.charCodeAt(0)));
}
planCards.forEach(card => {
const title = convertPersianNumbersToEnglish(card.querySelector('.uk-card-title').textContent.trim());
const description = convertPersianNumbersToEnglish(card.querySelector('.uk-card-body p').textContent.trim());
const price = convertPersianNumbersToEnglish(card.querySelector('.price h3').textContent.trim());
const numericPrice = Number(price.replace(/[^\d.]/g, '')) / 10;
const gb = Number(title.replace(/[^\d.]/g, ''));
const monthMatch = description.match(/(\d+)\s*ماهه/);
const months = monthMatch ? Number(monthMatch[1]) : null;
const ratio = numericPrice / gb;
const gbPerMonth = gb / months;
cardDetails.push({ card, ratio, numericPrice, gb, months, gbPerMonth });
});
text = ''
cardDetails.sort((a, b) => a.ratio - b.ratio);
cardDetails.forEach(({ card, ratio, numericPrice, gb, months, gbPerMonth }) => {
text += `Ratio: ${ratio}\n`;
text += `Price: ${numericPrice}\n`;
text += `GB: ${gb}\n`;
text += `Months: ${months} (${gbPerMonth} per month)\n`;
text += `---------------------------\n`;
});
console.log(text);
@SamadiPour
Copy link
Author

SamadiPour commented Dec 17, 2023

May 27, 2024 for ADSL:

Ratio: 712.1031746031746
Price: 3589000
GB: 5040
Months: 12 (420 per month)
---------------------------
Ratio: 742.4603174603175
Price: 1871000
GB: 2520
Months: 6 (420 per month)
---------------------------
Ratio: 765.0793650793651
Price: 964000
GB: 1260
Months: 3 (420 per month)
---------------------------
Ratio: 765.4761904761905
Price: 321500
GB: 420
Months: 1 (420 per month)
---------------------------
Ratio: 775
Price: 1116000
GB: 1440
Months: 12 (120 per month)
---------------------------
Ratio: 801.6908212560387
Price: 3319000
GB: 4140
Months: 12 (345 per month)
---------------------------
Ratio: 808.3333333333334
Price: 582000
GB: 720
Months: 6 (120 per month)
---------------------------
Ratio: 833.3333333333334
Price: 300000
GB: 360
Months: 3 (120 per month)
---------------------------
Ratio: 833.3333333333334
Price: 100000
GB: 120
Months: 1 (120 per month)
---------------------------
Ratio: 836.231884057971
Price: 1731000
GB: 2070
Months: 6 (345 per month)
---------------------------
Ratio: 860.8695652173913
Price: 297000
GB: 345
Months: 1 (345 per month)
---------------------------
Ratio: 861.8357487922706
Price: 892000
GB: 1035
Months: 3 (345 per month)
---------------------------
Ratio: 930.2083333333334
Price: 893000
GB: 960
Months: 12 (80 per month)
---------------------------
Ratio: 968.75
Price: 465000
GB: 480
Months: 6 (80 per month)
---------------------------
Ratio: 1000
Price: 480000
GB: 480
Months: 12 (40 per month)
---------------------------
Ratio: 1000
Price: 240000
GB: 240
Months: 3 (80 per month)
---------------------------
Ratio: 1000
Price: 80000
GB: 80
Months: 1 (80 per month)
---------------------------
Ratio: 1023.8738738738739
Price: 2273000
GB: 2220
Months: 12 (185 per month)
---------------------------
Ratio: 1041.6666666666667
Price: 625000
GB: 600
Months: 12 (50 per month)
---------------------------
Ratio: 1041.6666666666667
Price: 250000
GB: 240
Months: 6 (40 per month)
---------------------------
Ratio: 1067.5675675675675
Price: 1185000
GB: 1110
Months: 6 (185 per month)
---------------------------
Ratio: 1075
Price: 129000
GB: 120
Months: 3 (40 per month)
---------------------------
Ratio: 1086.6666666666667
Price: 326000
GB: 300
Months: 6 (50 per month)
---------------------------
Ratio: 1100
Price: 203500
GB: 185
Months: 1 (185 per month)
---------------------------
Ratio: 1100.900900900901
Price: 611000
GB: 555
Months: 3 (185 per month)
---------------------------
Ratio: 1120
Price: 168000
GB: 150
Months: 3 (50 per month)
---------------------------
Ratio: 1120
Price: 56000
GB: 50
Months: 1 (50 per month)
---------------------------
Ratio: 1540.4761904761904
Price: 647000
GB: 420
Months: 12 (35 per month)
---------------------------
Ratio: 1607.142857142857
Price: 337500
GB: 210
Months: 6 (35 per month)
---------------------------
Ratio: 1657.142857142857
Price: 174000
GB: 105
Months: 3 (35 per month)
---------------------------
Ratio: 1657.142857142857
Price: 58000
GB: 35
Months: 1 (35 per month)
---------------------------
Ratio: 1965.909090909091
Price: 519000
GB: 264
Months: 12 (22 per month)
---------------------------
Ratio: 2045.4545454545455
Price: 270000
GB: 132
Months: 6 (22 per month)
---------------------------
Ratio: 2113.6363636363635
Price: 46500
GB: 22
Months: 1 (22 per month)
---------------------------
Ratio: 2121.212121212121
Price: 140000
GB: 66
Months: 3 (22 per month)
---------------------------
Ratio: 2458.3333333333335
Price: 29500
GB: 12
Months: 1 (12 per month)
---------------------------

@hosni
Copy link

hosni commented Dec 18, 2023

I suggest using IIFE to be able to run over and over.
Just put the above code in this block:

(function() {
# CODE
})()
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment