UNPKG

twitter-helper

Version:

Allows to fetch data from Twitter without using its API. Does not require any authentication.

1 lines 1.03 kB
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():t()}(this,function(){const e="myBlockGetTweets",t=()=>{const t=document.getElementById(e);t&&t.parentNode.removeChild(t)},n=t=>{const n=document.createElement("script");return n.type="text/javascript",n.id=e,n.src=["https://syndication.twitter.com/timeline/profile?","callback=twitterHelper.getTweetsByUsernameCallback","&screen_name=",t].join(""),n},i=e=>{return{username:e.querySelector('[data-scribe="element:name"]').innerHTML,text:e.querySelector(".timeline-Tweet-text").innerHTML,published:e.querySelector(".dt-updated").getAttribute("datetime")}},c={getTweetsByUsername(e){t(),document.body.appendChild(n(e))},getTweetsByUsernameCallback(e){const t=document.createElement("div");t.innerHTML=e.body;const n=[...t.querySelectorAll(".timeline-Tweet")].map(i),c=new CustomEvent("tweetsByUsernameFetched",{detail:{tweetsData:n},bubbles:!0,cancelable:!0});document.body.dispatchEvent(c)}};return window.twitterHelper=c,c});