1、触发迅雷下载
<a data-thunder href="http://localhost:8080/download/"></a>
<script>
const links = document.querySelectorAll('a[data-thunder]');
for(const link of links){
const base64 = btoa(`AA${link.href}ZZ`);
link.href = `thunder://${base64}`;
}
</script>
2、中文输入法导致的高频事件
<input type="text" class="txt">
<script>
var inp = document.querySelector('input');
function search(){
console.log('搜索的值'+inp.value)
}
let isComposition = false;
inp.addEventListener('input',function(){
if(isComposition){
return;
}
search();
})
inp.addEventListener('compositionstart',function(){
isComposition = true
})
inp.addEventListener('compositionend',function(){
isComposition = false;
search();
})
</script>
3、统计下面字符串中每个字符出现的频率
const str = 'ghsdhkjjggsfaf';
const result = [...str].reduce((r,c)=>(r[c]++ || (r[c] = 1),r),{});