Merged in merge_pr25 (pull request #34) Instagram, drafts, some fixes.

This commit is contained in:
Alexey Skobkin 2015-01-31 08:20:24 +03:00
commit 62673d3790
7 changed files with 217 additions and 56 deletions

View file

@ -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..."
}
}

View file

@ -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": "Сохранение поста..."
}
}

View file

@ -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;

View file

@ -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<text.length;i++){
@ -60,6 +69,9 @@ function sad_safe_reg(text){
return s;
}
/**
* @deprecated since 1.36.0
*/
function sad_xml_getnode(node,path){//node as domNode
if ('' ==path){return node;}
if ('#'==path){return node.textContent || node.text;}
@ -81,6 +93,9 @@ function sad_xml_getnode(node,path){//node as domNode
return undefined;
}
/**
* @deprecated since 1.36.0
*/
function sad_xml_attribute(node,name){
if (node==undefined){return undefined;}
var r=new RegExp('^'+sad_safe_reg(name)+'$','i');
@ -90,6 +105,9 @@ function sad_xml_attribute(node,name){
return '';
}
/**
* @deprecated since 1.36.0
*/
function sad_x2n(xml){
return xml.responseXML.childNodes[xml.responseXML.childNodes.length-1];
}

View file

@ -33,11 +33,6 @@ function PointPlus(ppVersion) {
}).text('Point+ ' + ppVersion + ' loading...')
.insertBefore('#user-menu-cb');
// Черновики. Ставим хандлер и восстанавливаем предыдущее состояние
draft_set_save_handler();
draft_restore();
// Loading options
chrome.storage.sync.get('options', function(sync_data) {
var options = new OptionsManager(sync_data.options);
@ -55,6 +50,11 @@ function PointPlus(ppVersion) {
load_all_booru_images();
}
// Instagram
if (options.is('option_embedding_instagram_posts')){
instagram_posts_embedding_init(options);
}
// Parse webm-links and create video instead
if (options.is('option_videos_parse_links')) {
if (options.is('option_videos_parse_links_type', 'all')) {
@ -617,6 +617,12 @@ function PointPlus(ppVersion) {
twitter_tweet_embedding_init();
}
// Post drafts
if (options.is('option_other_post_draft_save')) {
draft_set_save_handler();
draft_restore();
}
$('#point-plus-debug').fadeOut(1000);
});
}
@ -725,10 +731,7 @@ function create_comment_elements(commentData, onCommentCreated) {
// Картинки с бурятников
var booru_picture_count = 0;
function load_all_booru_images() {
$('.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 = null;
@ -828,10 +831,7 @@ function mark_unread_post() {
// Webm
function parse_webm(current_options) {
$('.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 = null;
@ -855,10 +855,7 @@ function parse_webm(current_options) {
// Видео
function parse_all_videos(current_options) {
$('.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 = null;
@ -1095,14 +1092,12 @@ function set_space_key_skip_handler() {
}
function space_key_event() {
var scroll_current = $('body').scrollTop();
var scroll_step_size = 0;
var scroll_real = Math.max(scroll_current - scroll_step_size, 0);
var scroll_current = Math.floor($('body').scrollTop());
var posts = $('.content-wrap > .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($('<span id="draft-save-status">'));
}
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;
}
// @todo i18n
$('#draft-save-status').text('Сохраняем черновик...').show();
// Сохраняем
draft_save_busy = true;
draft_save_last_time = new Date();
// @todo i18n
$('#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);
}
}
});
}
});
}

View file

@ -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",

View file

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title>Point Plus options</title>
<meta charset="utf-8">
<title data-i18n="options_page_title"></title>
<link rel="stylesheet" href="css/options.css" type="text/css">
</head>
@ -131,6 +131,16 @@
<input type="checkbox" name="option-embedding-twitter-tweets">
<span data-i18n="option_embedding_twitter_tweets"></span>
</label>
<div class="option-node">
<input type="checkbox" name="option-embedding-instagram-posts" id="option-embedding-instagram-posts">
<label for="option-embedding-instagram-posts" data-i18n="option_embedding_instagram_posts"></label>
<label class="option-node">
<input type="checkbox" name="option-embedding-instagram-posts-orig-link">
<span data-i18n="option_embedding_instagram_posts_orig_link"></span>
</label>
</div>
</div>
<div class="option-node">
@ -246,6 +256,11 @@
<input type="checkbox" name="option-other-comments-user-system">
<span data-i18n="option_other_comments_user_system"></span>
</label>
<label class="option-node">
<input type="checkbox" name="option-other-post-draft-save">
<span data-i18n="option_other_post_draft_save"></span>
</label>
</section>
<section class="tabs-content-item" id="websocket">