-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblurt-widgets.min.js
8 lines (8 loc) · 14.3 KB
/
blurt-widgets.min.js
1
2
3
4
5
6
7
8
/**
* Blurt Widgets
*
* @author mkt <kontakt@markus-kottlaender.de>
* @author eastmael <eastmaels@gmail.com>
* @license MIT
*/
var blurtWidgets={updateIntervals:[]};blurt.api.setOptions({url:"https://rpc.blurt.world",useAppbaseApi:!0}),blurtWidgets.profile=function(e){var t=Object.assign({element:null,user:"mkt",template:'<img width="100" src="${IMAGE}" /><br><a href="https://blurt.blog/@${USER}">@${USER}</a>',reputationPrecision:0,votingPowerPrecision:2,updateInterval:60,createdCallback:function(e){return["January","February","March","April","May","June","July","August","September","October","November","December"][(e=new Date(e)).getMonth()]+" "+e.getDate()+", "+e.getFullYear()}},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);if(r){function a(){blurt.api.getAccounts([t.user],function(e,a){if(!e&&a.length){var l=(a=a[0]).json_metadata?JSON.parse(a.json_metadata).profile:{};blurt.api.getFollowCount(t.user,function(e,n){var i=blurtWidgets.getTemplate(t.template).replace(/\${USER}/gi,a.name).replace(/\${NAME}/gi,l.name).replace(/\${LOCATION}/gi,l.location).replace(/\${WEBSITE}/gi,l.website).replace(/\${IMAGE}/gi,l.profile_image?"https://blurtimages.com/2048x512/"+l.profile_image:"").replace(/\${COVERIMAGE}/gi,l.cover_image?"https://blurtimages.com/2048x512/"+l.cover_image:"").replace(/\${REPUTATION}/gi,blurtWidgets.calculateReputation(a.reputation,t.reputationPrecision)).replace(/\${VOTINGPOWER}/gi,blurtWidgets.calculateVotingPower(a.voting_power,a.last_vote_time,t.votingPowerPrecision)).replace(/\${FOLLOWERS}/gi,n.follower_count).replace(/\${FOLLOWING}/gi,n.following_count).replace(/\${POSTCOUNT}/gi,a.post_count).replace(/\${CREATED}/gi,t.createdCallback(a.created)).replace(/\${ABOUT}/gi,l.about);r.innerHTML=i})}else r.innerHTML="Error: API not responding!"})}a(),t.updateInterval&&blurtWidgets.updateIntervals.push(setInterval(a,1e3*t.updateInterval))}else console.log("Element "+t.element+" not found!")},blurtWidgets.blog=function(e){var t=Object.assign({element:null,user:"mkt",limit:10,template:'<div><a href="${URL}">${TITLE}</a>${REBLURTED}<br>${Payout}, ${UPVOTES} Upvotes, ${COMMENTS} Comments</div>',defaultImage:"https://blurtimages.com/DQmXYX9hqSNcikTK8ARb61BPnTk4CKMhaiqr22iCKD8CKsp/blurt-logo.png",reblurtedIndicator:" (reblurted) ",payoutPrecision:2,reputationPrecision:0,updateInterval:60,dateCallback:function(e){return e}},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);if(r){function a(){blurt.api.getDiscussionsByBlog({tag:t.user,limit:t.limit},function(e,a){if(!e&&a.length){for(var l="",n=0;n<a.length;n++){var i=JSON.parse(a[n].json_metadata);l+=blurtWidgets.getTemplate(t.template).replace(/\${URL}/gi,"https://blurt.world"+a[n].url).replace(/\${TITLE}/gi,a[n].title).replace(/\${AUTHOR}/gi,a[n].author).replace(/\${REPUTATION}/gi,blurtWidgets.calculateReputation(a[n].author_reputation,t.reputationPrecision)).replace(/\${REBLURTED}/gi,a[n].author!=t.user?t.reblurtedIndicator:"").replace(/\${REBLURTEDBY}/gi,a[n].first_reblogged_by?"reblurted by "+a[n].first_reblogged_by:"").replace(/\${DATE}/gi,t.dateCallback(new Date(a[n].created))).replace(/\${IMAGE}/gi,i.image?"https://blurtimages.com/2048x512/"+i.image[0]:t.defaultImage).replace(/\${PAYOUT}/gi,blurtWidgets.getPayout(a[n]).toFixed(t.payoutPrecision)).replace(/\${COMMENTS}/gi,a[n].children).replace(/\${UPVOTES}/gi,a[n].net_votes).replace(/\${CATEGORY}/gi,a[n].category)}r.innerHTML=l}else r.innerHTML="Error: API not responding!"})}a(),t.updateInterval&&blurtWidgets.updateIntervals.push(setInterval(a,1e3*t.updateInterval))}else console.log("Element "+t.element+" not found!")},blurtWidgets.feed=function(e){var t=Object.assign({element:null,user:"mkt",limit:10,template:'<div><a href="${URL}">${TITLE}</a>${REBLURTED}<br>${Payout}, ${UPVOTES} Upvotes, ${COMMENTS} Comments</div>',defaultImage:"https://blurtimages.com/DQmXYX9hqSNcikTK8ARb61BPnTk4CKMhaiqr22iCKD8CKsp/blurt-logo.png",reblurtedIndicator:" (reblurted) ",payoutPrecision:2,reputationPrecision:0,updateInterval:60,dateCallback:function(e){return e}},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);if(r){function a(){blurt.api.getDiscussionsByFeed({tag:t.user,limit:t.limit},function(e,a){if(!e&&a.length){for(var l="",n=0;n<a.length;n++){var i=JSON.parse(a[n].json_metadata);l+=blurtWidgets.getTemplate(t.template).replace(/\${URL}/gi,"https://blurt.world"+a[n].url).replace(/\${TITLE}/gi,a[n].title).replace(/\${AUTHOR}/gi,a[n].author).replace(/\${REPUTATION}/gi,blurtWidgets.calculateReputation(a[n].author_reputation,t.reputationPrecision)).replace(/\${REBLURTED}/gi,a[n].first_reblogged_by?t.reblurtedIndicator:"").replace(/\${REBLURTEDBY}/gi,a[n].first_reblogged_by?"reblurted by "+a[n].first_reblogged_by:"").replace(/\${DATE}/gi,t.dateCallback(new Date(a[n].created))).replace(/\${IMAGE}/gi,i.image?"https://blurtimages.com/2048x512/"+i.image[0]:t.defaultImage).replace(/\${PAYOUT}/gi,blurtWidgets.getPayout(a[n]).toFixed(t.payoutPrecision)).replace(/\${COMMENTS}/gi,a[n].children).replace(/\${UPVOTES}/gi,a[n].net_votes).replace(/\${CATEGORY}/gi,a[n].category)}r.innerHTML=l}else r.innerHTML="Error: API not responding!"})}a(),t.updateInterval&&blurtWidgets.updateIntervals.push(setInterval(a,1e3*t.updateInterval))}else console.log("Element "+t.element+" not found!")},blurtWidgets.new=function(e){var t=Object.assign({element:null,tag:null,limit:10,template:'<div><a href="${URL}">${TITLE}</a><br>${Payout}, ${UPVOTES} Upvotes, ${COMMENTS} Comments</div>',defaultImage:"https://blurtimages.com/DQmXYX9hqSNcikTK8ARb61BPnTk4CKMhaiqr22iCKD8CKsp/blurt-logo.png",payoutPrecision:2,reputationPrecision:0,updateInterval:60,dateCallback:function(e){return e}},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);if(r){function a(){blurt.api.getDiscussionsByCreated({tag:t.tag,limit:t.limit},function(e,a){if(!e&&a.length){for(var l="",n=0;n<a.length;n++){var i=JSON.parse(a[n].json_metadata);l+=blurtWidgets.getTemplate(t.template).replace(/\${URL}/gi,"https://blurt.world"+a[n].url).replace(/\${TITLE}/gi,a[n].title).replace(/\${AUTHOR}/gi,a[n].author).replace(/\${REPUTATION}/gi,blurtWidgets.calculateReputation(a[n].author_reputation,t.reputationPrecision)).replace(/\${DATE}/gi,t.dateCallback(new Date(a[n].created))).replace(/\${IMAGE}/gi,i.image?"https://blurtimages.com/2048x512/"+i.image[0]:t.defaultImage).replace(/\${PAYOUT}/gi,blurtWidgets.getPayout(a[n]).toFixed(t.payoutPrecision)).replace(/\${COMMENTS}/gi,a[n].children).replace(/\${UPVOTES}/gi,a[n].net_votes).replace(/\${CATEGORY}/gi,a[n].category)}r.innerHTML=l}else r.innerHTML="Error: API not responding!"})}a(),t.updateInterval&&blurtWidgets.updateIntervals.push(setInterval(a,1e3*t.updateInterval))}else console.log("Element "+t.element+" not found!")},blurtWidgets.hot=function(e){var t=Object.assign({element:null,tag:null,limit:10,template:'<div><a href="${URL}">${TITLE}</a><br>${Payout}, ${UPVOTES} Upvotes, ${COMMENTS} Comments</div>',defaultImage:"https://blurtimages.com/DQmXYX9hqSNcikTK8ARb61BPnTk4CKMhaiqr22iCKD8CKsp/blurt-logo.png",payoutPrecision:2,reputationPrecision:0,updateInterval:60,dateCallback:function(e){return e}},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);if(r){function a(){blurt.api.getDiscussionsByHot({tag:t.tag,limit:t.limit},function(e,a){if(!e&&a.length){for(var l="",n=0;n<a.length;n++){var i=JSON.parse(a[n].json_metadata);l+=blurtWidgets.getTemplate(t.template).replace(/\${URL}/gi,"https://blurt.world"+a[n].url).replace(/\${TITLE}/gi,a[n].title).replace(/\${AUTHOR}/gi,a[n].author).replace(/\${REPUTATION}/gi,blurtWidgets.calculateReputation(a[n].author_reputation,t.reputationPrecision)).replace(/\${DATE}/gi,t.dateCallback(new Date(a[n].created))).replace(/\${IMAGE}/gi,i.image?"https://blurtimages.com/2048x512/"+i.image[0]:t.defaultImage).replace(/\${PAYOUT}/gi,blurtWidgets.getPayout(a[n]).toFixed(t.payoutPrecision)).replace(/\${COMMENTS}/gi,a[n].children).replace(/\${UPVOTES}/gi,a[n].net_votes).replace(/\${CATEGORY}/gi,a[n].category)}r.innerHTML=l}else r.innerHTML="Error: API not responding!"})}a(),t.updateInterval&&blurtWidgets.updateIntervals.push(setInterval(a,1e3*t.updateInterval))}else console.log("Element "+t.element+" not found!")},blurtWidgets.trending=function(e){var t=Object.assign({element:null,tag:null,limit:10,template:'<div><a href="${URL}">${TITLE}</a><br>${Payout}, ${UPVOTES} Upvotes, ${COMMENTS} Comments</div>',defaultImage:"https://blurtimages.com/DQmXYX9hqSNcikTK8ARb61BPnTk4CKMhaiqr22iCKD8CKsp/blurt-logo.png",payoutPrecision:2,reputationPrecision:0,updateInterval:60,dateCallback:function(e){return e}},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);if(r){function a(){blurt.api.getDiscussionsByTrending({tag:t.tag,limit:t.limit},function(e,a){if(!e&&a.length){for(var l="",n=0;n<a.length;n++){var i=JSON.parse(a[n].json_metadata);l+=blurtWidgets.getTemplate(t.template).replace(/\${URL}/gi,"https://blurt.world"+a[n].url).replace(/\${TITLE}/gi,a[n].title).replace(/\${AUTHOR}/gi,a[n].author).replace(/\${REPUTATION}/gi,blurtWidgets.calculateReputation(a[n].author_reputation,t.reputationPrecision)).replace(/\${DATE}/gi,t.dateCallback(new Date(a[n].created))).replace(/\${IMAGE}/gi,i.image?"https://blurtimages.com/2048x512/"+i.image[0]:t.defaultImage).replace(/\${PAYOUT}/gi,blurtWidgets.getPayout(a[n]).toFixed(t.payoutPrecision)).replace(/\${COMMENTS}/gi,a[n].children).replace(/\${UPVOTES}/gi,a[n].net_votes).replace(/\${CATEGORY}/gi,a[n].category)}r.innerHTML=l}else r.innerHTML="Error: API not responding!"})}a(),t.updateInterval&&blurtWidgets.updateIntervals.push(setInterval(a,1e3*t.updateInterval))}else console.log("Element "+t.element+" not found!")},blurtWidgets.fullPost=function(e){var t=Object.assign({element:null,author:"mkt",permlink:"blurtline-beta-multifeed-ui-and-notifications-for-blurt",template:'<div><a href="${URL}">${TITLE}</a><br>${Payout}, ${UPVOTES} Upvotes, ${COMMENTS} Comments<p>${BODY}</p></div>',payoutPrecision:2,reputationPrecision:0,dateCallback:function(e){return e},bodyCallback:function(e){return e},tagsCallback:function(e){var t,r="";for(t=0;t<e.length;t++)r+='<a href="https://blurt.world/trending/'+e[t]+'">'+e[t]+"</a>";return'<div class="blurt-full-post-tags">'+r+"</div>"}},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);r?blurt.api.getContent(t.author,t.permlink,function(e,a){if(!e&&a){var l=JSON.parse(a.json_metadata),n=blurtWidgets.getTemplate(t.template).replace(/\${URL}/gi,"https://blurt.world"+a.url).replace(/\${TITLE}/gi,a.title).replace(/\${AUTHOR}/gi,a.author).replace(/\${REPUTATION}/gi,blurtWidgets.calculateReputation(a.author_reputation,t.reputationPrecision)).replace(/\${DATE}/gi,t.dateCallback(new Date(a.created))).replace(/\${BODY}/gi,t.bodyCallback(a.body)).replace(/\${PAYOUT}/gi,blurtWidgets.getPayout(a).toFixed(t.payoutPrecision)).replace(/\${COMMENTS}/gi,a.children).replace(/\${UPVOTES}/gi,a.net_votes).replace(/\${CATEGORY}/gi,a.category).replace(/\${TAGS}/gi,t.tagsCallback(l.tags));r.innerHTML=n}else r.innerHTML="Error: API not responding!"}):console.log("Element "+t.element+" not found!")},blurtWidgets.ticker=function(e){var t=Object.assign({element:null,currency:"blurt",template:"<h3>${NAME} <small>(${SYMBOL})</small></h3><p>USD: ${PRICE_USD}<br>BTC: ${PRICE_BTC}</p>",priceBTCPrecision:8,priceUSDPrecision:2,updateInterval:300},e),r=t.element instanceof Element?t.element:document.getElementById(t.element);if(r){function a(){var e=new XMLHttpRequest;e.open("GET","https://api.coinmarketcap.com/v1/ticker/"+t.currency+"/",!0),e.send(),e.onreadystatechange=function(){if(4==e.readyState)if(200==e.status){var a=JSON.parse(e.responseText)[0],l="";l+=blurtWidgets.getTemplate(t.template).replace(/\${ID}/g,a.id).replace(/\${NAME}/g,a.name).replace(/\${RANK}/g,a.rank).replace(/\${SYMBOL}/g,a.symbol).replace(/\${IMAGE}/g,"https://files.coinmarketcap.com/static/img/coins/64x64/"+a.id+".png").replace(/\${24H_VOLUME_USD}/g,parseFloat(a["24h_volume_usd"]).toLocaleString(void 0,{minimumFractionDigits:2})).replace(/\${AVAILABLE_SUPPLY}/g,parseFloat(a.available_supply).toLocaleString(void 0,{minimumFractionDigits:2})).replace(/\${TOTAL_SUPPLY}/g,parseFloat(a.total_supply).toLocaleString(void 0,{minimumFractionDigits:2})).replace(/\${MARKET_CAP_USD}/g,parseFloat(a.market_cap_usd).toLocaleString()).replace(/\${PERCENT_CHANGE_1H}/g,blurtWidgets.getColoredPercentChange(a.percent_change_1h)).replace(/\${PERCENT_CHANGE_7D}/g,blurtWidgets.getColoredPercentChange(a.percent_change_7d)).replace(/\${PERCENT_CHANGE_24H}/g,blurtWidgets.getColoredPercentChange(a.percent_change_24h)).replace(/\${PRICE_BTC}/g,parseFloat(a.price_btc).toFixed(t.priceBTCPrecision)).replace(/\${PRICE_USD}/g,parseFloat(a.price_usd).toFixed(t.priceUSDPrecision)),r.innerHTML=l}else r.innerHTML="Error: API not responding!"}}a(),t.updateInterval&&blurtWidgets.updateIntervals.push(setInterval(a,1e3*t.updateInterval))}else console.log("Element "+t.element+" not found!")},blurtWidgets.getTemplate=function(e){var t=document.getElementById(e);return t?t.innerHTML:e},blurtWidgets.getPayout=function(e){if("1970-01-01T00:00:00"==e.last_payout){var t=e.pending_payout_value.replace(" SBD","");return parseFloat(t)}var r=e.total_payout_value.replace(" SBD",""),a=e.curator_payout_value.replace(" SBD","");return parseFloat(r)+parseFloat(a)},blurtWidgets.getColoredPercentChange=function(e){return e>0&&(e="+"+e),e>0?'<span style="color: #090;">'+e+" %</span>":e<0?'<span style="color: #900;">'+e+" %</span>":e+" %"},blurtWidgets.calculateReputation=function(e,t){var r=9*(Math.log10(Math.abs(e))-9)+25;return(e<0?"-":"")+((t=parseInt(t))?r.toFixed(t):Math.floor(r))},blurtWidgets.calculateVotingPower=function(e,t,r){return e+=1e4*((new Date-new Date(t+"Z"))/1e3)/432e3,Math.min(e/100,100).toFixed(r)},window.jQuery&&(jQuery.fn.blurtProfile=function(e){blurtWidgets.profile(jQuery.extend({element:this[0]},e))},jQuery.fn.blurtBlog=function(e){blurtWidgets.blog(jQuery.extend({element:this[0]},e))},jQuery.fn.blurtFeed=function(e){blurtWidgets.feed(jQuery.extend({element:this[0]},e))},jQuery.fn.blurtNew=function(e){blurtWidgets.new(jQuery.extend({element:this[0]},e))},jQuery.fn.blurtHot=function(e){blurtWidgets.hot(jQuery.extend({element:this[0]},e))},jQuery.fn.blurtTrending=function(e){blurtWidgets.trending(jQuery.extend({element:this[0]},e))},jQuery.fn.blurtFullPost=function(e){blurtWidgets.fullPost(jQuery.extend({element:this[0]},e))},jQuery.fn.blurtTicker=function(e){blurtWidgets.ticker(jQuery.extend({element:this[0]},e))});