Vimeo Player Custom Buttons

Add an interface to add custom buttons to embeded Vimeo players

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Vimeo Player Custom Buttons
// @namespace    http://PennyJim.com/
// @version      6
// @description  Add an interface to add custom buttons to embeded Vimeo players
// @author       PennyJim
// @match        https://embed.vhx.tv/videos/*
// @grant        none
// @license      GNU GPLv3
// ==/UserScript==


function addMessageHandler(handler) {
	if (window.onmessage === null)
	{
		window.onmessage = handler;
	} else {
		let oldHandler = window.onmessage
		window.onmessage = function(e) {
			oldHandler(e);
			handler(e);
		}
	}
}

//function addPlayerButton(name, callBack, width, icon, beforeWhat) {
function addPlayerButton(data, origin) {
    let newBtn = document.createElement("button")
	newBtn.classList.add(data.name)
	newBtn.onclick = event => {
		window.top.postMessage({method: data.callBack}, origin)
	}
	newBtn.innerHTML = data.icon;
	newBtn.style.width = data.width;
	newBtn.style.height = "100%";
	newBtn.style.marginLeft = "1em";
	document.querySelector(".vp-controls > div").insertBefore(newBtn, document.querySelector(data.beforeWhat));
	console.log(`${data.name} Button Added`);
	window.top.postMessage({method: "eventCall", event: "buttonAdded"}, origin);
}


(function() {
    'use strict';
	addMessageHandler(function(e) {
		let data = e.data
		if (data.method == "addPlayerButton") {
			addPlayerButton(data, e.origin);
		}
	});
})();