在当前弹出窗口中获取事件描述

时间:2015-10-05 08:27:16

标签: javascript google-calendar-api tampermonkey

我目前正在尝试编写自己的tampermonkey脚本,将事件的描述插入到Google日历中的弹出窗口中。 (编辑:点击时显示特定事件详情的弹出窗口)

不幸的是,谷歌日历内部的JS库隐藏了实际的请求/链接(所以我不知道实际执行了什么POST / GET请求或者它是如何生成的 - 它只是" javascript:void(0 )"。)

因此,我提出了三种不同的解决方案(每个问题都有一个问题):

  • 是否可以使用tampermonkey查找Google日历中当前显示的弹出窗口的事件ID? (之后我可以使用官方JavaScript API)
  • 是否可以在tampermonkey中克隆完整的网站上下文?这将允许我执行单击(在不同的上下文中,因此不更改当前页面),解析描述并在当前上下文中重用它。
  • 是否有可能(在合理的时间内)找出" javascript:void(0)"之后执行的确切内容?单击以对请求创建进行反向工程(这也意味着我必须能够访问javascript的当前事件ID的上下文f.e.)。

感谢您的回答/帮助!

修改
我已经可以访问窗口的JS上下文(使用@grant unsafeWindow),但如果我能在上下文中找到事件的ID(直到现在都找不到它)我仍然会必须手动调用Google Calendar API。我想知道是否有更简单的方法来查找当前显示事件的描述(在当前事件弹出窗口中)。

我当前的代码如下所示(我要阅读说明的部分标有TODO):

// ==UserScript==
// @name         EnhanceGCal
// @version      0.1
// @description  Script to enhance the Google Calendar popup view
// @license      Apache License 2.0
// @match        https://www.google.com/calendar/*
// @grant        unsafeWindow
// @require      http://code.jquery.com/jquery-latest.js
// @require      https://apis.google.com/js/client.js?onload=checkAuth
// ==/UserScript==

console.log('Started....')

// check if the bubble is available
if (!$('.bubblecontent').length) { console.log('Nothing found...'); return; }

// Try enhance the popup everytime it is created
$('.bubblecontent').bind("DOMSubtreeModified", function() {
    var table, tbody, tr, td1, td2;
    table = document.getElementsByClassName('eb-data')[0];
    if (!table) { return; }
    tbody = table.childNodes[0];
    if (!tbody) { return; }

    if (window.currentlyEditing) { return; }
    window.currentlyEditing = true;

    // add a new table row for the description
    if (!$('#enhanceGCalDescriptionRow').length) {
        tr = document.createElement('tr');
        tr.id = 'enhanceGCalDescriptionRow';
        td1 = document.createElement('td');
        td1.innerHTML="<b>Description</b>";
        td2 = document.createElement('td');
        td2.innerHTML="Description text";
        td2.id = 'enhanceGCalDescriptionText';
        tr.appendChild(td1);

        tr.appendChild(td2);
        tbody.appendChild(tr);
    }

    // TODO read the description of the current event and set it in the new table column
    $('#enhanceGCalDescriptionText').text('Enter description of the event in the popup here...');

    window.currentlyEditing = false;
});

0 个答案:

没有答案