diff --git a/chrome_point_plus/_locales/en/messages.json b/chrome_point_plus/_locales/en/messages.json index 4871642..2cd4fe4 100644 --- a/chrome_point_plus/_locales/en/messages.json +++ b/chrome_point_plus/_locales/en/messages.json @@ -6,9 +6,12 @@ "message": "Alexey Skobkin" }, "ext_page_action_title": { - "message": "Point+ settings" + "message": "Settings" }, + "options_page_title": { + "message": "Point+ settings" + }, "options_text_saved": { "message": "Reload page to apply changes." @@ -95,6 +98,12 @@ "option_embedding_twitter_tweets": { "message": "Twitter" }, + "option_embedding_instagram_posts": { + "message": "Instagram" + }, + "option_embedding_instagram_posts_orig_link": { + "message": "Leave original link" + }, "option_nsfw": { "message": "NSFW content filtering" }, @@ -172,10 +181,13 @@ "message": "Your hints about users" }, "option_other_comments_count_refresh":{ - "message": "Refresh unread posts and comments count in left menu" + "message": "Refresh unread posts and comments count in the sidebar" }, "option_other_comments_count_refresh_title":{ - "message": "Show counts in the title of tabs" + "message": "Page title" + }, + "option_other_post_draft_save":{ + "message": "Save post drafts" }, "options_feedback_text": { @@ -185,5 +197,8 @@ "msg_comment_send_failed":{ "message": "Comment send error:" + }, + "msg_saving_post_draft":{ + "message": "Saving the post..." } } diff --git a/chrome_point_plus/_locales/ru/messages.json b/chrome_point_plus/_locales/ru/messages.json index 8d6b14d..2be940c 100644 --- a/chrome_point_plus/_locales/ru/messages.json +++ b/chrome_point_plus/_locales/ru/messages.json @@ -6,9 +6,12 @@ "message": "Алексей Скобкин" }, "ext_page_action_title": { - "message": "Настройки Point+" + "message": "Настройки" }, + "options_page_title": { + "message": "Настройки Point+" + }, "options_text_saved": { "message": "Для применения изменений перезагрузите страницу." @@ -95,6 +98,12 @@ "option_embedding_twitter_tweets": { "message": "Twitter" }, + "option_embedding_instagram_posts": { + "message": "Instagram" + }, + "option_embedding_instagram_posts_orig_link": { + "message": "Не убирать ссылку" + }, "option_nsfw": { "message": "Фильтрация NSFW-контента" }, @@ -172,10 +181,13 @@ "message": "Заметки о пользователях на полях" }, "option_other_comments_count_refresh":{ - "message": "Обновляем количество непрочитанных комментариев и постов в ленте" + "message": "Обновление количества непрочитанных постов и комментариев в сайдбаре" }, "option_other_comments_count_refresh_title":{ - "message": "Указываем кол-во комментариев и сообщений в заголовке страницы" + "message": "В заголовке страницы" + }, + "option_other_post_draft_save":{ + "message": "Сохранение черновика поста" }, @@ -186,5 +198,8 @@ "msg_comment_send_failed":{ "message": "Ошибка отправки комментария:" + }, + "msg_saving_post_draft":{ + "message": "Сохранение поста..." } } diff --git a/chrome_point_plus/css/point-plus.css b/chrome_point_plus/css/point-plus.css index 5c7ab56..dd943dc 100644 --- a/chrome_point_plus/css/point-plus.css +++ b/chrome_point_plus/css/point-plus.css @@ -28,12 +28,12 @@ div#markItUpText-input { } /* Auto-loaded Booru pictures */ -.booru_pic { +.booru_pic, .instagram-post-embedded { display: block !important; float: none !important; } -.booru_pic img { +.booru_pic img, .instagram-post-embedded img { border: none; max-width: 60%; max-height: 300px; diff --git a/chrome_point_plus/js/bquery_ajax.js b/chrome_point_plus/js/bquery_ajax.js index 553c39c..72a7603 100644 --- a/chrome_point_plus/js/bquery_ajax.js +++ b/chrome_point_plus/js/bquery_ajax.js @@ -1,3 +1,6 @@ +/** + * @deprecated since 1.36.0 + */ function $ajax_prot(settings){ if (settings==undefined){return;} if (settings['url'] ==undefined){return;}this.url=settings['url']; @@ -46,8 +49,14 @@ $ajax_prot.prototype={ $ajax=function (settings){return new $ajax_prot(settings);} +/** + * @deprecated since 1.36.0 + */ function urlencode(text){return encodeURIComponent(text);} +/** + * @deprecated since 1.36.0 + */ function sad_safe_reg(text){ var ar='.-\\/[]{}?+'; var s=''; for (var i=0;i .post'); for (var i = 0; i < posts.length; i++) { - var this_top_px = $(posts[i]).offset().top; - if (this_top_px > scroll_real) { + var this_top_px = Math.floor(posts.eq(i).offset().top); + if (this_top_px > scroll_current) { $('body').animate({ 'scrollTop': this_top_px }, 200); @@ -1111,50 +1106,109 @@ function space_key_event() { } } -/* Автосохранение черновиков */ -var draft_last_text = ''; // Последний зафиксированный текст -// Восстанавливаем черновик +/** + * Last draft text + * @type {string} + */ +var draft_last_text = ''; + +/** + * Last draft tags + * @type {string} + */ +var draft_last_tags = ''; + +/** + * Is extension now saving draft + * @type {boolean} + */ +var draft_save_busy = false; + +/** + * Last draft saving time + * @type {Date|null} + */ +var draft_save_last_time = null; + +/** + * Is there any setTimeout'ed handlers + * @type {boolean} + */ +var draft_waiting = false; + +/** + * Restore draft from localStorage + */ function draft_restore() { - chrome.storage.local.get('point_draft_text', function(items) { - if ($('#new-post-form #text-input').val() == '') { + chrome.storage.local.get(['point_draft_text', 'point_draft_tags'], function(items) { + if ($('#new-post-form #text-input').val() === '') { $('#new-post-form #text-input').val(items.point_draft_text); draft_last_text = items.point_draft_text; } + if ($('#new-post-form #tags-input').val() === '') { + $('#new-post-form #tags-input').val(items.point_draft_tags); + draft_last_tags = items.point_draft_tags; + } }); } -// Установка хандлера +/** + * Set draft save handler + */ function draft_set_save_handler() { - // Господи, прости меня грешного за эту строку. Меня вынудили - $('#text-input').on('keyup', function(){ + $('#text-input, #tags-input').on('keyup', function() { draft_save_check(); + // For last keyup + if (!draft_waiting) { + setTimeout(draft_save_check, 3000); + draft_waiting = true; + } }); + // Adding span indicator $('#new-post-wrap .footnote').append($('')); } -var draft_save_busy = false; -// Фукнция, дёргающаяся по крону, проверяющая надо ли сохранять черновик +/** + * Check if we can save the draft now + */ function draft_save_check() { if (draft_save_busy) { return; } - draft_save_busy = true; + + if (draft_save_last_time !== null) { + if ((new Date()).getTime() < draft_save_last_time.getTime() + 3000) { + return; + } + } var current_text = $('#new-post-form #text-input').val(); - if (draft_last_text == current_text) { + var current_tags = $('#new-post-form #tags-input').val(); + + if ((draft_last_text === current_text) && (draft_last_tags === current_tags)) { draft_save_busy = false; return; } + + draft_save_busy = true; + draft_save_last_time = new Date(); + // @todo i18n - $('#draft-save-status').text('Сохраняем черновик...').show(); + $('#draft-save-status').text(chrome.i18n.getMessage('msg_saving_post_draft')).show(); - // Сохраняем + // Saving current data draft_last_text = current_text; + draft_last_tags = current_tags; + // Save it using the Chrome extension storage API. - chrome.storage.local.set({'point_draft_text': draft_last_text}, function() { + chrome.storage.local.set({ + point_draft_text: draft_last_text, + point_draft_tags: draft_last_tags + }, function() { // Notify that we saved. draft_save_busy = false; - $('#draft-save-status').text('Черновик сохранён...'); + draft_waiting = false; + setTimeout(function() { $('#draft-save-status').fadeOut(1000); }, 1000); @@ -1533,25 +1587,21 @@ function twitter_tweet_embedding_wait_for_ready_injected() { function twitter_tweet_embedding_parse_links() { // Обрабатываем все твиты var twitter_tweet_count = 0; - $('.post-content a').each(function(num, obj) { - if ($(obj).hasClass('booru_pic')) { - return; - } - + $('.post-content a:not(.booru_pic)').each(function(num, obj) { var href = obj.href; var n; if (n = href.match(new RegExp('^https?://(www\\.)?twitter\\.com/[^/]+/status/([0-9]+)', 'i'))) { - var image = document.createElement('div'); - $(image).attr({ + var tweet = document.createElement('div'); + $(tweet).attr({ 'id': 'tweet-' + twitter_tweet_count, 'data-tweet-id': n[2] }).addClass('twitter-tweet-embedded'); - obj.parentElement.insertBefore(image, obj); + obj.parentElement.insertBefore(tweet, obj); window.twttr.widgets.createTweet( n[2], - image, + tweet, { 'lang': 'ru' } @@ -1560,3 +1610,50 @@ function twitter_tweet_embedding_parse_links() { } }); } + +/** + * Instagram posts + * + * @param {OptionsManager} options OptionsManager with current options + */ +function instagram_posts_embedding_init(options) { + var regex = new RegExp('^https?://(www\\.)?instagram\\.com/p/([\\w-]+)/?', 'i'); + + $('.post-content a:not(.booru_pic)').each(function(num, $link) { + var href = $link.href; + var n; + + if (n = href.match(regex)) { + $ajax({ + 'url': 'https://api.instagram.com/oembed?url=' + urlencode('http://instagram.com/p/' + n[2] + '/'), + 'success': function(text) { + var answer = JSON.parse(text); + var new_post = document.createElement('a'); + $(new_post).attr({ + 'id': 'instagram-' + num, + 'href': answer.thumbnail_url, + 'title': answer.title, + 'target': '_blank', + 'data-fancybox-group': (options.is('option_fancybox_bind_images_to_one_flow')) + ? 'one_flow_gallery' : '', + 'data-fancybox-title': (options.is('option_fancybox_smart_hints')) + ? answer.title : ' ' + }).addClass('postimg instagram-post-embedded'); + + var image = document.createElement('img'); + image.alt = new_post.title; + image.src = new_post.href; + new_post.appendChild(image); + + // Leave or replace + if (options.is('option_embedding_instagram_posts_orig_link')) { + $link.parentElement.insertBefore(new_post, $link); + } else { + $($link).replaceWith(new_post); + } + } + }); + + } + }); +} diff --git a/chrome_point_plus/manifest.json b/chrome_point_plus/manifest.json index a4e88b2..49d9ad9 100644 --- a/chrome_point_plus/manifest.json +++ b/chrome_point_plus/manifest.json @@ -61,6 +61,7 @@ "https://player.soundcloud.com/*", "https://api.kanaria.ru/point/*", "https://*.twitter.com/*", + "https://api.instagram.com/*", "https://coub.com/embed/*", "storage", "notifications", diff --git a/chrome_point_plus/options.html b/chrome_point_plus/options.html index 36034dc..b388067 100644 --- a/chrome_point_plus/options.html +++ b/chrome_point_plus/options.html @@ -1,8 +1,8 @@ - Point Plus options + @@ -131,6 +131,16 @@ + +
+ + + + +
@@ -246,6 +256,11 @@ + +