-
-
Save inkhsutesou/d3b69a395fe1b7d0b7a996723477a001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Google Docs SHIFT+D Delete | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Use SHIFT+D to delete files fast | |
// @author Inkh Su Tesou | |
// @match https://docs.google.com/document/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
console.log( ` - Delete files with SHIFT+D` ) | |
const simulateMouseEvent = function ( element, eventName ) { | |
const bbox = element.getBoundingClientRect(), | |
clientX = bbox.left + ( bbox.right - bbox.left ) / 2, | |
clientY = bbox.top + ( bbox.bottom - bbox.top ) / 2 | |
element.dispatchEvent( new MouseEvent( eventName, { | |
view : window, | |
bubbles : true, | |
cancelable : true, | |
clientX, | |
clientY, | |
button : 0 | |
} ) ) | |
} | |
let target | |
let onkeypress = e => { | |
if ( e.which !== 68 || !e.shiftKey ) { return } | |
while ( !target.classList.contains( `docs-homescreen-list-item` ) ) { target = target.parentNode } | |
const parent = target | |
const menuToggle = target.querySelector( `[aria-label="More actions. Popup button."]` ) | |
menuToggle.click() | |
let i = 0 | |
console.log( parent ) | |
Array.from( parent.querySelectorAll( `div` ) ).forEach( node => { | |
if ( node.innerHTML === `Remove` ) { | |
const toClick = node.parentNode.parentNode.parentNode.parentNode | |
console.log( node, toClick ) | |
simulateMouseEvent ( toClick, `mousedown` ) | |
simulateMouseEvent ( toClick, `mouseup` ) | |
simulateMouseEvent ( toClick, `click` ) | |
document.querySelector('[name="moveToTrash"]').click() | |
} | |
} ) | |
} | |
let onmousemove = e => { | |
target = e.target | |
} | |
document.body.addEventListener( `mousemove`, onmousemove, false ) | |
document.body.addEventListener( `keypress`, onkeypress, false ) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment