Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 8 commits
  • 4 files changed
  • 0 commit comments
  • 3 contributors
View
8 buffer-overlay.js
@@ -173,10 +173,14 @@ var bufferData = function (port, postData) {
if( typeof data.embed === "object" ) {
for( var i in data.embed ) {
if( data.embed.hasOwnProperty(i) ) {
- data[i] = data.embed[i];
+ if( i === "image" ) {
+ data.picture = data.embed[i];
+ } else {
+ data[i] = data.embed[i];
+ }
}
}
- if( !data.embed.url ) {
+ if( data.embed.text && !data.embed.url ) {
data.url = null;
}
data.embed = null;
View
80 embeds/buffer-facebook.js
@@ -20,21 +20,46 @@
};
// Listen for share button clicks
-
var share = {};
$('body').on('click', 'a.share_action_link', function (e) {
- var parent = $(this).closest('.genericStreamStory');
- share.via = $(parent).find('.actorName').text();
- share.text = $(parent).find('.messageBody').text();
- var url = $(parent).find('.uiStreamSource a').attr('href');
- if( url[0] == "/" ) url = "https://facebook.com" + url;
- share.url = url;
- var small_img = $(parent).find('.uiPhotoThumb img').attr('src');
- if( small_img ) {
- var img = small_img.replace(/s[0-9]+x[0-9]+\//, '')
- share.image = img;
- share.url = $(parent).find('.uiPhotoThumb').attr('href');
- }
+ var $parent = $(this).closest('.genericStreamStory, .fbTimelineUnit');
+
+ // reset share object on every 'share' button click
+ share = {};
+
+ // find the name of the person that shared the attachment
+ share.via = $('.passiveName', $parent).first().text() || $('.actorName', $parent).first().text();
+
+ // find the message for this attachment, or if none use the attachment caption
+ // .tlTxFe is used on new timeline
+ share.text = $('.messageBody, .tlTxFe', $parent).first().text() || $('.caption', $parent).text();
+
+ var thumb = $('.uiPhotoThumb img, .photoUnit img', $parent).attr('src');
+ var url = $('.uiAttachmentTitle a, a.externalShareUnit', $parent).attr('href');
+
+ // find picture status
+ if( thumb ) {
+ // convert the thumbnail link to a link to the fullsize image
+ share.picture = thumb.replace(/s[0-9]+x[0-9]+\//, '');
+
+ // we pass the source of the image for the 'found at' text
+ share.url = $('a.uiPhotoThumb, a.photo', $parent).attr('href');
+
+ share.placement = 'facebook-share-picture';
+ }
+
+ // find link status
+ else if (url) {
+ if( url[0] == "/" ) url = "https://facebook.com" + url;
+ share.url = url;
+ share.placement = 'facebook-share-link';
+ }
+
+ // standard text status
+ else
+ {
+ share.placement = 'facebook-share-status';
+ }
});
var config = {};
@@ -106,7 +131,7 @@
{
name: "share",
text: "Buffer",
- container: 'div.dialogFooter',
+ container: 'div.uiOverlayFooter',
before: '.uiButtonConfirm',
className: 'buffer-facebook-button',
selector: '.buffer-facebook-button',
@@ -150,21 +175,18 @@
},
data: function (elem) {
- var parent = $(elem).closest('.uiDialog');
- var text = $(parent).find('div.uiMentionsInput textarea').val();
+
+ var $parent = $(elem).closest('.modalWrapper');
+
+ // if the user has written a message, allow this to override the default text
+ var text = $('div.textInput textarea', $parent).val();
if( text === "Write something" ) text = undefined;
- if( share.url ) {
- if( text ) share.text = text;
- return {
- text: share,
- placement: 'facebook-share'
- }
- } else {
- return {
- text: text,
- placement: 'facebook-share'
- }
- }
+ if( text ) share.text = text;
+
+ // fallback placement when we don't know if the attachment is a picture, link or status
+ if( !share.placement ) share.placement = 'facebook-share';
+
+ return share;
},
clear: function (elem) {
share = {};
@@ -218,7 +240,7 @@
clearcb = function () {}; // prevent clear from being called again, until the button is clicked again
});
- })
+ });
}
View
182 embeds/buffer-scraper.js
@@ -0,0 +1,182 @@
+;(function () {
+
+ console.log("Filtering images.");
+
+ // Utility functions
+ function rtrim (str, charlist) {
+ // Removes trailing whitespace
+ //
+ // version: 1109.2015
+ // discuss at: http://phpjs.org/functions/rtrim
+ // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + input by: Erkekjetter
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
+ // + bugfixed by: Onno Marsman
+ // + input by: rem
+ // + bugfixed by: Brett Zamir (http://brett-zamir.me)
+ // * example 1: rtrim(' Kevin van Zonneveld ');
+ // * returns 1: ' Kevin van Zonneveld'
+ charlist = !charlist ? ' \\s\u00A0' : (charlist + '').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\\$1');
+ var re = new RegExp('[' + charlist + ']+$', 'g');
+ return (str + '').replace(re, '');
+ }
+
+ // Info
+ var scraper = {};
+ scraper.base = document.location.origin;
+ scraper.path = document.location.pathname;
+ scraper.url = document.location.href;
+
+ var config = {};
+ config.banned = [
+ 'http://ds.issuemediagroup.com'
+ ];
+ config.need = 8;
+
+ var formatSrc = function (src) {
+
+ // add protocol to relative urls
+ if( src.substring(0, 2) === "//" ) {
+ src = document.location.protocol + src;
+ }
+
+ // prepend site if missing
+ if( ! src.match(/^https?:\/\//g) ) {
+
+ // relative to site root
+ if( src.substring(0,1) === "/" ) {
+ src = scraper.url + src;
+ }
+ // no slash, relative to base
+ else {
+ src = scraper.base + scraper.path + '/' + src;
+ }
+
+ }
+
+ return src;
+
+ };
+
+ var calcGCD = function(size) {
+ var a = size.x, b = size.y;
+ var remander = 0;
+ while (b !== 0) {
+ remainder = a % b;
+ a = b;
+ b = remainder;
+ }
+ return Math.abs(a);
+ };
+
+ var calcAspect = function(size) {
+ if ( ! size.x || ! size.y ) return 1;
+ var gcd = calcGCD(size);
+ return (size.x / gcd) / (size.y / gcd);
+ };
+
+ // Filter out unwanted images
+ var filterImage = function (img) {
+
+ var src, ext, height = $(img).width(), width = $(img).height(), aspect;
+
+ src = $(img).attr('src');
+
+ ext = src.split('.').pop(); // This could break with query string... kitten.jpg?size=large
+
+ src = formatSrc(src);
+
+ // valid extension?
+ if( ! ext.match(/(jpg|jpeg|gif|png)/i) ) { return false; }
+
+ aspect = calcAspect({x: width, y: height});
+
+ if( height < 50 || width < 85 || aspect < 0.4 || aspect > 4 ) { return false; }
+
+ return {
+ url: src,
+ title: $(img).attr('title'),
+ height: height,
+ width: width
+ };
+
+ };
+
+ // Retrieve & filter images from current page
+ var getImages = function () {
+
+ // Old-skool base tag
+ var base = $('base');
+ if( base.length > 0 ) {
+ scraper.base = rtrim($('base').first().attr('href'), '/') + '/';
+ }
+
+ // All images
+ var images = $('img'), filtered = [], srcs = {};
+
+ // Grab the open graph image
+ var ogimage = $('meta[property="og:image"]');
+ var ogtmp;
+ if( ogimage.length > 0 ) {
+ ogtmp = $('<img>').prop({
+ 'src': $(ogimage).text(),
+ 'class': 'opengraph',
+ 'width': 1000, // High priority
+ 'height': 1000
+ });
+ images.push(ogtmp);
+ }
+
+ // Cycle through all images
+ var i = 0, l=images.length, result, img;
+ for(; i < l; i++) {
+
+ img = images[i];
+
+ // Have we seen this image already?
+ if( !! srcs[$(img).attr('src')] ) {
+ // Yep, skip it
+ continue;
+ } else {
+ // Nope, remember it
+ srcs[$(img).attr('src')] = true;
+ }
+
+ result = filterImage(img);
+
+ if( result !== false ) {
+ filtered.push(result);
+ }
+
+ }
+
+ var pow = Math.pow;
+ filtered.sort(function (a, b) {
+ return pow(pow(b.width, 2) + pow(b.height, 2), 1/2) - pow(pow(a.width, 2) + pow(a.height, 2), 1/2);
+ });
+
+ console.log(filtered);
+
+ return filtered.slice(0, config.need);
+
+ };
+
+ var getDescription = function () {
+ var text = $('p').first().text().substring(0, 200);
+ return $('meta[property="og:description"]').text() || $('meta[name=description]').prop('content') || (text.length > 0 ? text + '...' : false) || '';
+ };
+
+ var getDetails = function () {
+
+ return {
+ original: scraper.url,
+ title: $('meta[property="og:title"]').prop('content') || document.title || $('h1').first().text() || '',
+ description: getDescription(),
+ images: getImages()
+ };
+
+ };
+
+ console.log(getDetails());
+
+}());
View
17 embeds/buffer-twitter.js
@@ -193,7 +193,7 @@
return {
text: $(elem).parents('.ft').siblings('.bd').find('#status').val(),
placement: 'twitter-tweetbutton'
- }
+ };
},
clear: function (elem) {
window.close();
@@ -211,7 +211,7 @@
};
$(target).on('keyup focus blur change paste cut', function (e) {
activate();
- });
+ });
activate();
}
},
@@ -274,6 +274,11 @@
clear: function (elem) {
},
activator: function (elem, btnConfig) {
+
+ if( $(elem).closest('.in-reply-to').length > 0 ) {
+ $(elem).find('i').css({'background-position-y': '-30px'});
+ }
+
}
},
{
@@ -330,11 +335,15 @@
return {
text: rt,
placement: 'twitter-feed'
- }
+ };
},
clear: function (elem) {
},
activator: function (elem, btnConfig) {
+
+ if( $(elem).closest('.in-reply-to').length > 0 ) {
+ $(elem).find('i').css({'background-position-y': '-21px'});
+ }
}
}
];
@@ -382,7 +391,7 @@
clearcb = function () {}; // prevent clear from being called again, until the button is clicked again
});
- })
+ });
}

No commit comments for this range

Something went wrong with that request. Please try again.