Skip to content

Instantly share code, notes, and snippets.

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 chestozo/2235311 to your computer and use it in GitHub Desktop.
Save chestozo/2235311 to your computer and use it in GitHub Desktop.
кнопка «Архив» для почты Яндекса
// «archive» button for yandex mail
// version 0.1.5
// 2012-03-28
//
// ==UserScript==
// @name «Yandex Mail Archive button»
// @namespace http://gurugray.ru
// @description Создаём кнопку «В архив» на web-почте Яндекса
// @include http*://mail.yandex*/neo2/*
// ==/UserScript==
var __msgRegExp = /message\//,
__showedButton = false,
__archiveTitle = 'Архив';
setTimeout(function(){
__init();
}, 1000);
setInterval(__eventLoop, 250);
function __eventLoop(){
if ((__isMailChecked() || __isReadingMessage()) && !__isArchiveFolder()) {
__showButton();
} else {
__hideButton();
}
}
function __isReadingMessage(){
return __msgRegExp.test(unsafeWindow.location.hash);
}
function _$(path) {
return document.querySelectorAll(path);
}
function __init(){
var a = document.createElement('a');
a.className = 'b-toolbar__item b-toolbar__item_archive',
a.href = '#archive';
a.style.display = 'none';
a.style.width = '5em';
a.title = 'В архив'
a.innerHTML = '<img class="b-ico b-ico_compose" src="https://mailstatic.yandex.net/neo2/5.6.21/static/lego/blocks/b-ico/b-ico.gif" style="background-position-x: -216px;"><span class="b-toolbar__item__label">В архив</span><span class="b-toolbar__item__selected b-toolbar__item__selected_left-border"></span><span class="b-toolbar__item__selected b-toolbar__item__selected_right-border"></span>';
var chevron = _$('.b-toolbar__block_chevron')[0];
chevron.insertBefore(a, chevron.firstChild);
__locationHash = unsafeWindow.location.hash;
__addSingleEvents();
}
function __isArchiveFolder(){
var archive = _$('a.daria-action[title="'+__archiveTitle+'"]')[0];
return archive && archive.href == unsafeWindow.location;
}
function __addSingleEvents(){
_$('.b-toolbar__item_archive')[0].addEventListener('click', function(event){
event.stopPropagation();
event.preventDefault();
_$('a.daria-action[title="'+__archiveTitle+'"]')[0].click();
return false;
}, false);
}
function __showButton(){
if (!__showedButton) {
_$('.b-toolbar__item_archive')[0].style.display = 'inline-block';
__showedButton = true;
}
}
function __hideButton(){
if (__showedButton) {
_$('.b-toolbar__item_archive')[0].style.display = 'none';
__showedButton = false;
}
}
function __isMailChecked(){
return ( !!_$('.block-messages:not([style^="display"]) .b-messages__message__checkbox__input:checked').length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment