├── README.md └── 0.0.2.js /README.md: -------------------------------------------------------------------------------- 1 | // just copy all the code into your ios short cuts and it should work fine. 2 | -------------------------------------------------------------------------------- /0.0.2.js: -------------------------------------------------------------------------------- 1 | /**屠龙0.0.2 版权归 “潮目 - Hypeeyes”所有,未经授权不得转发 */ 2 | /**Follow @Hypeeyes on twitter to get the latest update 3 | * Peer code review by @navar_jande on twitter 4 | */ 5 | 6 | (function () { 7 | let keyWord = '+pendant'; /** +box,+logo,-bear*/ 8 | let categories = ["Jackets", "Coats", "Shirts", "Tops/Sweaters", "Sweatshirts", "Pants", "Shorts", "T-Shirts", "Hats", "Bags", "Accessories", "Shoes", "Skate"]; 9 | /** 0 -> "Jackets", 1 -> "Coats", 2-> "Shirts", 3 -> "Tops/Sweaters", 4 ->"Sweatshirts", 5->"Pants", 6->"Shorts", 7->"T-Shirts", 10 | 8-> "Hats", 9->"Bags", 10->"Accessories", 11->"Shoes", 12->"Skate" */ 11 | let category = categories[10]; 12 | let preferredSize = 'medium'; /**尺码没有了会选择默认尺码 */ 13 | let preferColor = 'any'; /**颜色没有了回选最后一个有货的,填any回选第一个颜色有货的 */ 14 | let autoCheckout = false; /**自动结账, */ 15 | let checkout_delay = 2500; /**结账延迟设置, 2500 = 2.5秒 */ 16 | 17 | /**Address info */ 18 | let billing_name = "us last"; 19 | let order_email = "test@gmail.com"; 20 | let order_tel = "1112223344"; 21 | let order_address = "707 test St"; 22 | let order_billing_address_2 = "Apt48"; 23 | let order_billing_zip = "95116"; 24 | let order_billing_city = "San Jose"; 25 | let order_billing_state = "CA"; /**日本省份前面要加空格, */ 26 | let order_billing_country = "USA"; /**USA, CANADA,EU:GB, FR 欧洲国家大写缩写 */ 27 | 28 | /**Payment info */ 29 | let credit_card_type = "visa"; /**日本代金填cod */ 30 | /**欧洲:visa, american_express, master, solo */ 31 | /**日本:visa, american_express, master, jcb, cod(代金) */ 32 | let cnb = "4111 1111 1111 1111"; 33 | let month = "10"; 34 | let year = "2022"; 35 | let vval = "119"; 36 | 37 | /**======================================================================================================= */ 38 | 39 | let startTime = null; 40 | let isNew = true; 41 | let item_selected = false; 42 | 43 | let mobile_stock_api = "https://www.supremenewyork.com/mobile_stock.json"; 44 | let event = document.createEvent('Event'); 45 | event.initEvent('change', true, true); 46 | 47 | let notifyHeader = document.createElement('p'); 48 | notifyHeader.style.cssText = "padding-left:120px;margin: auto;width: 100%;background-color: #70de4c;"; 49 | let refresh_count = 0; 50 | document.getElementsByTagName('header')[0].appendChild(notifyHeader); 51 | 52 | let retryFetch = async (url, options=null, retry=0) => { 53 | if (retry >= 4) return Promise.resolve(1); 54 | let res = await fetch(url, options); 55 | if (res.status !== 200) { 56 | await sleep(Math.min(retry * 500, 2 * 1000)); 57 | return await retryFetch(url, options, retry + 1); 58 | } else { 59 | return await res.json(); 60 | } 61 | }; 62 | 63 | function matchKeyWord (itemName, keyWords) { 64 | let name = itemName.toLowerCase().trim(); 65 | let keyWordsList = keyWords.toLowerCase().split(","); 66 | for (let i = 0; i < keyWordsList.length; i ++) { 67 | let word = keyWordsList[i].trim(); 68 | if ((word.includes('+') && !name.includes(word.substr(1))) || 69 | (word.includes('-') && name.includes(word.substr(1)))) { 70 | return false; 71 | } 72 | } 73 | return true; 74 | }; 75 | 76 | let sleep = (ms) => { 77 | return new Promise(resolve => setTimeout(resolve, ms)); 78 | }; 79 | 80 | async function mobileAPIRefreshed(respond) { 81 | let categoryProduct = respond['products_and_categories'][category]; 82 | console.log(categoryProduct); 83 | if (categoryProduct) { 84 | for (let index = 0; index < categoryProduct.length; index ++) { 85 | let item = categoryProduct[index]; 86 | if (item != null && item['name'] != null && matchKeyWord(item['name'], keyWord)) { 87 | isNew = false; 88 | return true; 89 | }; 90 | }; 91 | }; 92 | return false; 93 | } 94 | 95 | async function monitor() { 96 | if (!item_selected) { 97 | notifyHeader.innerHTML = '监测新的产品。。。 次数: ' + refresh_count; 98 | refresh_count ++; 99 | let refreshed = false; 100 | 101 | let respond = await retryFetch(mobile_stock_api); 102 | refreshed = respond == null ? false : await mobileAPIRefreshed(respond); 103 | if (refreshed) { 104 | respondJSON = respond; 105 | startTime = new Date(); 106 | console.log("Detect Page refreshed with mobile endpoint at: " + startTime.toISOString()); 107 | notifyHeader.innerHTML = "新商品已经上线。。。如果页面没有跳转到商品页面请手动刷新并且重启程序。"; 108 | window.location.href = isNew ? 'https://www.supremenewyork.com/mobile/#categories/new' : `https://www.supremenewyork.com/mobile/#categories/${category}`; 109 | await sleep(300); 110 | start(); 111 | return; 112 | } else { 113 | console.log("Not refreshed, retrying ..."); 114 | await sleep(1000); 115 | await monitor(); 116 | return; 117 | } 118 | } 119 | } 120 | 121 | 122 | let start = () => { 123 | console.log("start!!"); 124 | let items = document.getElementsByClassName("name"); 125 | let selectedItem = null; 126 | if (items.length > 0) { 127 | notifyHeader.innerHTML = "寻找相应物品中。。。如有卡顿,请手动点击商品图片。"; 128 | for (item of items) { 129 | let name = item.innerHTML; 130 | 131 | if (matchKeyWord(name, keyWord)) { 132 | startTime = new Date().getTime(); 133 | selectedItem =item; 134 | selectedItem.click(); 135 | break; 136 | }; 137 | }; 138 | 139 | if (selectedItem !== null) { 140 | (function waitTillItemClick() { 141 | items = document.getElementsByClassName("name"); 142 | if (items.length > 0) { 143 | console.log('wait item click ...'); 144 | selectedItem.click(); 145 | setTimeout(function(){ waitTillItemClick(); }, 150); 146 | } else { 147 | return; 148 | } 149 | })(); 150 | } else { 151 | sleep(50).then(start); 152 | }; 153 | } else { 154 | sleep(150).then(start); 155 | }; 156 | }; 157 | 158 | ( function waitTillArticlePageIsOpen(){ 159 | console.log('wait item page ...'); 160 | let atcBtn = document.getElementsByClassName("cart-button")[0]; 161 | if (atcBtn) { 162 | addToCart(); 163 | } else { 164 | setTimeout(function(){ waitTillArticlePageIsOpen(); }, 150); 165 | }; 166 | return; 167 | } )(); 168 | 169 | 170 | 171 | async function addToCart(){ 172 | if (document.getElementById('cart-update').children[0].innerHTML === "remove") { 173 | checkout(); 174 | return; 175 | } 176 | notifyHeader.innerHTML = "选择相应颜色中。。。"; 177 | await chooseColor(); 178 | notifyHeader.innerHTML = "颜色选择完毕。。。"; 179 | await sleep(70); 180 | notifyHeader.innerHTML = "选择相应尺码中。。。"; 181 | chooseSize(); 182 | notifyHeader.innerHTML = "尺码选择完毕。。。"; 183 | await sleep(70); 184 | let atcBtn = document.getElementsByClassName("cart-button")[0]; 185 | atcBtn.click(); 186 | item_selected = true; 187 | 188 | (function waitTillCartUpdates() { 189 | let cart = document.getElementById("goto-cart-link").innerHTML; 190 | if (cart == '' || cart == 0) { 191 | setTimeout(function(){ waitTillCartUpdates(); }, 150); 192 | return; 193 | } else { 194 | notifyHeader.innerHTML = "已经加入购物车"; 195 | checkout(); 196 | return; 197 | } 198 | })(); 199 | } 200 | 201 | 202 | async function chooseColor() { 203 | let image; 204 | let url = "/shop/"+window.location.hash.split("/")[1]+".json"; 205 | let res = await fetch(url); 206 | let myJson = await res.json(); 207 | for (item of myJson.styles){ 208 | let color = item.name; 209 | if (checkAvaliability(item.sizes)) { 210 | let id = item.id; 211 | let imageID = "style-"+id; 212 | image = document.getElementById(imageID).getElementsByClassName("style-thumb")[0]; 213 | if (color.toLowerCase().includes(preferColor.toLowerCase()) || preferColor.toLowerCase() === 'any') { 214 | image.click(); 215 | break; 216 | } 217 | } 218 | } 219 | if (image !== undefined) { 220 | image.click(); 221 | } 222 | } 223 | 224 | function checkAvaliability(sizes) { 225 | for (size of sizes) { 226 | if (size['stock_level'] > 0) { 227 | return true; 228 | } 229 | } 230 | return false; 231 | } 232 | 233 | function chooseSize(){ 234 | let sizeOpts = document.getElementsByTagName("option"); 235 | let sizeVal = sizeOpts[0].value; 236 | for (let option of sizeOpts){ 237 | let size = option.text.toLowerCase(); 238 | if (size === preferredSize.toLowerCase() || size === 'N/A'){ 239 | sizeVal = option.value; 240 | break; 241 | } 242 | } 243 | sizeOpts = document.getElementsByTagName("select")[0].value = sizeVal; 244 | 245 | } 246 | 247 | function checkout(){ 248 | window.location.href = 'https://www.supremenewyork.com/mobile/#checkout'; 249 | let checkoutBtn = document.getElementById("submit_button"); 250 | waitTillCheckoutPageIsOpen(); 251 | } 252 | 253 | async function waitTillCheckoutPageIsOpen() { 254 | 255 | checkoutBtn = document.getElementById("submit_button"); 256 | if (checkoutBtn) { 257 | notifyHeader.innerHTML = "正在填写个人信息。。。"; 258 | await sleep(50); 259 | document.getElementById("order_billing_name").focus(); 260 | document.getElementById("order_billing_name").value = billing_name; 261 | 262 | await sleep(50); 263 | document.getElementById("order_email").focus(); 264 | document.getElementById("order_email").value = order_email; 265 | await sleep(50); 266 | document.getElementById("order_tel").focus(); 267 | document.getElementById("order_tel").value = order_tel; 268 | await sleep(50); 269 | document.getElementById("order_billing_address").focus(); 270 | document.getElementById("order_billing_address").value = order_address; 271 | 272 | if (document.getElementById("order_billing_address_2")) { 273 | await sleep(50); 274 | document.getElementById("order_billing_address_2").focus(); 275 | document.getElementById("order_billing_address_2").value = order_billing_address_2; 276 | } 277 | 278 | 279 | if (document.getElementById("obz")) { 280 | await sleep(50); 281 | document.getElementById("obz").focus(); 282 | document.getElementById("obz").value = order_billing_zip; 283 | } 284 | if (document.getElementById("order_billing_zip")) { 285 | await sleep(50); 286 | document.getElementById("order_billing_zip").focus(); 287 | document.getElementById("order_billing_zip").value = order_billing_zip; 288 | } 289 | await sleep(50); 290 | 291 | document.getElementById("order_billing_city").focus(); 292 | document.getElementById("order_billing_city").value = order_billing_city; 293 | 294 | if (document.getElementById("order_billing_country")) { 295 | await sleep(50); 296 | document.getElementById("order_billing_country").value = order_billing_country; 297 | document.getElementById("order_billing_country").dispatchEvent(event); 298 | } 299 | 300 | if (document.getElementById("order_billing_state")) { 301 | await sleep(50); 302 | document.getElementById("order_billing_state").focus(); 303 | document.getElementById("order_billing_state").value = order_billing_state; 304 | document.getElementById("order_billing_state").dispatchEvent(event); 305 | } 306 | 307 | if (document.getElementById("credit_card_type")) { 308 | await sleep(50); 309 | document.getElementById("credit_card_type").value = credit_card_type; 310 | document.getElementById("credit_card_type").dispatchEvent(event); 311 | } 312 | if (document.getElementById("credit_card_n")) { 313 | await sleep(50); 314 | document.getElementById("credit_card_n").focus(); 315 | document.getElementById("credit_card_n").value = cnb; 316 | } 317 | if (document.getElementById("credit_card_month")) { 318 | await sleep(50); 319 | document.getElementById("credit_card_month").focus(); 320 | document.getElementById("credit_card_month").value = month; 321 | document.getElementById("credit_card_month").dispatchEvent(event); 322 | } 323 | if (document.getElementById("credit_card_year")) { 324 | await sleep(50); 325 | document.getElementById("credit_card_year").focus(); 326 | document.getElementById("credit_card_year").value = year; 327 | document.getElementById("credit_card_year").dispatchEvent(event); 328 | } 329 | if (document.getElementById("cav")) { 330 | await sleep(50); 331 | document.getElementById("cav").focus(); 332 | document.getElementById("cav").value = vval; 333 | } 334 | if (document.getElementById("credit_card_cvv")) { 335 | await sleep(50); 336 | document.getElementById("credit_card_cvv").focus(); 337 | document.getElementById("credit_card_cvv").value = vval; 338 | } 339 | 340 | await sleep(50); 341 | document.getElementById("order_terms").click(); 342 | 343 | notifyHeader.innerHTML = "填写完毕,请结账。。。"; 344 | if (autoCheckout){ 345 | notifyHeader.innerHTML = "自动结账中。。。"; 346 | await sleep(checkout_delay); 347 | document.getElementById("hidden_cursor_capture").click(); 348 | } 349 | console.log('paymentTime: ' + (new Date().getTime() - startTime) + ' ms'); 350 | notifyHeader.remove(); 351 | return; 352 | } else { 353 | setTimeout(async function(){ await waitTillCheckoutPageIsOpen(); }, 200); 354 | console.log("waiting to Chekcout..."); 355 | } 356 | } 357 | 358 | monitor(); 359 | })(); 360 | completion(); 361 | --------------------------------------------------------------------------------