Created
December 23, 2022 18:56
-
-
Save IvanaGyro/da94d1cbaa71a408d1c5f05a153a2e9d to your computer and use it in GitHub Desktop.
找 Kobo 上面最便宜的國家
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
/** | |
* 1. Get current rates from https://www.xe.com/api/protected/midmarket-converter/ | |
* 2. Replace "rates" object with the correct currency rates. | |
* 3. Select a book on Kobo. | |
* 4. Click the country flag at the top right corner. | |
* 5. Execute this script. | |
*/ | |
rates = { | |
ADA: 3.8456167243, | |
AED: 3.6725, | |
AFN: 88.4769615132, | |
ALL: 107.5801371358, | |
AMD: 391.7775173811, | |
ANG: 1.7899896574, | |
AOA: 510.0081478307, | |
ARS: 174.8236563613, | |
ATS: 12.9593695667, | |
AUD: 1.4902714495, | |
AWG: 1.79, | |
AZM: 8499.6974068942, | |
AZN: 1.6999394814, | |
BAM: 1.8419891848, | |
BBD: 2, | |
BCH: 0.0097832721, | |
BDT: 106.3582698746, | |
BEF: 37.9918804375, | |
BGN: 1.8419891848, | |
BHD: 0.376, | |
BIF: 2062.6433832318, | |
BMD: 1, | |
BND: 1.3504175257, | |
BOB: 6.9072139218, | |
BRL: 5.163976781, | |
BSD: 1, | |
BTC: 0.0000593622, | |
BTN: 82.8223696346, | |
BWP: 12.9525551151, | |
BYN: 2.5047511507, | |
BYR: 25047.5115072178, | |
BZD: 2.0147192473, | |
CAD: 1.3603732307, | |
CDF: 2034.326291625, | |
CHF: 0.9333058987, | |
CLF: 0.0380809882, | |
CLP: 878.0332064486, | |
CNH: 7.0038881072, | |
CNY: 6.9917791547, | |
COP: 4734.826911074, | |
CRC: 582.6955705799, | |
CUC: 1, | |
CUP: 23.9972434316, | |
CVE: 103.8516371098, | |
CYP: 0.5512076091, | |
CZK: 22.791026954, | |
DEM: 1.8419891848, | |
DJF: 177.7684480485, | |
DKK: 7.0029442293, | |
DOGE: 12.928637459, | |
DOP: 55.7895980973, | |
DOT: 0.222617892, | |
DZD: 137.5875230166, | |
EEK: 14.7359134784, | |
EGP: 24.7491820466, | |
ERN: 15, | |
ESP: 156.701355692, | |
ETB: 53.597990201, | |
ETH: 0.0008198803, | |
EUR: 0.9417941154, | |
FIM: 5.599653526, | |
FJD: 2.2318419754, | |
FKP: 0.8306037044, | |
FRF: 6.1777644258, | |
GBP: 0.8306037044, | |
GEL: 2.6896342286, | |
GGP: 0.8306037044, | |
GHC: 92764.4335765763, | |
GHS: 9.2764433577, | |
GIP: 0.8306037044, | |
GMD: 61.8915758688, | |
GNF: 8629.1046692298, | |
GRD: 320.9163448369, | |
GTQ: 7.8565505774, | |
GYD: 208.8325878494, | |
HKD: 7.8046987022, | |
HNL: 24.6729025109, | |
HRK: 7.1005729862, | |
HTG: 146.0935962995, | |
HUF: 376.5475808232, | |
IDR: 15589.6419726558, | |
IEP: 0.7417231407, | |
ILS: 3.5020674043, | |
IMP: 0.8306037044, | |
INR: 82.8223696346, | |
IQD: 1459.1574318561, | |
IRR: 41636.5702676274, | |
ISK: 143.4381949011, | |
ITL: 1823.5676919073, | |
JEP: 0.8306037044, | |
JMD: 152.6791075809, | |
JOD: 0.709, | |
JPY: 132.8874400049, | |
KES: 123.2909596426, | |
KGS: 85.678596494, | |
KHR: 4112.6783683926, | |
KMF: 463.3323319373, | |
KPW: 899.9099168824, | |
KRW: 1281.0673893522, | |
KWD: 0.3064827815, | |
KYD: 0.8199870236, | |
KZT: 461.7102073563, | |
LAK: 17272.5011774459, | |
LBP: 1507.5, | |
LINK: 0.1671262295, | |
LKR: 365.488306107, | |
LRD: 154.3696471598, | |
LSL: 17.0141068708, | |
LTC: 0.015237124, | |
LTL: 3.2518267218, | |
LUF: 37.9918804375, | |
LUNA: 7.13128503703983e40, | |
LVL: 0.6618929043, | |
LYD: 4.8207639054, | |
MAD: 10.5018197051, | |
MDL: 19.2773995083, | |
MGA: 4443.5397349128, | |
MGF: 22217.6986745641, | |
MKD: 57.998330228, | |
MMK: 2099.8282797932, | |
MNT: 3433.8362874812, | |
MOP: 8.0388396633, | |
MRO: 372.1456194658, | |
MRU: 37.2145619466, | |
MTL: 0.4043122138, | |
MUR: 44.2117526658, | |
MVR: 15.4107183181, | |
MWK: 1028.0352244005, | |
MXN: 19.3967479775, | |
MXV: 2.758460685, | |
MYR: 4.4246984602, | |
MZM: 64042.8989959457, | |
MZN: 64.0428989959, | |
NAD: 17.0141068708, | |
NGN: 446.0888231722, | |
NIO: 36.4137863467, | |
NLG: 2.0754411101, | |
NOK: 9.8663703534, | |
NPR: 132.5779081926, | |
NZD: 1.5903853002, | |
OMR: 0.3849538615, | |
PAB: 1, | |
PEN: 3.8165000182, | |
PGK: 3.5210923462, | |
PHP: 55.2341808334, | |
PKR: 226.3691539969, | |
PLN: 4.3714187244, | |
PTE: 188.8127678521, | |
PYG: 7296.2181201286, | |
QAR: 3.64, | |
ROL: 46244.3001887193, | |
RON: 4.6244300189, | |
RSD: 110.4652966219, | |
RUB: 68.7950965919, | |
RWF: 1067.8394000382, | |
SAR: 3.75, | |
SBD: 8.2573420562, | |
SCR: 14.2249470298, | |
SDD: 57235.533221287, | |
SDG: 572.3553322129, | |
SEK: 10.5197650693, | |
SGD: 1.3504175257, | |
SHP: 0.8306037044, | |
SIT: 225.6915418246, | |
SKK: 28.3724895218, | |
SLE: 18.8642875357, | |
SLL: 18864.2875356555, | |
SOS: 569.1151057231, | |
SPL: 0.166666666, | |
SRD: 31.5530918221, | |
SRG: 31553.0918221314, | |
STD: 23099.67002775, | |
STN: 23.0996700278, | |
SVC: 8.75, | |
SYP: 2512.4276806864, | |
SZL: 17.0141068708, | |
THB: 34.7626392404, | |
TJS: 10.2025056681, | |
TMM: 17468.3271860555, | |
TMT: 3.4936654372, | |
TND: 3.1156579743, | |
TOP: 2.3600484299, | |
TRL: 18683615.126171418, | |
TRY: 18.6836151262, | |
TTD: 6.7871310728, | |
TVD: 1.4902714495, | |
TWD: 30.7574728705, | |
TZS: 2333.9631932529, | |
UAH: 36.8747555515, | |
UGX: 3637.4756211684, | |
UNI: 19.0375055386, | |
USD: 1, | |
UYU: 38.604508423, | |
UZS: 11225.5993750431, | |
VAL: 1823.5676919073, | |
VEB: 1641540077.0165398, | |
VED: 16.4154007702, | |
VEF: 1641540.0770165399, | |
VES: 16.4154007702, | |
VND: 23526.8727306767, | |
VUV: 119.3643230661, | |
WST: 2.7275952107, | |
XAF: 617.7764425831, | |
XAG: 0.0421805017, | |
XAU: 0.0005569, | |
XBT: 0.0000593622, | |
XCD: 2.6999138387, | |
XDR: 0.7514053202, | |
XLM: 13.174815167, | |
XOF: 617.7764425831, | |
XPD: 0.0005851886, | |
XPF: 112.3859326299, | |
XPT: 0.0010011189, | |
XRP: 2.8465365428, | |
YER: 250.1564306194, | |
ZAR: 17.0141068708, | |
ZMK: 18005.8477021466, | |
ZMW: 18.0058477021, | |
ZWD: 361.9, | |
ZWL: 671.810102792, | |
}; | |
my_read_page = async (url, index) => { | |
let response = await fetch(url, {}); | |
let elm = document.createElement("html"); | |
elm.innerHTML = await response.text(); | |
let price = elm.querySelector('[property="og:price"]').content; | |
let current = elm.querySelector('[property="og:currency_code"]').content; | |
console.log(`${index} ${url} ${price}${current}`); | |
return { | |
price, | |
current, | |
url, | |
}; | |
}; | |
(async () => { | |
let urls = Array.from(document.querySelectorAll("a.country")).map( | |
(el) => el.href | |
); | |
let results = await Promise.allSettled( | |
urls.map((u, i) => my_read_page(u, i)) | |
); | |
results = results.map((r) => r.value); | |
results.sort((a, b) => { | |
let to_ntd = (c) => | |
(Number(c.price.replace(",", ".")) / rates[c.current]) * rates.TWD; | |
a.ntd = to_ntd(a); | |
b.ntd = to_ntd(b); | |
return a.ntd - b.ntd; | |
}); | |
console.log(results.map((r) => `${r.ntd} ${r.url}`)); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment