Skip to content

Instantly share code, notes, and snippets.

@mh61503891
Last active March 12, 2020 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mh61503891/f2033f13042de0e1d0e379040ca876e4 to your computer and use it in GitHub Desktop.
Save mh61503891/f2033f13042de0e1d0e379040ca876e4 to your computer and use it in GitHub Desktop.
Search mails by labels in Inbox - mail.google.com
// ==UserScript==
// @name Search mails by labels in Inbox - mail.google.com
// @namespace https://msyk.hgsn.info/
// @match https://mail.google.com/mail/u/*
// @grant GM_registerMenuCommand
// @grant GM_getValue
// @version 1.0
// @author Masayuki Higashino
// ==/UserScript==
function label_names_to_search_uri(label_names) {
let base_uri = document.location.href.split('/').slice(0, 6).join('/');
let search_query = '((label:inbox) AND (' + label_names.map(label_name => 'label:' + label_name).join(' OR ') + '))';
let target_uri = base_uri + '/#search/' + encodeURIComponent(search_query);
return target_uri;
}
function search_mails_by_labels_in_inbox() {
let labels = GM_getValue('labels', []);
let uri = label_names_to_search_uri(labels);
document.location.href = uri;
}
GM_registerMenuCommand("Search mails by labels in Inbox", search_mails_by_labels_in_inbox);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment