Skip to content

Instantly share code, notes, and snippets.

@kane-c
Last active September 4, 2018 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kane-c/884fe804e3a04a09739e4bf8f7ea7804 to your computer and use it in GitHub Desktop.
Save kane-c/884fe804e3a04a09739e4bf8f7ea7804 to your computer and use it in GitHub Desktop.
BeardedSpice strategy to un/mute Google Hangouts via media keys/headphones button
//
// GoogleHangouts.js
// BeardedSpice
//
// Created by @kane-c.
// Copyright (c) 2015-2017 GPL v3 http://www.gnu.org/licenses/gpl.html
//
// We put the copyright inside the plist to retain consistent syntax coloring.
BSStrategy = {
version: 1,
displayName: "Google Hangouts",
accepts: {
method: "predicateOnTab",
format: "%K LIKE[c] '*hangouts.google.com/hangouts/_/*'",
args: ["URL"]
},
isPlaying: function () {
var button = document.querySelector(".IQ");
return button && button.getAttribute("aria-pressed") === "false";
},
toggle: function () {
function simulate(target, evtName) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent(evtName, true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, target);
target.dispatchEvent(evt);
}
function simulateClick(target) {
simulate(target, "mouseover");
simulate(target, "mousedown");
simulate(target, "mouseup");
simulate(target, "mouseout");
}
simulateClick(document.querySelector(".IQ"), "click");
},
previous: function () {},
next: function () {},
pause: function () {
var button = document.querySelector(".IQ");
if (button.getAttribute("aria-pressed") === "false") {
function simulate(target, evtName) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent(evtName, true, true, document.defaultView, 0, 0, 0, 0, 0, false, false, false, false, 0, target);
target.dispatchEvent(evt);
}
function simulateClick(target) {
simulate(target, "mouseover");
simulate(target, "mousedown");
simulate(target, "mouseup");
simulate(target, "mouseout");
}
simulateClick(button, "click");
}
},
favorite: function () {},
trackInfo: function () {
var pathName = window.location.pathname.split("/");
var track = pathName.pop();
var album = pathName.pop();
return {
track: track,
album: album,
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment