aboutsummaryrefslogtreecommitdiffstats
path: root/twittperator/twsidebar-expand-url.tw
diff options
context:
space:
mode:
authorebith2012-11-18 08:43:28 +0900
committerebith2012-11-18 08:43:28 +0900
commit98ff4833155e50e0dfc83044e7e8430248207de5 (patch)
treef91a8c286b5b5979f38cb81241aba6d6e8b3fcab /twittperator/twsidebar-expand-url.tw
parent25e6aa07cf75f02d9f813639474b9b48613e5aca (diff)
downloadvimperator-plugins-98ff4833155e50e0dfc83044e7e8430248207de5.tar.bz2
展開したURLが画像っぽい場合サムネイルを表示する
Diffstat (limited to 'twittperator/twsidebar-expand-url.tw')
-rw-r--r--twittperator/twsidebar-expand-url.tw27
1 files changed, 24 insertions, 3 deletions
diff --git a/twittperator/twsidebar-expand-url.tw b/twittperator/twsidebar-expand-url.tw
index 218fe33..c782d08 100644
--- a/twittperator/twsidebar-expand-url.tw
+++ b/twittperator/twsidebar-expand-url.tw
@@ -4,6 +4,7 @@ require('twsidebar');
(function () {
let Config = liberator.globalVariables.twittperator_sidebar_expand_url_config || {
host: ['ff.im', 'is.gd', 't.co', 'bit.ly', 'j.mp', 'htn.to', 'goo.gl', 'ow.ly'],
+ photo: ['png', 'jpg', 'gif'],
filter: function (url, callback) {
let isStatus = /https?:\/\/twitter\.com\/(\w+)\/status(?:es)?\/(\d+)/.exec(url);
let isPhoto = /\/photo\/\d/;
@@ -13,6 +14,11 @@ require('twsidebar');
callback('\u26A1 ' + msg.user.screen_name + ' : ' + msg.text);
});
}
+ } else if (Config.photo.indexOf(url.substr(-3)) >= 0) {
+ var img = document.createElement('image');
+ img.setAttribute('src', url);
+ img.setAttribute('style', 'max-height: 120px; max-width: 120px;');
+ callback([img, url.length > 30 ? url.substr(0, 30) + '...' : url], 'both');
} else {
callback(url.length > 60 ? url.substr(0, 60) + '...' : url);
}
@@ -67,12 +73,27 @@ require('twsidebar');
tweet.text = tweet.text.replace(sUrl, eUrl);
if (!sidebar().getElementById('tw-anekos-sb-home-list')) { return; }
let fUrl = expand ? sUrl : eUrl;
+ eUrl = urls[i].media_url ? urls[i].media_url : eUrl;
setTimeout(function () {
let e = twsText(id);
if (e) {
- Config.filter(eUrl, function(filtered){
- e.textContent = escapeBreakers(e.textContent.replace(fUrl, filtered));
- scroll();
+ Config.filter(eUrl, function(filtered, mode){
+ switch (mode) {
+ case 'appendChild':
+ e.parentElement.appendChild(filtered);
+ break;
+ case 'both':
+ if ( i == 0 ) {
+ let br = document.createElementNS('http://www.w3.org/1999/xhtml', 'br')
+ e.parentElement.appendChild(br);
+ }
+ e.parentElement.appendChild(filtered[0]);
+ e.textContent = escapeBreakers(e.textContent.replace(fUrl, filtered[1]));
+ break;
+ default:
+ e.textContent = escapeBreakers(e.textContent.replace(fUrl, filtered));
+ }
+ setTimeout(function () { scroll(); }, 500);
});
}
}, 100);