Javascript 在greasemonkey脚本中使用google日历
我试图在greasemonkey脚本中使用google日历api。这是我的代码,灵感来自google calender api教程:Javascript 在greasemonkey脚本中使用google日历,javascript,greasemonkey,google-calendar-api,Javascript,Greasemonkey,Google Calendar Api,我试图在greasemonkey脚本中使用google日历api。这是我的代码,灵感来自google calender api教程: // ==UserScript== // @name Google Calender // @namespace xyz // @include * // @version 1 // ==/UserScript== var $ = unsafeWindow.jQuery; API_js_callback = "https://
// ==UserScript==
// @name Google Calender
// @namespace xyz
// @include *
// @version 1
// ==/UserScript==
var $ = unsafeWindow.jQuery;
API_js_callback = "https://apis.google.com/js/api.js";
var script = document.createElement('script');
script.src = API_js_callback;
var head = document.getElementsByTagName("head")[0];
(head || document.body).appendChild(script);
//this is not working
var gapi = unsafeWindow.gapi;
$(document).ready(function()
{
// Client ID and API key from the Developer Console
var CLIENT_ID = 'XXX';
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://www.googleapis.com/auth/calendar.readonly";
handleClientLoad();
/**
* On load, called to load the auth2 library and API client library.
*/
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
.........
}
});
在handleClientLoad
方法中,我得到了以下异常:
Cannot read property 'load' of undefined
有什么想法吗?我可以让它在我这边工作,也许是加载时间阻止了这个变量,试着移动
var gapi=unsafeWindow.gapi函数$(document)中的code>。ready(function()
我尝试了这个方法,但是gapi变量仍然没有定义。也许您必须使用类似https://calendar.google.com/calendar/*
include说明脚本应该在哪里执行(在哪些页面上),而不是应该包含的内容。由于此类页面加载了许多子域,每个子域都会触发脚本,这就是我测试iti的方式,可能是加载时间阻止了此变量,请尝试在函数$(document).ready(function()内移动var gapi=unsafeWindow.gapi;
)
我尝试了这个方法,但是gapi变量仍然没有定义。也许您必须使用类似于https://calendar.google.com/calendar/*
include说明脚本应该在哪里执行(在哪些页面上),而不是应该包含的内容。由于此类页面加载了许多子域,因此每个子域都会触发脚本,我就是这样测试它的