diff --git a/chrome_point_plus/_locales/en/messages.json b/chrome_point_plus/_locales/en/messages.json index 3fbbb13..2f9825a 100644 --- a/chrome_point_plus/_locales/en/messages.json +++ b/chrome_point_plus/_locales/en/messages.json @@ -89,6 +89,9 @@ "option_embedding_coubcom": { "message": "Coub.com ▼" }, + "option_embedding_twitter_tweets": { + "message": "Embedding tweets from Twitter" + }, "option_nsfw": { "message": "NSFW content filtering" }, diff --git a/chrome_point_plus/_locales/ru/messages.json b/chrome_point_plus/_locales/ru/messages.json index 6ee7b72..7ad1d62 100644 --- a/chrome_point_plus/_locales/ru/messages.json +++ b/chrome_point_plus/_locales/ru/messages.json @@ -89,6 +89,9 @@ "option_embedding_coubcom": { "message": "Coub.com ▼" }, + "option_embedding_twitter_tweets": { + "message": "Встраиваем твиты из Твиттера" + }, "option_nsfw": { "message": "Фильтрация NSFW-контента" }, diff --git a/chrome_point_plus/js/point-plus.js b/chrome_point_plus/js/point-plus.js index fbd2731..1c34686 100644 --- a/chrome_point_plus/js/point-plus.js +++ b/chrome_point_plus/js/point-plus.js @@ -512,6 +512,11 @@ $(document).ready(function() { set_comments_refresh_tick(options); } + // Твиты из Твиттера + if (options.option_embedding_twitter_tweets.value == true){ + twitter_tweet_embedding_init(); + } + $('#point-plus-debug').fadeOut(1000); }); }); @@ -1327,3 +1332,79 @@ function comments_count_refresh_tick(current_options) { 'height': '300px' }).hide(); } + +/** + * Встраиваем твиты из Твиттера + */ +function twitter_tweet_embedding_init() { + // Чёрная магия. Выбираемся из манямирка, прихватив с собой пару сраных функций + // https://developer.chrome.com/extensions/content_scripts Isolated World + var e = document.createElement("script"); + e.appendChild(document.createTextNode(twitter_tweet_embedding_wait_for_ready_injected.toString() + + twitter_tweet_embedding_parse_links.toString() + 'twitter_tweet_embedding_wait_for_ready_injected();')); + document.head.appendChild(e); + + // Встраиваем скрипт так, как описано в best twitter practice https://dev.twitter.com/web/javascript/loading + window.twttr = (function(d, s, id) { + var t, js, fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) return; + js = d.createElement(s); + js.id = id; + js.src = "https://platform.twitter.com/widgets.js"; + fjs.parentNode.insertBefore(js, fjs); + return window.twttr || (t = { + _e: [], ready: function(f) { + t._e.push(f); + } + }); + }(document, "script", "twitter-wjs")); +} + +/** + * Проверяем загрузились ли мы. Эта функция запускается из page scope + */ +function twitter_tweet_embedding_wait_for_ready_injected() { + if (typeof(window.twttr) == 'undefined') { + setTimeout(twitter_tweet_embedding_wait_for_ready_injected, 100); + return; + } + if (typeof(window.twttr.widgets) == 'undefined') { + setTimeout(twitter_tweet_embedding_wait_for_ready_injected, 100); + return; + } + twitter_tweet_embedding_parse_links(); +} + +/** + * Парсим все ссылки. Эта функция запускается из page scope + */ +function twitter_tweet_embedding_parse_links() { + // Обрабатываем все твиты + var twitter_tweet_count = 0; + $('.post-content a').each(function(num, obj) { + if ($(obj).hasClass('booru_pic')) { + return; + } + + 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({ + 'id': 'tweet-' + twitter_tweet_count, + 'data-tweet-id': n[2] + }).addClass('twitter-tweet-embedded'); + obj.parentElement.insertBefore(image, obj); + + window.twttr.widgets.createTweet( + n[2], + image, + { + theme: 'dark' + } + ); + twitter_tweet_count++; + } + }); +} diff --git a/chrome_point_plus/manifest.json b/chrome_point_plus/manifest.json index f9bc888..04a88ef 100644 --- a/chrome_point_plus/manifest.json +++ b/chrome_point_plus/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Point+", - "version": "1.18.7", + "version": "1.18.8", "default_locale": "ru", "author": "__MSG_ext_author__", "homepage_url": "https://bitbucket.org/skobkin/chrome_point_plus", diff --git a/chrome_point_plus/options.html b/chrome_point_plus/options.html index b83e950..ef0a7fa 100644 --- a/chrome_point_plus/options.html +++ b/chrome_point_plus/options.html @@ -101,6 +101,10 @@ + +
+ +