如何同时使用 Javascript 完成 CTRL + F 和 CMD + F 功能

问题描述

我想用 ctrl + f 启用 cmd + fJavascript。到目前为止,我已经能够执行 ctrl + f 功能,但我不知道如何同时启用。

这是我目前所拥有的:

window.addEventListener('keydown',(e) => {
    if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
        alert('working');
    }
})

这是一个 this question

编辑 1:如果我可以在 Mac 上运行 cmd + f 或在 Windows 上运行 ctrl + f 那就更好了。

编辑 2:我尝试了以下 code playground,但我无法工作...

解决方法

我让它像这样工作:

    test_dict = {1: 'Okay',2: 'not good',3: 'not well',4: 'fine',5: 'not good'}
    new_dict = {}
    no_of_chunks = 0
    values_greater_size = 0
    for key,val in test_dict.items():
        if len(val) > 4:
            chunks = [val[i:i + 4] for i in range(0,len(val),4)]
            for new_val in chunks:
                new_dict.update({key + no_of_chunks - values_greater_size: new_val})
                no_of_chunks = no_of_chunks + 1
            values_greater_size = values_greater_size + 1
        else:
            new_dict.update({key + no_of_chunks - values_greater_size: val})
    print(new_dict)

这是一个 working code sample