Skip to content

Instantly share code, notes, and snippets.

@mintsoft
Last active March 16, 2019 16:41
Show Gist options
  • Save mintsoft/dd426d54b93707a62a19cecaac1eb163 to your computer and use it in GitHub Desktop.
Save mintsoft/dd426d54b93707a62a19cecaac1eb163 to your computer and use it in GitHub Desktop.
GMail - HTML - Mark Page As Read
// ==UserScript==
// @name GMail - Mark Page As Read
// @namespace gmail
// @include https://mail.google.com/*
// @version 1
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Add From Box
if(document.getElementById("cc") != null)
{
var cc_tr = document.getElementById("cc").parentNode.parentNode;
var from_row = document.createElement("tr");
var label_td = document.createElement("td");
label_td.innerHTML = "<b>From:</b>";
label_td.align = "right";
from_row.appendChild(label_td);
var to_box_td = document.createElement("td");
to_box_td.innerHTML = '<input name="from" id="from" value="" size="40" class="i" autocomplete="off" type="text">';
from_row.appendChild(to_box_td);
cc_tr.parentNode.insertBefore(from_row, cc_tr);
}
var leftmost_button = document.getElementsByName('nvp_a_arch')[0] || document.getElementsByName('nvp_bu_rl')[0] || document.getElementsByName('nvp_a_dl')[0] || document.getElementsByName('nvp_a_sp')[0];
if(leftmost_button) {
var maar_btn = document.createElement('button');
maar_btn.name = 'x-re-mark-all-as-read';
maar_btn.innerHTML = 'M-A-A-R';
maar_btn.onclick = function () {
// drop down:
document.getElementsByName('tact')[0].value = 'rd';
//all checkboxes:
var boxes = document.getElementsByName('t');
for (var x = 0; x < boxes.length; ++x) {
boxes[x].checked = true;
}
document.getElementsByName('nvp_tbu_go')[0].click();
};
var maa = document.createElement("input");
maa.type = "checkbox";
maa.name = "x-re-mark-all";
maa.onclick = function() {
var boxes = document.getElementsByName('t');
for (var x = 0; x < boxes.length; ++x) {
boxes[x].checked = maa.checked;
}
};
var selectAllunread = document.createElement('button');
selectAllunread.name = 'x-re-select-add-unread';
selectAllunread.innerHTML = 'S-A-U';
selectAllunread.onclick = function () {
var boxes = document.getElementsByName('t');
for (var x = 0; x< boxes.length ; ++x) {
if(boxes[x].parentNode.parentNode.bgColor == '#ffffff')
boxes[x].checked = true;
}
return false;
};
leftmost_button.parentNode.insertBefore(maar_btn, leftmost_button);
leftmost_button.parentNode.insertBefore(selectAllunread, maar_btn);
leftmost_button.parentNode.insertBefore(maa, selectAllunread);
}
})();
@mintsoft
Copy link
Author

There are a few features missing from the incredibly fast HTML view of GMail; this crowbars some stuff into the DOM to do some of the functions I miss (select all is the big one!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment