劫持超链接跳转
document.body.addEventListener('click', /* async */ function (event) {
if (event.target.nodeName.toLocaleLowerCase() === 'a') {
event.preventDefault();
// await new Promise(function (t, c) {setTimeout(t, 5000);});
let url = event.target.getAttribute("href");
console.log(url);
window.open('https://www.douyin.com');
}
});
实现js的sleep函数.
async function sleep(msecs) {
return new Promise(function (resolve, reject) {
let uuid = Math.floor(Math.random() * 65536)
.toString(16)
.toUpperCase()
.padStart(4, "0");
console.log(`SLEEP#${uuid} START`);
setTimeout(function () {
resolve(uuid);
}, msecs);
}).then(function (uuid) {
console.log(`SLEEP#${uuid} END`);
});
}