* Исправил debug-плашку для Point+

+ Добавил автосохранение черновиков
This commit is contained in:
Nokita Kaze 2014-11-24 16:20:19 +03:00
parent 79fad70964
commit 3d9e54b62d
3 changed files with 77 additions and 13 deletions

View file

@ -215,14 +215,10 @@ div#markItUpText-input {
/* point-plus-debug */ /* point-plus-debug */
.point-plus-debug{ .point-plus-debug{
position: absolute; float: right;
padding: 10px 20px; display: block;
top: 60px; color: rgba(255,255,255,.75);
left: 20px; padding: 10px 0px;
border-radius: 3px;
border: 1px solid #333;/* @todo Сделать не такой галимый */
background-color: #ddd;/* @todo Аналогично */
z-index: 11;
} }
.post-tag-nsfw.hide-nsfw-posts, .post-tag-nsfw.hide-nsfw-posts,
@ -230,3 +226,22 @@ div#markItUpText-input {
display: none; display: none;
} }
/* Черновики */
#new-post-form #text-input{
height: 30em !important;
}
#new-post-form .draft_save_status{
display: none;
padding: 3px 5px;
color: green;
}

View file

@ -14,11 +14,17 @@ $(document).ready(function() {
} }
point_plus_debug = null; point_plus_debug = null;
var new_div = document.createElement('div'); var new_div = document.createElement('div');
document.body.appendChild(new_div);
$(new_div).attr({ $(new_div).attr({
'data-point-plus-version': getVersion() 'data-point-plus-version': getVersion()
}).addClass('point-plus-debug').html('Point+ v' + getVersion() + ' loading...').hide(); }).addClass('point-plus-debug').html('Point+ v' + getVersion() + ' loading...');
var obj = $('#user-menu-cb')[0];
obj.parentElement.insertBefore(new_div, obj);
new_div = null; new_div = null;
obj = null;
// Черновики. Ставим хандлер и восстанавливаем предыдущее состояние
draft_set_save_handler();
draft_restore();
// Loading options // Loading options
chrome.storage.sync.get('options', function(options_data) { chrome.storage.sync.get('options', function(options_data) {
@ -895,3 +901,46 @@ function space_key_event() {
} }
} }
} }
/* Автосохранение черновиков */
var draft_last_text = '';// Последний зафиксированный текст
function draft_restore() {
chrome.storage.sync.get('point_draft_text', function(items) {
$('#new-post-form #text-input').val(items.point_draft_text);
draft_last_text=items.point_draft_text;
});
}
function draft_set_save_handler() {
setInterval(draft_save_check, 5000);
$('#new-post-wrap .footnote').html($('#new-post-wrap .footnote').html() + '<div class="draft_save_status"></div>');
}
var draft_save_busy = false;
function draft_save_check() {
if (draft_save_busy) {
return;
}
draft_save_busy = true;
// Видишь поиск id внутри id?.. ненавидишь меня?
var current_text = $('#new-post-form #text-input').val();
if (draft_last_text == current_text) {
draft_save_busy = false;
return;
}
// @todo i18n
$('.draft_save_status').html('Сохраняем черновик...').show();
// Сохраняем
draft_last_text=current_text;
// Save it using the Chrome extension storage API.
chrome.storage.sync.set({'point_draft_text': draft_last_text}, function() {
// Notify that we saved.
draft_save_busy=false;
$('.draft_save_status').html('Черновик сохранён...');
setTimeout(function(){
$('.draft_save_status').fadeOut(500);
}, 1000);
});
}

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Point+", "name": "Point+",
"version": "1.15.1", "version": "1.16.0",
"default_locale": "ru", "default_locale": "ru",
"author": "__MSG_ext_author__", "author": "__MSG_ext_author__",
"homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus", "homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus",