I'm using GM to write a custom script for a website. The script adds an embed Youtube player to the page, so I'm calling the Youtube API. Here is the beginning of the code :
// ==UserScript==
// @author mens
// @match http://thewebsite.com
// @grant none
// ==/UserScript==
///////////// YOUTUBE
// API
var player;
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// API loaded
window.onYouTubeIframeAPIReady = function()
{
console.log("API loaded");
}
With this code, everything works fine. The first few lines call the API, when it's loaded it fires onYouTubeIframeAPIReady, then later on my script generates the player.
You will notice that @grant is set to none. The problem is when I change this line, even the slightest. I use GM_getResourceURL to access external files (like graphics).
So when I set :
// @grant GM_getResourceURL
...the API doesn't work anymore : onYouTubeIframeAPIReady is never called !
From what I gathered in the GM documentation, @grant none is the default mode that means maximum access to all APIs used in the code. When changing @grant more restrictions may appear... I think that's part of the problem but I have no idea how to work with it.
Thanks for your help !!