Last active
December 4, 2019 09:16
-
-
Save Fardinak/fe7f0acf9fe87b1254dd5ffb8d32909a to your computer and use it in GitHub Desktop.
MTN Irancell data package price per gig
This file contains hidden or 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
// Since MTN Irancell loves to experiment with their data packages and pricing | |
// i made this little snippet so I can easily choose a new package, fit for my | |
// needs and expectations instead of calculating the new PPGs every couple of | |
// month. | |
// | |
// Just run it in the console after page load and PPGs should replace the USSD | |
// Codes | |
const connection_speed = 20; // Mbps (approximate downlink speed) | |
const fair_usage_limit = 999; // GBs | |
function parseFarsiFloat(str) { | |
return parseFloat(str.replace(/[۰-۹]/g, (m) => ({'۰': 0, '۱': 1, '۲': 2, '۳': 3, '۴': 4, '۵': 5, '۶': 6, '۷': 7, '۸': 8, '۹': 9})[m])); | |
} | |
jQuery('.mobileInternetPackagesCard').each((_, el) => { | |
try { | |
let $product = jQuery(el); | |
let price = $product.data('total-price'); | |
let gigs = $product.data('size'); | |
let ppg = price / gigs * 1000; | |
if (gigs == -1) { | |
// Calculate unlimited packages | |
let hours = parseFarsiFloat($product.data('size-label').match(/[۰-۹0-9]+ ?ساعته/)[0]); | |
gigs = Math.min(connection_speed / 8 * 3.6 * hours, fair_usage_limit); | |
ppg = price / gigs; | |
} | |
$product.find('.cardNetworkCoverage').text('به ازای هر گیگ'); | |
$product.find('.cardNetworkCoverage').append('<p>~' + (ppg).toFixed() + ' تومان</p>'); | |
$product.data('ppg', ppg); | |
} catch (err) { | |
return; | |
} | |
}).detach().sort((a, b) => jQuery(a).data('ppg') - jQuery(b).data('ppg')).appendTo('#offers'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment