Last active
June 6, 2018 05:06
-
-
Save Xenofex/5fc69a29d79c24629748f8f1cb478ddd to your computer and use it in GitHub Desktop.
支付宝口碑后台操作
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
window.$ = jQuery; | |
nextPage = () => new Promise((resolve => { | |
$('[data-role=next]').click(); | |
$(document).one("ajaxComplete", () => { | |
resolve() | |
}) | |
})); | |
let ADDRESS_COLUMN = jQuery('#J-detail-container thead th:nth-child(2)').text() == "门店名称/ID" ? 2 : 3; | |
findElements = (cityPattern) => $("#J-detail-container tr[rid]").filter((i, e) => e.children[ADDRESS_COLUMN].innerText.match(cityPattern) && e.children[1].innerText.match(/大娘水饺/)); | |
function goOnline(cityPattern) { | |
let promiseArray = findElements(cityPattern).filter((i, e) => $(e).find('.J_online').length > 0).map((i, e) => { | |
return new Promise(resolve => { | |
if ($(e).find('.J_online').length > 0) { | |
let operationId = $(e).attr('data-operationid') || $(e).attr('rid'); | |
$.post("online.json", { operationId: operationId }).done((data) => { | |
console.log(e.children[1].innerText, data); | |
resolve() | |
}) | |
} else { | |
resolve(); | |
} | |
}) | |
}).get(); | |
console.info(`找到${promiseArray.length}个城市需要上线`) | |
return Promise.all(promiseArray) | |
} | |
function goOffline(cityPattern) { | |
let promiseArray = findElements(cityPattern).filter((i, e) => $(e).find('.J_offline').length > 0).map((i, e) => { | |
return new Promise(resolve => { | |
if ($(e).find('.J_offline').length > 0) { | |
let operationId = $(e).attr('data-operationid') || $(e).attr('rid'); | |
$.post("offline.json", { operationId: operationId }).done((data) => { | |
console.log(e.children[1].innerText, data); | |
resolve() | |
}) | |
} else { | |
resolve(); | |
} | |
}) | |
}).get(); | |
console.info(`找到${promiseArray.length}个城市需要下线`) | |
return Promise.all(promiseArray) | |
} | |
for (let n = 0; n < 44; n++) { | |
await goOffline(/苏州市/); | |
console.log(`转到第${n + 2}页`); | |
await nextPage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment