diff --git a/js/twitterFetcher.js b/js/twitterFetcher.js index 871c804..91c3139 100644 --- a/js/twitterFetcher.js +++ b/js/twitterFetcher.js @@ -91,7 +91,7 @@ return decodeURIComponent(data_src) + '.jpg'; } } - + var twitterFetcher = { fetch: function(config) { @@ -220,8 +220,8 @@ } function swapDataSrc(element) { - var avatarImg = element.getElementsByTagName('img')[0]; - avatarImg.src = avatarImg.getAttribute('data-src-2x'); + var avatarImg = element.getElementsByTagName('img')[0] !== undefined ? element.getElementsByTagName('img')[0] : ""; + avatarImg.src = avatarImg !== "" ? avatarImg.getAttribute('data-src-2x') : ""; return element; } @@ -427,4 +427,3 @@ window.twitterFetcher = twitterFetcher; return twitterFetcher; })); - diff --git a/js/twitterFetcher_min.js b/js/twitterFetcher_min.js index 19a1076..004cbe3 100644 --- a/js/twitterFetcher_min.js +++ b/js/twitterFetcher_min.js @@ -8,58 +8,51 @@ * Github: https://github.com/jasonmayes/Twitter-Post-Fetcher * Updates will be posted to this site. *********************************************************************/ -(function(root,factory){if(typeof define==='function'&&define.amd){define([],factory);}else if(typeof exports==='object'){module.exports=factory();}else{factory();}}(this,function(){var domNode='';var maxTweets=20;var parseLinks=true;var queue=[];var inProgress=false;var printTime=true;var printUser=true;var formatterFunction=null;var supportsClassName=true;var showRts=true;var customCallbackFunction=null;var showInteractionLinks=true;var showImages=false;var useEmoji=false;var targetBlank=true;var lang='en';var permalinks=true;var dataOnly=false;var script=null;var scriptAdded=false;function handleTweets(tweets){if(customCallbackFunction===null){var x=tweets.length;var n=0;var element=document.getElementById(domNode);var html='';element.innerHTML=html;}else{customCallbackFunction(tweets);}} -function strip(data){return data.replace(/]*>(.*?)<\/b>/gi,function(a,s){return s;}).replace(/class="(?!(tco-hidden|tco-display|tco-ellipsis))+.*?"|data-query-source=".*?"|dir=".*?"|rel=".*?"/gi,'');} -function targetLinksToNewWindow(el){var links=el.getElementsByTagName('a');for(var i=links.length-1;i>=0;i--){links[i].setAttribute('target','_blank');}} -function getElementsByClassName(node,classname){var a=[];var regex=new RegExp('(^| )'+classname+'( |$)');var elems=node.getElementsByTagName('*');for(var i=0,j=elems.length;i=0){var data_src=image_data.innerHTML.match(/data-image=\"([A-z0-9]+:\/\/[A-z0-9]+\.[A-z0-9]+\.[A-z0-9]+\/[A-z0-9]+\/[A-z0-9\-]+)/i)[1];return decodeURIComponent(data_src)+'.jpg';}} -var twitterFetcher={fetch:function(config){if(config.maxTweets===undefined){config.maxTweets=20;} -if(config.enableLinks===undefined){config.enableLinks=true;} -if(config.showUser===undefined){config.showUser=true;} -if(config.showTime===undefined){config.showTime=true;} -if(config.dateFunction===undefined){config.dateFunction='default';} -if(config.showRetweet===undefined){config.showRetweet=true;} -if(config.customCallback===undefined){config.customCallback=null;} -if(config.showInteraction===undefined){config.showInteraction=true;} -if(config.showImages===undefined){config.showImages=false;} -if(config.useEmoji===undefined){config.useEmoji=false;} -if(config.linksInNewWindow===undefined){config.linksInNewWindow=true;} -if(config.showPermalinks===undefined){config.showPermalinks=true;} -if(config.dataOnly===undefined){config.dataOnly=false;} -if(inProgress){queue.push(config);}else{inProgress=true;domNode=config.domId;maxTweets=config.maxTweets;parseLinks=config.enableLinks;printUser=config.showUser;printTime=config.showTime;showRts=config.showRetweet;formatterFunction=config.dateFunction;customCallbackFunction=config.customCallback;showInteractionLinks=config.showInteraction;showImages=config.showImages;useEmoji=config.useEmoji;targetBlank=config.linksInNewWindow;permalinks=config.showPermalinks;dataOnly=config.dataOnly;var head=document.getElementsByTagName('head')[0];if(script!==null){head.removeChild(script);} -script=document.createElement('script');script.type='text/javascript';if(config.list!==undefined){script.src='https://syndication.twitter.com/timeline/list?'+'callback=__twttrf.callback&dnt=false&list_slug='+ -config.list.listSlug+'&screen_name='+config.list.screenName+'&suppress_response_codes=true&lang='+(config.lang||lang)+'&rnd='+Math.random();}else if(config.profile!==undefined){script.src='https://syndication.twitter.com/timeline/profile?'+'callback=__twttrf.callback&dnt=false'+'&screen_name='+config.profile.screenName+'&suppress_response_codes=true&lang='+(config.lang||lang)+'&rnd='+Math.random();}else if(config.likes!==undefined){script.src='https://syndication.twitter.com/timeline/likes?'+'callback=__twttrf.callback&dnt=false'+'&screen_name='+config.likes.screenName+'&suppress_response_codes=true&lang='+(config.lang||lang)+'&rnd='+Math.random();}else{script.src='https://cdn.syndication.twimg.com/widgets/timelines/'+ -config.id+'?&lang='+(config.lang||lang)+'&callback=__twttrf.callback&'+'suppress_response_codes=true&rnd='+Math.random();} -head.appendChild(script);}},callback:function(data){if(data===undefined||data.body===undefined){inProgress=false;if(queue.length>0){twitterFetcher.fetch(queue[0]);queue.splice(0,1);} -return;} -if(!useEmoji){data.body=data.body.replace(/(]*>)|(]*>)/g,'');} -if(!showImages){data.body=data.body.replace(/(]*>|(]*>))/g,'');} -if(!printUser){data.body=data.body.replace(/(]*>)/g,'');} -var div=document.createElement('div');div.innerHTML=data.body;if(typeof(div.getElementsByClassName)==='undefined'){supportsClassName=false;} -function swapDataSrc(element){var avatarImg=element.getElementsByTagName('img')[0];avatarImg.src=avatarImg.getAttribute('data-src-2x');return element;} -var tweets=[];var authors=[];var times=[];var images=[];var rts=[];var tids=[];var permalinksURL=[];var x=0;if(supportsClassName){var tmp=div.getElementsByClassName('timeline-Tweet');while(x0){rts.push(true);}else{rts.push(false);} -if(!rts[x]||rts[x]&&showRts){tweets.push(tmp[x].getElementsByClassName('timeline-Tweet-text')[0]);tids.push(tmp[x].getAttribute('data-tweet-id'));if(printUser){authors.push(swapDataSrc(tmp[x].getElementsByClassName('timeline-Tweet-author')[0]));} -times.push(tmp[x].getElementsByClassName('dt-updated')[0]);permalinksURL.push(tmp[x].getElementsByClassName('timeline-Tweet-timestamp')[0]);if(tmp[x].getElementsByClassName('timeline-Tweet-media')[0]!==undefined){images.push(tmp[x].getElementsByClassName('timeline-Tweet-media')[0]);}else{images.push(undefined);}} -x++;}}else{var tmp=getElementsByClassName(div,'timeline-Tweet');while(x0){rts.push(true);}else{rts.push(false);} -if(!rts[x]||rts[x]&&showRts){tweets.push(getElementsByClassName(tmp[x],'timeline-Tweet-text')[0]);tids.push(tmp[x].getAttribute('data-tweet-id'));if(printUser){authors.push(swapDataSrc(getElementsByClassName(tmp[x],'timeline-Tweet-author')[0]));} -times.push(getElementsByClassName(tmp[x],'dt-updated')[0]);permalinksURL.push(getElementsByClassName(tmp[x],'timeline-Tweet-timestamp')[0]);if(getElementsByClassName(tmp[x],'timeline-Tweet-media')[0]!==undefined){images.push(getElementsByClassName(tmp[x],'timeline-Tweet-media')[0]);}else{images.push(undefined);}} -x++;}} -if(tweets.length>maxTweets){tweets.splice(maxTweets,(tweets.length-maxTweets));authors.splice(maxTweets,(authors.length-maxTweets));times.splice(maxTweets,(times.length-maxTweets));rts.splice(maxTweets,(rts.length-maxTweets));images.splice(maxTweets,(images.length-maxTweets));permalinksURL.splice(maxTweets,(permalinksURL.length-maxTweets));} -var arrayTweets=[];var x=tweets.length;var n=0;if(dataOnly){while(n';} -op+='

'+strip(tweets[n].innerHTML)+'

';if(printTime){if(permalinks){op+='

'+times[n].getAttribute('aria-label')+'

';}else{op+='

'+ -times[n].getAttribute('aria-label')+'

';}}}else{if(tweets[n].textContent){if(printUser){op+='

'+authors[n].textContent+'

';} -op+='

'+tweets[n].textContent+'

';if(printTime){op+='

'+times[n].textContent+'

';}}else{if(printUser){op+='

'+authors[n].textContent+'

';} -op+='

'+tweets[n].textContent+'

';if(printTime){op+='

'+times[n].textContent+'

';}}} -if(showInteractionLinks){op+='

'+'

';} -if(showImages&&images[n]!==undefined&&extractImageUrl(images[n])!==undefined){op+='
'+'Image from tweet'+'
';} -if(showImages){arrayTweets.push(op);}else if(!showImages&&tweets[n].textContent.length){arrayTweets.push(op);} -n++;}} -handleTweets(arrayTweets);inProgress=false;if(queue.length>0){twitterFetcher.fetch(queue[0]);queue.splice(0,1);}}};window.__twttrf=twitterFetcher;window.twitterFetcher=twitterFetcher;return twitterFetcher;})); \ No newline at end of file +(function(root,factory){if(typeof define==='function'&&define.amd){define([],factory)}else if(typeof exports==='object'){module.exports=factory()}else{factory()}}(this,function(){var domNode='';var maxTweets=20;var parseLinks=!0;var queue=[];var inProgress=!1;var printTime=!0;var printUser=!0;var formatterFunction=null;var supportsClassName=!0;var showRts=!0;var customCallbackFunction=null;var showInteractionLinks=!0;var showImages=!1;var useEmoji=!1;var targetBlank=!0;var lang='en';var permalinks=!0;var dataOnly=!1;var script=null;var scriptAdded=!1;function handleTweets(tweets){if(customCallbackFunction===null){var x=tweets.length;var n=0;var element=document.getElementById(domNode);var html='
    ';while(n'+tweets[n]+'';n++} +html+='
';element.innerHTML=html}else{customCallbackFunction(tweets)}} +function strip(data){return data.replace(/]*>(.*?)<\/b>/gi,function(a,s){return s}).replace(/class="(?!(tco-hidden|tco-display|tco-ellipsis))+.*?"|data-query-source=".*?"|dir=".*?"|rel=".*?"/gi,'')} +function targetLinksToNewWindow(el){var links=el.getElementsByTagName('a');for(var i=links.length-1;i>=0;i--){links[i].setAttribute('target','_blank')}} +function getElementsByClassName(node,classname){var a=[];var regex=new RegExp('(^| )'+classname+'( |$)');var elems=node.getElementsByTagName('*');for(var i=0,j=elems.length;i=0){var data_src=image_data.innerHTML.match(/data-image=\"([A-z0-9]+:\/\/[A-z0-9]+\.[A-z0-9]+\.[A-z0-9]+\/[A-z0-9]+\/[A-z0-9\-]+)/i)[1];return decodeURIComponent(data_src)+'.jpg'}} +var twitterFetcher={fetch:function(config){if(config.maxTweets===undefined){config.maxTweets=20} +if(config.enableLinks===undefined){config.enableLinks=!0} +if(config.showUser===undefined){config.showUser=!0} +if(config.showTime===undefined){config.showTime=!0} +if(config.dateFunction===undefined){config.dateFunction='default'} +if(config.showRetweet===undefined){config.showRetweet=!0} +if(config.customCallback===undefined){config.customCallback=null} +if(config.showInteraction===undefined){config.showInteraction=!0} +if(config.showImages===undefined){config.showImages=!1} +if(config.useEmoji===undefined){config.useEmoji=!1} +if(config.linksInNewWindow===undefined){config.linksInNewWindow=!0} +if(config.showPermalinks===undefined){config.showPermalinks=!0} +if(config.dataOnly===undefined){config.dataOnly=!1} +if(inProgress){queue.push(config)}else{inProgress=!0;domNode=config.domId;maxTweets=config.maxTweets;parseLinks=config.enableLinks;printUser=config.showUser;printTime=config.showTime;showRts=config.showRetweet;formatterFunction=config.dateFunction;customCallbackFunction=config.customCallback;showInteractionLinks=config.showInteraction;showImages=config.showImages;useEmoji=config.useEmoji;targetBlank=config.linksInNewWindow;permalinks=config.showPermalinks;dataOnly=config.dataOnly;var head=document.getElementsByTagName('head')[0];if(script!==null){head.removeChild(script)} +script=document.createElement('script');script.type='text/javascript';if(config.list!==undefined){script.src='https://syndication.twitter.com/timeline/list?'+'callback=__twttrf.callback&dnt=false&list_slug='+config.list.listSlug+'&screen_name='+config.list.screenName+'&suppress_response_codes=true&lang='+(config.lang||lang)+'&rnd='+Math.random()}else if(config.profile!==undefined){script.src='https://syndication.twitter.com/timeline/profile?'+'callback=__twttrf.callback&dnt=false'+'&screen_name='+config.profile.screenName+'&suppress_response_codes=true&lang='+(config.lang||lang)+'&rnd='+Math.random()}else if(config.likes!==undefined){script.src='https://syndication.twitter.com/timeline/likes?'+'callback=__twttrf.callback&dnt=false'+'&screen_name='+config.likes.screenName+'&suppress_response_codes=true&lang='+(config.lang||lang)+'&rnd='+Math.random()}else{script.src='https://cdn.syndication.twimg.com/widgets/timelines/'+config.id+'?&lang='+(config.lang||lang)+'&callback=__twttrf.callback&'+'suppress_response_codes=true&rnd='+Math.random()} +head.appendChild(script)}},callback:function(data){if(data===undefined||data.body===undefined){inProgress=!1;if(queue.length>0){twitterFetcher.fetch(queue[0]);queue.splice(0,1)} +return} +if(!useEmoji){data.body=data.body.replace(/(]*>)|(]*>)/g,'')} +if(!showImages){data.body=data.body.replace(/(]*>|(]*>))/g,'')} +if(!printUser){data.body=data.body.replace(/(]*>)/g,'')} +var div=document.createElement('div');div.innerHTML=data.body;if(typeof(div.getElementsByClassName)==='undefined'){supportsClassName=!1} +function swapDataSrc(element){var avatarImg=element.getElementsByTagName('img')[0]!==undefined?element.getElementsByTagName('img')[0]:"";avatarImg.src=avatarImg!==""?avatarImg.getAttribute('data-src-2x'):"";return element} +var tweets=[];var authors=[];var times=[];var images=[];var rts=[];var tids=[];var permalinksURL=[];var x=0;if(supportsClassName){var tmp=div.getElementsByClassName('timeline-Tweet');while(x0){rts.push(!0)}else{rts.push(!1)} +if(!rts[x]||rts[x]&&showRts){tweets.push(tmp[x].getElementsByClassName('timeline-Tweet-text')[0]);tids.push(tmp[x].getAttribute('data-tweet-id'));if(printUser){authors.push(swapDataSrc(tmp[x].getElementsByClassName('timeline-Tweet-author')[0]))} +times.push(tmp[x].getElementsByClassName('dt-updated')[0]);permalinksURL.push(tmp[x].getElementsByClassName('timeline-Tweet-timestamp')[0]);if(tmp[x].getElementsByClassName('timeline-Tweet-media')[0]!==undefined){images.push(tmp[x].getElementsByClassName('timeline-Tweet-media')[0])}else{images.push(undefined)}} +x++}}else{var tmp=getElementsByClassName(div,'timeline-Tweet');while(x0){rts.push(!0)}else{rts.push(!1)} +if(!rts[x]||rts[x]&&showRts){tweets.push(getElementsByClassName(tmp[x],'timeline-Tweet-text')[0]);tids.push(tmp[x].getAttribute('data-tweet-id'));if(printUser){authors.push(swapDataSrc(getElementsByClassName(tmp[x],'timeline-Tweet-author')[0]))} +times.push(getElementsByClassName(tmp[x],'dt-updated')[0]);permalinksURL.push(getElementsByClassName(tmp[x],'timeline-Tweet-timestamp')[0]);if(getElementsByClassName(tmp[x],'timeline-Tweet-media')[0]!==undefined){images.push(getElementsByClassName(tmp[x],'timeline-Tweet-media')[0])}else{images.push(undefined)}} +x++}} +if(tweets.length>maxTweets){tweets.splice(maxTweets,(tweets.length-maxTweets));authors.splice(maxTweets,(authors.length-maxTweets));times.splice(maxTweets,(times.length-maxTweets));rts.splice(maxTweets,(rts.length-maxTweets));images.splice(maxTweets,(images.length-maxTweets));permalinksURL.splice(maxTweets,(permalinksURL.length-maxTweets))} +var arrayTweets=[];var x=tweets.length;var n=0;if(dataOnly){while(n'} +op+='

'+strip(tweets[n].innerHTML)+'

';if(printTime){if(permalinks){op+='

'+times[n].getAttribute('aria-label')+'

'}else{op+='

'+times[n].getAttribute('aria-label')+'

'}}}else{if(tweets[n].textContent){if(printUser){op+='

'+authors[n].textContent+'

'} +op+='

'+tweets[n].textContent+'

';if(printTime){op+='

'+times[n].textContent+'

'}}else{if(printUser){op+='

'+authors[n].textContent+'

'} +op+='

'+tweets[n].textContent+'

';if(printTime){op+='

'+times[n].textContent+'

'}}} +if(showInteractionLinks){op+='

'+'

'} +if(showImages&&images[n]!==undefined&&extractImageUrl(images[n])!==undefined){op+='
'+'Image from tweet'+'
'} +if(showImages){arrayTweets.push(op)}else if(!showImages&&tweets[n].textContent.length){arrayTweets.push(op)} +n++}} +handleTweets(arrayTweets);inProgress=!1;if(queue.length>0){twitterFetcher.fetch(queue[0]);queue.splice(0,1)}}};window.__twttrf=twitterFetcher;window.twitterFetcher=twitterFetcher;return twitterFetcher}))