删除Google表格的书签

时间:2018-10-01 17:15:48

标签: javascript google-sheets bookmarklet

我正在寻找一个书签,它将删除当前的Google表格(而不是"Move to bin"菜单选项)。从JavaScript中可以看到"File">"Move to bin"代码如下:

Ih = Ak(uk("docs-trash").label("Move to bin").Ea(765), "trash").dc("bin | delete | remove ||").build();

我认为解决方案可能是:    javascript: document.getElementById("docs-trash").click();

我走错路了吗?

1 个答案:

答案 0 :(得分:1)

我希望这样对您有所帮助:

javascript:(function() {
    var eltMove = document.querySelector('#\\:b2>div>span');
    fireMouseEvent(document.querySelector('#docs-file-menu'), 'mousedown');
    fireMouseEvent(eltMove, 'mousedown');
    fireMouseEvent(eltMove, 'mouseup');
    fireMouseEvent(eltMove, 'mouseup');

    function fireMouseEvent(eltTarget, myEvent) {
        var screenX, screenY, clientX, clientY;
        var event = document.createEvent('MouseEvents');
        event.initMouseEvent(myEvent, true, true, window, 1, screenX, screenY, clientX, clientY, false, false, false, false, 0, null);
        eltTarget.dispatchEvent(event);
    }
})();