Last active
August 29, 2015 14:07
-
-
Save Barbayar/5fa8e9b6deecb31d403d to your computer and use it in GitHub Desktop.
[Gmail] Select All & Delete
This file contains hidden or 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
// jQuery injection | |
var jq = document.createElement('script'); | |
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"; | |
document.getElementsByTagName('body')[0].appendChild(jq); | |
// http://stackoverflow.com/questions/6157929/how-to-simulate-mouse-click-using-javascript | |
// jQuery-ын mousedown, mouseup ашиглахаар болохгүй байгаа. Яагаад гэдгийг мэдэхгүй | |
function simulate(element, eventName) | |
{ | |
var options = extend(defaultOptions, arguments[2] || {}); | |
var oEvent, eventType = null; | |
for (var name in eventMatchers) | |
{ | |
if (eventMatchers[name].test(eventName)) { eventType = name; break; } | |
} | |
if (!eventType) | |
throw new SyntaxError('Only HTMLEvents and MouseEvents interfaces are supported'); | |
if (document.createEvent) | |
{ | |
oEvent = document.createEvent(eventType); | |
if (eventType == 'HTMLEvents') | |
{ | |
oEvent.initEvent(eventName, options.bubbles, options.cancelable); | |
} | |
else | |
{ | |
oEvent.initMouseEvent(eventName, options.bubbles, options.cancelable, document.defaultView, | |
options.button, options.pointerX, options.pointerY, options.pointerX, options.pointerY, | |
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, options.button, element); | |
} | |
element.dispatchEvent(oEvent); | |
} | |
else | |
{ | |
options.clientX = options.pointerX; | |
options.clientY = options.pointerY; | |
var evt = document.createEventObject(); | |
oEvent = extend(evt, options); | |
element.fireEvent('on' + eventName, oEvent); | |
} | |
return element; | |
} | |
function extend(destination, source) { | |
for (var property in source) | |
destination[property] = source[property]; | |
return destination; | |
} | |
var eventMatchers = { | |
'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/, | |
'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/ | |
} | |
var defaultOptions = { | |
pointerX: 0, | |
pointerY: 0, | |
button: 0, | |
ctrlKey: false, | |
altKey: false, | |
shiftKey: false, | |
metaKey: false, | |
bubbles: true, | |
cancelable: true | |
} | |
var timer = setInterval(function() { | |
var selectAllCheckBox = jQuery('.T-Jo.J-J5-Ji.T-Jo-auq.T-Jo-aMF'); | |
if (selectAllCheckBox.length === 1) { | |
// Select All | |
jQuery('.T-Jo.J-J5-Ji.T-Jo-aMF').click(); | |
// Delete | |
simulate(jQuery('.T-I.J-J5-Ji.nX.T-I-ax7.T-I-Js-Gs.ar7').get(0), 'mousedown'); | |
simulate(jQuery('.T-I.J-J5-Ji.nX.T-I-ax7.T-I-Js-Gs.ar7').get(0), 'mouseup'); | |
} | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment