Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Google docs
- // @include https://*docs.google.*/document/*
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
- // ==/UserScript==
- // sources:
- // for iframe https://stackoverflow.com/a/46217408/3154274
- // for switch https://stackoverflow.com/q/13362028/3154274
- // combinaison of key https://stackoverflow.com/a/37559790/3154274
- // dispatchEvent https://stackoverflow.com/a/33887557/3154274
- // simulate keypress https://stackoverflow.com/a/26863396/3154274 or https://stackoverflow.com/a/5920206/3154274
- // js key code http://keycode.info/
- // listen for key shorcuts on the text part of google gocs
- var editingIFrame = $('iframe.docs-texteventtarget-iframe')[0];
- if (editingIFrame) {
- editingIFrame.contentDocument.addEventListener("keydown", hook, false);
- }
- // match the key with the color
- function hook(key) {
- if (key.altKey && key.code === "KeyQ") {
- var button = document.getElementById("zoomSelect");
- callMouseEvent(button);
- keyEvent(button);
- }
- }
- //call each mouse event
- function callMouseEvent(button){
- triggerMouseEvent (button, "mouseover");
- triggerMouseEvent (button, "mousedown");
- triggerMouseEvent (button, "mouseup");
- }
- // send mouse even
- function triggerMouseEvent (node, eventType) {
- var eventObj = document.createEvent('MouseEvents');
- eventObj.initEvent (eventType, true, true);
- node.dispatchEvent (eventObj);
- }
- // send keyboard event
- function keyEvent(node) {
- var eventObj = document.createEvent("KeyboardEvent");
- (eventObj.initKeyEvent || eventObj.initKeyboardEvent)("keypress", true, true, null,
- 0, 0, 0, 0,
- 0, character.charCodeAt(9));
- node.dispatchEvent(eventObj);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement