Last active
October 13, 2016 21:41
-
-
Save Mido22/5b14c63636b3874902e47a8e1f6c4f74 to your computer and use it in GitHub Desktop.
for google inbox, select all and delete all buttons
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 gmail mark read | |
// @match https://inbox.google.com/* | |
// @version 1.0.3 | |
// @grant none | |
// @namespace https://gist.github.com/Mido22 | |
// @downloadURL https://gist.github.com/Mido22/5b14c63636b3874902e47a8e1f6c4f74 | |
// ==/UserScript== | |
(function(w, d){ | |
'use strict' | |
let cget = 'getElementsByClassName' | |
w.addEventListener('load', () => { | |
addButton('select read', selectReadFn) | |
addButton('select all', selectAll, {left:'18%'}) | |
addButton('delete all', delAll, {bottom: '10%', left:'18%'}) | |
addButton('delete read', delRead, {bottom: '10%'}) | |
}) | |
function delAll() { | |
selectAll(); | |
deleteMails(); | |
} | |
function delRead() { | |
selectReadFn(); | |
deleteMails(); | |
} | |
function addButton(text, onclick, cssObj) { | |
cssObj = cssObj || {} | |
let dflt = {position: 'fixed', bottom: '7%', left:'13%', 'z-index': 3} | |
Object.keys(dflt).filter(k => !cssObj[k]).forEach(k => cssObj[k]=dflt[k]) | |
let button = d.createElement('button'), btnStyle = button.style | |
d.body.appendChild(button) | |
button.innerHTML = text | |
button.onclick = onclick | |
btnStyle.position = 'absolute' | |
Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key]) | |
return button | |
} | |
function selectReadFn() { | |
[...d[cget]('MN')].filter(isRead).forEach(e => e.click()) | |
} | |
function deleteMails() { | |
d.querySelector('.itemIconTrash').click() | |
} | |
function selectAll() { | |
[...d[cget]('MN')].forEach(e => e.click()) | |
} | |
function isRead(e) { | |
let p = 'parentElement' | |
return ![...e[p][p][p][cget]('G3')].some(e => e.innerText.search(/unread/i)!==-1) | |
} | |
}(window, document)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment