Advertisement
Guest User

Untitled

a guest
Apr 25th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.63 KB | None | 0 0
  1. javascript:(function(){const version="2.06e";const setting={"trim_blank_line":10,"replace_youtube_url":2,"replace_youtube_url_methods":["none","space","short"]};class Tweet{constructor(feed,tweetid,twitter,isChild){let tweet=feed.globalObjects.tweets[tweetid];let user=feed.globalObjects.users[tweet.user_id_str];this.promises=[];this.feed=feed;this.tweetid=tweetid;this.twitter=twitter;this.tweet=tweet;this.user=user;this.username=this.removeEmoji(user.name);this.screen_name=user.screen_name;this.created_at=new Date(tweet.created_at);this.isChild=isChild;this.body=this.removeEmoji((tweet.full_text&&tweet.full_text.substring(...Tweet.gettextrange(tweet.full_text,tweet.display_text_range[0],tweet.display_text_range[1])))||"");if(tweet.card){if(tweet.card.binding_values.title){let title=tweet.card.binding_values.title.string_value;let titlepart=title.split(/( - )|(|)|( \| )/);if(!(this.body.indexOf(title)>=0||(titlepart.length>=2&&this.body.indexOf(titlepart[0])>=0))){this.body=this.body.replace(tweet.card.binding_values.card_url.string_value,tweet.card.binding_values.title.string_value+"\n"+tweet.card.binding_values.card_url.string_value)}}let choice=tweet.card.name.match(/poll(\d)choice_text_only/);if(choice){this.is_enq_end=tweet.card.binding_values.counts_are_final.boolean_value;this.enq_enddate=new Date(tweet.card.binding_values.end_datetime_utc.string_value);if(tweet.card.binding_values.last_updated_datetime_utc){this.enq_lastupdate=new Date(tweet.card.binding_values.last_updated_datetime_utc.string_value)}this.enq=[];let num=choice[1];for(let i=1;i<=num;i++){this.enq.push({name:tweet.card.binding_values["choice"+i+"_label"].string_value,amount:parseInt(tweet.card.binding_values["choice"+i+"_count"].string_value)})}}if(tweet.card.binding_values.player_stream_url&&/.*\.vmap$/.test(tweet.card.binding_values.player_stream_url.string_value)){this.promises.push(this.getURLFromVMAP(tweet.card.binding_values.player_stream_url.string_value))}}if(tweet.entities&&tweet.entities.urls){tweet.entities.urls.forEach(url=>{this.body=this.body.replace(url.url,url.expanded_url)})}if(tweet.in_reply_to_screen_name){this.replyTo=this.replyTo||[];this.replyTo.push("@"+tweet.in_reply_to_screen_name)}if(tweet.entities&&tweet.entities.user_mentions){tweet.entities.user_mentions.forEach(mention=>{this.replyTo=this.replyTo||[];let str="@"+mention.screen_name;if(this.replyTo.indexOf(str)<0){this.replyTo.push(str)}})}tweet.extended_entities&&tweet.extended_entities.media.map(x=>{switch(x.type){case"animated_gif":case"video":let arr=x.video_info.variants.filter(y=>{return y.content_type==="video/mp4"}).map(y=>{return y.bitrate}).sort();this.videourl=x.video_info.variants.filter(y=>{return y.bitrate===arr[0]?y:null})[0].url.replace(/\?tag=\w*/,"");this.body=this.body.replace(x.url,this.videourl);break;case"photo":this.imgs=this.imgs||[];this.imgs.push(x.media_url_https);this.body=this.body.replace(x.url,x.media_url_https);break}});if(tweet.quoted_status_permalink&&!isChild){this.child=new Tweet(feed,Twitter.getTweetId(new URL(tweet.quoted_status_permalink.expanded)),twitter,true);this.body=this.body.replace(tweet.quoted_status_permalink.expanded,"")}};toString(){let str="";str+=this.username+" @"+this.screen_name+" ("+this.getDate()+") \n";str+=(this.replyTo?this.replyTo.filter(id=>{return this.body.indexOf(id)<0?id:null}).join(" ")+" ":"");str+=(this.body?this.replaceYouTubeURL(this.replaceNGWord(this.body))+"\n":"");if(this.enq){let total=this.enq.reduce((x,y)=>{return{amount:x.amount+y.amount}}).amount;let i=1;str+="【投票"+(this.is_enq_end?"結果":"中")+":"+this.getenqRemainTime();str+="("+(this.is_enq_end?"計":"現在")+total.toLocaleString()+"票)"+"】\n";str+=this.enq.map(item=>{return"["+i++ +"] "+item.name+"("+(total>0?Math.round(item.amount/total*100):0)+"%)\n"}).join("")}str+=(this.imgs?this.imgs.map(url=>{return this.body.indexOf(url)<0?url+"\n":""}).join(""):"");str+=(this.videourl&&this.body.indexOf(this.videourl)<0?this.replaceYouTubeURL(this.videourl)+"\n":"");str+=this.getURL();if(this.child){str+="\n[引用元] "+this.child.toString()}if(str.split("\n").length>parseInt(setting.trim_blank_line)){str=str.replace(/^\s*\n/gm,"")}console.log(this);console.log(str);return str}async getURLFromVMAP(vmap){await fetch(vmap).then(res=>{return res.text().then(text=>{let p=new DOMParser();let xml=p.parseFromString(text,"text/xml");let arr=Array.from(xml.getElementsByTagName("tw:videoVariant")).filter(x=>{return x.getAttribute("content_type")==="video/mp4"});let bitrate=arr.map(x=>{return x.getAttribute("bit_rate")}).sort();let videourl=arr.filter(x=>{return x.getAttribute("bit_rate")===bitrate[0]})[0].getAttribute("url");this.videourl=decodeURIComponent(videourl)})})}getenqRemainTime(){if(this.is_enq_end){return""}let diffsecond=Math.trunc((this.enq_enddate.getTime()-new Date().getTime())/1000);let day=Math.trunc(diffsecond/60/60/24);if(day>0){return"残り"+day+"日"}diffsecond-=day*60*60*24;let hour=Math.trunc(diffsecond/60/60);if(hour>0){return"残り"+hour+"時間"}diffsecond-=hour*60*60;let minute=Math.trunc(diffsecond/60);if(minute>0){return"残り"+minute+"分"}diffsecond-=minute*60;if(diffsecond>0){return"残り"+diffsecond+"秒"}return""}getURL(){return"https://twitter.com/"+this.screen_name+"/status/"+this.tweetid}getDate(){let d=this.created_at;return d.getFullYear()+"/"+("0"+(d.getMonth()+1)).slice(-2)+"/"+("0"+(d.getDate())).slice(-2)+" "+("0"+(d.getHours())).slice(-2)+":"+("0"+(d.getMinutes())).slice(-2)+":"+("0"+(d.getSeconds())).slice(-2)}replaceNGWord(text){Twitter.ngurl.forEach(urlregexp=>{let ngurl=this.body.match(urlregexp);if(ngurl){ngurl.forEach(url=>{text=text.replace(url,this.makeRedirectURL(url))})}});Twitter.ngword.forEach(ng=>{text=text.replace(ng.before,ng.after)});return text}fixedEncodeURIComponent(str,strong){let pattern=strong?/[a-zA-Z!'()*.-]/g:/[!'()*.-]/g;return encodeURIComponent(str).replace(pattern,function(c){return'%'+c.charCodeAt(0).toString(16).toUpperCase()})}makeRedirectURL(str,p){if(!p){str=Twitter.ngdomain.reduce((u,domain)=>{return u.replace(domain,this.fixedEncodeURIComponent(domain,true))},str);return"https://www.google.co.jp/url?q="+this.fixedEncodeURIComponent(str)}else{let url=new URL(str);return"http://pyokopyoko.php.xdomain.jp/redirect/?ssl="+(url.protocol==="https:"?"1":"0")+"&d="+url.host.replace(".","_")+"&p="+url.pathname.replace(/^\//,"")}}replaceYouTubeURL(url){if(!setting.replace_youtube_url){return url}let method=setting.replace_youtube_url_methods[setting.replace_youtube_url];switch(method){case"space":url=url.replace(/youtu\.be/g,"you tu.be");url=url.replace(/youtube.com/g,"you tube.com");break;case"short":url=url.replace(/https?:\/\/(?:.*?youtu\.be\/|.*?youtube\.com\/watch.*?v=)([A-Za-z\-\_0-9]+)(?:[\?\&\#][^t][\=\-\w\.]*)*(?:[\?\&\#]t=)([\dhms]+)(?:[\?\&\#][\w\=\-\.]*)*/g,"http://pyokopyoko.php.xdomain.jp/redirect/?yt=$1&t=$2 https://i.ytimg.com/vi/$1/hqdefault.jpg");url=url.replace(/https?:\/\/(?:.*?youtu\.be\/|.*?youtube\.com\/watch.*?v=)([A-Za-z\-\_0-9]+)(?:[\?\&\#][\w\=\-\.]*)*/g,"http://y2u.be/$1 https://i.ytimg.com/vi/$1/hqdefault.jpg");break}return url}removeEmoji(text){if(typeof text!=="string"){return text}return text.replace(this.twitter.emojiRegExp,"")}static r3(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++){n[t]=e[t]}return n}return(0,Array.from)(e)};static r1(e){return e.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/gm," ").length};static gettextrange(e,t,n){var u=(0,Tweet.r1)(e);if(e.length-u>0){var i=[].concat((0,Tweet.r3)(e)),a=0===t?"":i.slice(0,t).join(""),c=i.slice(t,n).join("");return[a.length,a.length+c.length]}return[t,n]}};class Twitter{constructor(){this.mainurl=Twitter.getScriptURL("/main");this.vendorurl=Twitter.getScriptURL("vendors~main");if(this.mainiurl===""||this.vendorurl===""){this.oldstyle=true;this.mainurl=Twitter.getScriptURL("/init\.ja");this.vendorurl=Twitter.getScriptURL("/init\.ja")}this.tweetid=Twitter.getTweetId();this.csfrtoken=Twitter.getCSFRToken()};static getScriptURL(scriptname){let r=new RegExp(scriptname+"\\.\\w*\\.js");let mainscript=Array.from(document.querySelectorAll("script")).filter(x=>{return x.src.match(r)})[0];return mainscript?mainscript.src:""}static getTweetId(url=location){let path=url.pathname.match(/\/[^\/]+\/status\/(\d+)/);if(!path){return}return path[1]}static getCSFRToken(){let n=document.cookie.match(/ct0=([^;]*);?/);if(n){return n[1]}}static ngurl=[/(https?:\/\/note\.mu\/?[^\s]*)/g,/(https?:\/\/www\.amazon\.co[^\s]*)/g,/(https?:\/\/www\.amazon\.jp\/?[^\s]*)/g,/(https?:\/\/seed\.online\/?[^\s]*)/g,/(https?:\/\/.*hatenablog\.com\/?[^\s]*)/g,/(https?:\/\/bit\.ly\/?[^\s]*)/g,/(https?:\/\/pr5\.work\/?[^\s]*)/g,/(https?:\/\/ow\.ly\/?[^\s]*)/g,/(https?:\/\/buff\.ly\/?[^\s]*)/g,/(https?:\/\/.+\.shop\/?[^\s]*)/g,/(https?:\/\/ur0\.link\/?[^\s]*)/g,/(https?:\/\/goo\.gl\/?[^\s]*)/g,/(https?:\/\/discord\.gg\/?[^\s]*)/g,/(https?:\/\/t\.co\/?[^\s]*)/g,/(https?:\/\/lineblog\.me\/?[^\s]*)/g,/(https?:\/\/db\.tt\/?[^\s]*)/g,/(https?:\/\/.*getuploader\.com\/?[^\s]*)/g,/(https?:\/\/.*r10\.to\/?[^\s]*)/g,/(https?:\/\/mjk\.ac\/?[^\s]*)/g,/(https?:\/\/kisu\.me\/?[^\s]*)/g,/(https?:\/\/j55\.pw\/?[^\s]*)/g,/(https?:\/\/j\.mp\/?[^\s]*)/g,/(https?:\/\/www\d?\.to\/?[^\s]*)/g,/(https?:\/\/ux\.nu\/?[^\s]*)/g,/(https?:\/\/urx\d?\.nu\/?[^\s]*)/g,/(https?:\/\/p\.tl\/?[^\s]*)/g,/(https?:\/\/amba\.to\/?[^\s]*)/g,/(https?:\/\/amzn\.to\/?[^\s]*)/g,/(https?:\/\/appsto\.re\/?[^\s]*)/g,/(https?:\/\/dlvr\.it\/?[^\s]*)/g,/(https?:\/\/kuku\.lu\/?[^\s]*)/g,/(https?:\/\/linkclub\.jp\/?[^\s]*)/g,/(https?:\/\/.*sakura.ne.jp\/?[^\s]*)/g,/(https?:\/\/.*wixsite.com\/?[^\s]*)/g,/(https?:\/\/lineblog\.me\/?[^\s]*)/g,/(https?:\/\/kakuyomu\.jp\/?[^\s]*)/g,/(https?:\/\/.*syosetu\.com\/?[^\s]*)/g,/(https?:\/\/.*stores\.jp\/?[^\s]*)/g,/(https?:\/\/.*shop-pro\.jp\/?[^\s]*)/g,/(https?:\/\/.*webmoney\.jp\/?[^\s]*)/g,/(https?:\/\/.*\.live\.nicovideo\.jp\/?[^\s]*)/g,/(https?:\/\/.*linkco\.re\/?[^\s]*)/g,];static ngword=[{before:"拡散希望",after:"拡/散/希/望"},{before:"拡散お願い",after:"拡/散/お/願/い"},{before:/(https?:\/\/marshmallow-qa\.com\/?[^?]+)\?[^\s]+/g,after:"$1"},{before:/&?utm_(source|medium|term|campaign|content)=[^&]*/g,after:""},{before:/([Aa]ma)(zon)/g,after:"$1/$2"},{before:/(am)(zn)/g,after:"$1/$2"},];static ngdomain=["amazon","amzn"];getData(){let m=fetch(this.mainurl,{mode:"cors"}).then(response=>{return response.text()});let v=fetch(this.vendorurl,{mode:"cors"}).then(response=>{return response.text()});Promise.all([m,v]).then(([m,v])=>{this.authtoken=m.match(/"AAAAAA[^"]+"/)[0].replace(/"/g,"");let emoji=v.match(/\/(\(\?:\\ud83d[^\/]+)\/g/);this.emojiRegExp=new RegExp(emoji?emoji[1]:"","g");return this.getTweets()})}getTweets(){let url="https://api.twitter.com/2/timeline/conversation/"+this.tweetid+".json?include_profile_interstitial_type=1&include_blocking=1&include_blocked_by=1&include_followed_by=1&include_want_retweets=1&include_mute_edge=1&include_can_dm=1&include_can_media_tag=1&skip_status=1&cards_platform=Web-12&include_cards=1&include_composer_source=true&include_ext_alt_text=true&include_reply_count=1&tweet_mode=extended&include_entities=true&include_user_entities=true&include_ext_media_color=true&include_ext_media_availability=true&send_error_codes=true&count=20&ext=mediaStats%2ChighlightedLabel%2CcameraMoment";fetch(url,{mode:"cors",credentials:"include",headers:{"authorization":"Bearer "+this.authtoken,"x-csrf-token":this.csfrtoken,"x-twitter-active-user":"yes","x-twitter-auth-type":"OAuth2Session","x-twitter-client-language":"ja"}}).then(response=>{return response.json()}).then(json=>{t=new Tweet(json,this.tweetid,this);if(t.promises.length>0){Promise.all(t.promises).then(x=>{let str=t.toString();navigator.clipboard.writeText(str);return str})}else{let str=t.toString();navigator.clipboard.writeText(str);return str}})}};t=new Twitter(true);t.getData()})();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement