From 6110aa6785f2d87e0f7dadcc6128b75013b85550 Mon Sep 17 00:00:00 2001
From: Nokita Kaze
Date: Fri, 26 Dec 2014 11:42:48 +0300
Subject: [PATCH] =?UTF-8?q?+=20=D0=A1=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=B0?=
=?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?=
=?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B8=D1=85=20=D0=BA=D0=BE=D0=BC=D0=BC?=
=?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B5=D0=B2=20=D0=BA=20?=
=?UTF-8?q?=D0=B4=D1=80=D1=83=D0=B3=D0=B8=D0=BC=20=D0=BF=D0=BE=D0=BB=D1=8C?=
=?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=D0=BC=20https:?=
=?UTF-8?q?//bitbucket.org/skobkin/chrome=5Fpoint=5Fplus/issue/50/--------?=
=?UTF-8?q?-------------------?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
chrome_point_plus/css/point-plus.css | 52 +++++++++++-
chrome_point_plus/js/point-plus.js | 118 +++++++++++++++++++++++++++
2 files changed, 169 insertions(+), 1 deletion(-)
diff --git a/chrome_point_plus/css/point-plus.css b/chrome_point_plus/css/point-plus.css
index 177851a..db76034 100644
--- a/chrome_point_plus/css/point-plus.css
+++ b/chrome_point_plus/css/point-plus.css
@@ -235,4 +235,54 @@ div#markItUpText-input {
display: block;
color: rgba(255,255,255,.75);
padding: 10px 0px;
-}
\ No newline at end of file
+}
+
+/* User hints */
+.current-user-hint{
+ min-height: 30px;
+ position: relative;
+}
+
+.current-user-hint .edit {
+ position: absolute;
+ right: 5px;
+ top: 5px;
+ display: none;
+ background-image: url("//point.im/img/btn-edit.png");
+ background-size: 100% 100%;
+ width: 16px;
+ height: 16px;
+}
+
+.current-user-hint:hover .edit {
+ display: block;
+}
+
+.current-user-hint > .text{
+ margin: 1em 0;
+ color: green;
+ font-style: italic;
+}
+
+.aside .aside-content #counters{
+ clear: both;
+}
+
+.current-user-hint .change_hint_block{
+
+}
+
+.current-user-hint .change_hint_block textarea{
+ width: 98%;
+ max-width: 98%;
+ margin-bottom: 10px;
+ height: 140px;
+}
+
+.current-user-hint .change_hint_block .button_save{
+ margin-right: 10px;
+}
+
+.current-user-hint .change_hint_block .button_cancel{
+
+}
diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js
index b102784..5b42fe5 100644
--- a/chrome_point_plus/js/point-plus.js
+++ b/chrome_point_plus/js/point-plus.js
@@ -497,6 +497,9 @@ $(document).ready(function() {
set_space_key_skip_handler();
}
+ // Система комментариев у пользователей
+ hints_init_user_system();
+
$('#point-plus-debug').fadeOut(1000);
});
});
@@ -1031,3 +1034,118 @@ function fancybox_set_smart_hints(){
all_post_images.attr('data-fancybox-title', hint_text);
});
}
+
+/**
+ * Система заметок о пользователях
+ * https://bitbucket.org/skobkin/chrome_point_plus/issue/50/---------------------------
+ */
+// Инициализируем
+function hints_init_user_system() {
+ chrome.storage.sync.get('point_user_hints', function (items) {
+ if (typeof(items.point_user_hints) == 'undefined') {
+ // Первый запуск системы
+ chrome.storage.sync.set({'point_user_hints': {}}, function () {
+ hints_draw_main_user_hint({});
+ hints_set_titles_on_users({});
+ });
+ } else {
+ // Второй+ запуск системы
+ hints_draw_main_user_hint(items.point_user_hints);
+ hints_set_titles_on_users(items.point_user_hints);
+ }
+ });
+}
+
+// Рисуем хинт и кнопку под текущим пользователем
+function hints_draw_main_user_hint(items) {
+ var current_user_name = $('.aside .info h1').text().toLowerCase();
+ if (current_user_name.length == '') {
+ return;
+ }
+
+ var current_user_hint_block = document.createElement('div');
+ $('.aside .aside-content #counters')[0].parentElement.
+ insertBefore(current_user_hint_block, $('.aside .aside-content #counters')[0]);
+ $(current_user_hint_block).addClass('current-user-hint');
+
+ // Рисуем кнопки управления
+ var buttons_block = document.createElement('div');
+ $(buttons_block).addClass('buttons').
+ html('');
+ current_user_hint_block.appendChild(buttons_block);
+ $(buttons_block).find('.edit').on('click', function () {
+ chrome.storage.sync.get('point_user_hints', function (items) {
+ var current_text = '';
+ if (typeof(items.point_user_hints[current_user_name]) !== 'undefined') {
+ current_text = items.point_user_hints[current_user_name];
+ }
+
+ $('.current-user-hint .change_hint_block').slideDown(500);
+ $('.current-user-hint .change_hint_block textarea').val(current_text);
+ });
+ });
+
+ // Рисуем текст
+ var current_text = '';
+ if (typeof(items[current_user_name]) !== 'undefined') {
+ current_text = items[current_user_name];
+ }
+ var text_block = document.createElement('div');
+ $(text_block).addClass('text').html(hints_raw_text_to_html(current_text));
+ current_user_hint_block.appendChild(text_block);
+
+ // Рисуем невидимый блок для управления
+ var change_hint_block = document.createElement('div');
+ $(change_hint_block).addClass('change_hint_block').hide().
+ html('' +
+ 'Отмена');
+ $(change_hint_block).find('.button_save').on('click', function () {
+ $('.current-user-hint .change_hint_block').slideUp(500);
+ var new_text = $('.current-user-hint .change_hint_block textarea').val();
+ $('.current-user-hint > .text').hide().html(hints_raw_text_to_html(new_text)).fadeIn(750);
+ hints_save_new_hint(current_user_name, new_text);
+ });
+ $(change_hint_block).find('.button_cancel').on('click', function () {
+ $('.current-user-hint .change_hint_block').slideUp(500);
+ });
+ current_user_hint_block.appendChild(change_hint_block);
+}
+
+// Превращаем сырой текст в нормальный, обёрнутый в p
+function hints_raw_text_to_html(text) {
+ // @todo проверить как работает
+ text = text
+ .replace('&', "&")
+ .replace('<', "<")
+ .replace('>', ">")
+ .replace('"', """)
+ .replace("'", "'")
+ .replace(/\r?\n/g, "
")
+ return '
' + text + '
';
+}
+
+// Рисуем title'ы на всех доступных пользователях, точнее на их аватарках
+function hints_set_titles_on_users(items) {
+ $('a').each(function () {
+ var n = $(this).attr('href').match(new RegExp('^https?\\://([0-9a-z-]+)\\.point\\.im/$'));
+ if (n == null) {
+ return;
+ }
+ var this_user_name = n[1].toLowerCase();
+ if (typeof(items[this_user_name]) == 'undefined') {
+ return;
+ }
+
+ $(this).attr({
+ 'title': items[this_user_name]
+ });
+ });
+}
+
+// Сохраняем новый хинт
+function hints_save_new_hint(username, new_hint) {
+ chrome.storage.sync.get('point_user_hints', function (items) {
+ items.point_user_hints[username] = new_hint;
+ chrome.storage.sync.set({'point_user_hints': items.point_user_hints});
+ });
+}