分配键盘快捷键以暂停网站中的音乐

Ami*_*ela 2 browser keyboard-shortcuts media-keys macos

我使用saavn.com来听宝莱坞音乐。这是一项很棒的服务,但他们没有本地 mac 应用程序,所以我无法使用键盘媒体键来控制它。

必须有一种方法可以使用键盘媒体键来控制所有音乐。

Lri*_*Lri 6

您可以为脚本分配一个快捷方式,如下所示:

tell application "Safari"
    repeat with t in documents
        tell t
            if URL starts with "http://www.saavn.com/" then
                do JavaScript "e = document.querySelectorAll('#pause:not(.hide)')[0] || document.querySelectorAll('#play:not(.hide)')[0]; e.click()"
                exit repeat
            end if
        end tell
    end repeat
end tell
Run Code Online (Sandbox Code Playgroud)

YouTube 和 Chrome 的类似脚本:

tell application "Google Chrome"
    repeat with t in tabs of windows
        tell t
            if URL starts with "http://www.youtube.com" then
                execute javascript "player = document.querySelectorAll('#player embed')[0]
if (player) {
    player.getPlayerState() == 1 ? player.pauseVideo() : player.playVideo()
} else { // if youtube.com/html5 is enabled
    document.querySelectorAll('.html5-player-chrome > button:first-child')[0].click()
}"
                exit repeat
            end if
        end tell
    end repeat
end tell
Run Code Online (Sandbox Code Playgroud)