Встраивание Instagram из pull request #25.

This commit is contained in:
Alexey Skobkin 2015-01-27 02:55:15 +03:00
parent afa1ef0fb0
commit 429c432dc5
7 changed files with 95 additions and 2 deletions

View file

@ -95,6 +95,12 @@
"option_embedding_twitter_tweets": { "option_embedding_twitter_tweets": {
"message": "Twitter" "message": "Twitter"
}, },
"option_embedding_instagram_posts": {
"message": "Instagram"
},
"option_embedding_instagram_posts_orig_link": {
"message": "Leave original link"
},
"option_nsfw": { "option_nsfw": {
"message": "NSFW content filtering" "message": "NSFW content filtering"
}, },

View file

@ -95,6 +95,12 @@
"option_embedding_twitter_tweets": { "option_embedding_twitter_tweets": {
"message": "Twitter" "message": "Twitter"
}, },
"option_embedding_instagram_posts": {
"message": "Instagram"
},
"option_embedding_instagram_posts_orig_link": {
"message": "Не убирать ссылку"
},
"option_nsfw": { "option_nsfw": {
"message": "Фильтрация NSFW-контента" "message": "Фильтрация NSFW-контента"
}, },

View file

@ -28,12 +28,12 @@ div#markItUpText-input {
} }
/* Auto-loaded Booru pictures */ /* Auto-loaded Booru pictures */
.booru_pic { .booru_pic, .instagram-post-embedded {
display: block !important; display: block !important;
float: none !important; float: none !important;
} }
.booru_pic img { .booru_pic img, .instagram-post-embedded img {
border: none; border: none;
max-width: 60%; max-width: 60%;
max-height: 300px; max-height: 300px;

View file

@ -1,3 +1,6 @@
/**
* @deprecated since 1.36.0
*/
function $ajax_prot(settings){ function $ajax_prot(settings){
if (settings==undefined){return;} if (settings==undefined){return;}
if (settings['url'] ==undefined){return;}this.url=settings['url']; if (settings['url'] ==undefined){return;}this.url=settings['url'];
@ -46,8 +49,14 @@ $ajax_prot.prototype={
$ajax=function (settings){return new $ajax_prot(settings);} $ajax=function (settings){return new $ajax_prot(settings);}
/**
* @deprecated since 1.36.0
*/
function urlencode(text){return encodeURIComponent(text);} function urlencode(text){return encodeURIComponent(text);}
/**
* @deprecated since 1.36.0
*/
function sad_safe_reg(text){ function sad_safe_reg(text){
var ar='.-\\/[]{}?+'; var ar='.-\\/[]{}?+';
var s=''; for (var i=0;i<text.length;i++){ var s=''; for (var i=0;i<text.length;i++){
@ -60,6 +69,9 @@ function sad_safe_reg(text){
return s; return s;
} }
/**
* @deprecated since 1.36.0
*/
function sad_xml_getnode(node,path){//node as domNode function sad_xml_getnode(node,path){//node as domNode
if ('' ==path){return node;} if ('' ==path){return node;}
if ('#'==path){return node.textContent || node.text;} if ('#'==path){return node.textContent || node.text;}
@ -81,6 +93,9 @@ function sad_xml_getnode(node,path){//node as domNode
return undefined; return undefined;
} }
/**
* @deprecated since 1.36.0
*/
function sad_xml_attribute(node,name){ function sad_xml_attribute(node,name){
if (node==undefined){return undefined;} if (node==undefined){return undefined;}
var r=new RegExp('^'+sad_safe_reg(name)+'$','i'); var r=new RegExp('^'+sad_safe_reg(name)+'$','i');
@ -90,6 +105,9 @@ function sad_xml_attribute(node,name){
return ''; return '';
} }
/**
* @deprecated since 1.36.0
*/
function sad_x2n(xml){ function sad_x2n(xml){
return xml.responseXML.childNodes[xml.responseXML.childNodes.length-1]; return xml.responseXML.childNodes[xml.responseXML.childNodes.length-1];
} }

View file

@ -55,6 +55,11 @@ function PointPlus(ppVersion) {
load_all_booru_images(); load_all_booru_images();
} }
// Instagram
if (options.is('option_embedding_instagram_posts')){
instagram_posts_embedding_init(options);
}
// Parse webm-links and create video instead // Parse webm-links and create video instead
if (options.is('option_videos_parse_links')) { if (options.is('option_videos_parse_links')) {
if (options.is('option_videos_parse_links_type', 'all')) { if (options.is('option_videos_parse_links_type', 'all')) {
@ -1548,3 +1553,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://player.soundcloud.com/*",
"https://api.kanaria.ru/point/*", "https://api.kanaria.ru/point/*",
"https://*.twitter.com/*", "https://*.twitter.com/*",
"https://api.instagram.com/*",
"https://coub.com/embed/*", "https://coub.com/embed/*",
"storage", "storage",
"notifications", "notifications",

View file

@ -131,6 +131,16 @@
<input type="checkbox" name="option-embedding-twitter-tweets"> <input type="checkbox" name="option-embedding-twitter-tweets">
<span data-i18n="option_embedding_twitter_tweets"></span> <span data-i18n="option_embedding_twitter_tweets"></span>
</label> </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>
<div class="option-node"> <div class="option-node">