$(function() { (function($) { var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; $.fn.attrchange = function(callback) { if(MutationObserver) { var options = { subtree: false, attributes: true }; var observer = new MutationObserver(function(mutations) { mutations.forEach(function(e) { callback.call(e.target,e.attributeName); }); }); return this.each(function() { observer.observe(this,options); }); } } })(jQuery); (function($) { $.fn.insertText = function(textToInsert) { return this.each(function() { var txt = $(this); var cursorPosStart = txt.prop('selectionStart'); var cursorPosEnd = txt.prop('selectionEnd'); var v = txt.val(); var textBefore = v.substring(0,cursorPosStart); var textAfter = v.substring(cursorPosEnd,v.length); txt.val(textBefore + textToInsert + textAfter); txt.prop('selectionStart',cursorPosStart + textToInsert.length); txt.prop('selectionEnd',cursorPosStart + textToInsert.length); txt.focus(); }); } })(jQuery); $.extend($.expr[':'],{ blank:function(el){ return $(el).val().match(/^\s*$/); } }); }); function indicesOf(input,value) { var indices = new Array(); var index = 0; while(index != -1) { index = input.indexOf(value,index); if(index != -1) indices.push(index++); } return indices; } function getLinkFromXHRHeader(xhrheaderstring) { const re = xhrheaderstring.match(/link: <.+api\/v1\/(.+?)>; rel="(.+?)", <.+api\/v1\/(.+?)>; rel="(.+?)"/i); let di = new Object(); if(re){ di[re[2]] = re[1]; di[re[4]] = re[3]; } return di; } function replaceInternalLink(){ $(".toot_article a,.profile_bio a,.follows_profile_bio a").each(function(i) { const pltags = $(this).attr('href').match(/https?:\/\/.+..+\/tag\/([a-zA-Z\d_%]+)\/?$/); if(pltags) $(this).attr('target','_self').attr('href','/search?q='+pltags[1]); const mstags = $(this).attr('href').match(/https?:\/\/.+..+\/tags\/([a-zA-Z\d_%]+)\/?$/); if(mstags) $(this).attr('target','_self').attr('href','/search?q='+mstags[1]); const plusers = $(this).attr('href').match(/https?:\/\/.+..+\/users\/([a-zA-Z\d_]+)(\/statuses\/\d+)\/?$/); if(plusers) $(this).attr('target','_self').attr('href','/@'+plusers[1]+'@'+$(this).attr('href').split("/")[2]); const msusers = $(this).attr('href').match(/https?:\/\/.+..+\/@([a-zA-Z\d_]+)\/?$/); if(msusers) $(this).attr('target','_self').attr('href','/@'+msusers[1]+'@'+$(this).attr('href').split("/")[2]); const msstatus = $(this).attr('href').match(/https?:\/\/.+..+\/@([a-zA-Z\d_]+)(\/\d+)\/?$/); if(msstatus) $(this).attr('target','_self').attr('href',"javascript:openStatus('"+msstatus[0]+"');void(0)"); const msstatus2 = $(this).attr('href').match(/https?:\/\/.+..+\/users\/([a-zA-Z\d_]+)\/?$/); if(msstatus2) $(this).attr('target','_self').attr('href',"javascript:openStatus('"+msstatus2[0]+"');void(0)"); const gsstatus = $(this).attr('href').match(/https?:\/\/.+..+\/notice\/(\d+)\/?$/); if(gsstatus) $(this).attr('target','_self').attr('href',"javascript:openStatus('"+gsstatus[0]+"');void(0)"); const plstatus = $(this).attr('href').match(/https?:\/\/.+..+\/objects\/([\da-z]{8}-[\da-z]{4}-[\da-z]{4}-[\da-z]{4}-[\da-z]{12})\/?$/); if(plstatus) $(this).attr('target','_self').attr('href',"javascript:openStatus('"+plstatus[0]+"');void(0)"); }); $(".toot_article a").each(function(i) { const ytcom = $(this).attr('href').match(/https?:\/\/(www\.)?youtube\.com\/watch\?v=([a-zA-Z\d_-]+)/); const htcom = $(this).attr('href').match(/https?:\/\/(www\.)?hooktube\.com\/watch\?v=([a-zA-Z\d_-]+)/); const ivcom = $(this).attr('href').match(/https?:\/\/(www\.)?invidio\.us\/watch\?v=([a-zA-Z\d_-]+)/); const ytbe = $(this).attr('href').match(/https?:\/\/(www\.)?youtu\.be\/([a-zA-Z\d_-]+)/); const htbe = $(this).attr('href').match(/https?:\/\/(www\.)?hooktube\.com\/([a-zA-Z\d_-]+)/); const vimeo = $(this).attr('href').match(/https?:\/\/(www\.)?vimeo\.com\/([\d]+)/); const peertube = $(this).attr('href').match(/https?:\/\/.+..+\/videos\/watch\/([\da-z]{8}-[\da-z]{4}-[\da-z]{4}-[\da-z]{4}-[\da-z]{12})\/?$/); if(ytcom) embedMedia("youtube",$(this).closest(".toot_article"),ytcom[2]); else if(htcom) embedMedia("youtube",$(this).closest(".toot_article"),htcom[2]); else if(ivcom) embedMedia("youtube",$(this).closest(".toot_article"),ivcom[2]); else if(ytbe) embedMedia("youtube",$(this).closest(".toot_article"),ytbe[2]); else if(htbe) embedMedia("youtube",$(this).closest(".toot_article"),htbe[2]); else if(vimeo) embedMedia("vimeo",$(this).closest(".toot_article"),vimeo[2]); else if(peertube) embedMedia("peertube",$(this).closest(".toot_article"),peertube[0].replace("/watch/","/embed/")); }); } function getConversionedDate(key, value) { if (value === null || value.constructor !== String || value.search(/^\d{4}-\d{2}-\d{2}/g) === -1) return value; return new Date(value); } function getRelativeDatetime(current_time,posted_time,withdot = true,future = false) { const calendar = [__("Jan"),__("Feb"),__("Mar"),__("Apr"),__("May"),__("Jun"),__("Jul"),__("Aug"),__("Sep"),__("Oct"),__("Nov"),__("Dec")]; var posted_time_original = posted_time, posted_time = getConversionedDate(null, posted_time_original).getTime(); if(future) var elapsedTime = Math.ceil((posted_time-current_time)/1000); else var elapsedTime = Math.ceil((current_time-posted_time)/1000); var dot = ""; if(withdot) dot = "· "; if(elapsedTime < 60) { const datetime = dot + elapsedTime + "s"; return datetime; } else if (elapsedTime < 120) { const datetime = dot+"1m"; return datetime; } else if (elapsedTime < (60*60)) { const datetime = dot + (Math.floor(elapsedTime / 60) < 10 ? " " : "") + Math.floor(elapsedTime / 60) + "m"; return datetime; } else if (elapsedTime < (120*60)) { const datetime = dot+"1h"; return datetime; } else if (elapsedTime < (24*60*60)) { const datetime = dot + (Math.floor(elapsedTime / 3600) < 10 ? " " : "") + Math.floor(elapsedTime / 3600) + "h"; return datetime; } else { const datetime = dot + calendar[posted_time_original.getMonth()] + " " + posted_time_original.getDate(); return datetime; } } function htmlEscape(strings, ...values) { var handleString = function(str) { return str.replace(/&/g, '&') .replace(/>/g, '>') .replace(/"); current_filters = new Array; } localStorage.setItem("current_display_name",AccountObj["display_name"]); localStorage.setItem("current_acct",AccountObj["acct"]); localStorage.setItem("current_url","/@"+AccountObj["acct"]+"@"+current_instance+"?mid="+current_id); localStorage.setItem("current_header",AccountObj["header"]); localStorage.setItem("current_avatar",AccountObj["avatar"]); localStorage.setItem("current_locked",AccountObj["locked"]); localStorage.setItem("current_statuses_count",AccountObj["statuses_count"]); localStorage.setItem("current_following_count",AccountObj["following_count"]); localStorage.setItem("current_followers_count",AccountObj["followers_count"]); localStorage.setItem("current_follow_loaded","false"); current_display_name = localStorage.getItem("current_display_name"); current_acct = localStorage.getItem("current_acct"); current_url = localStorage.getItem("current_url"); current_header = localStorage.getItem("current_header"); current_avatar = localStorage.getItem("current_avatar"); current_locked = localStorage.getItem("current_locked"); current_statuses_count = localStorage.getItem("current_statuses_count"); current_following_count = localStorage.getItem("current_following_count"); current_followers_count = localStorage.getItem("current_followers_count"); current_search_history = JSON.parse(localStorage.getItem("current_search_history")); setCurrentProfile(); }); api.get("accounts/"+current_id+"/following",function(data) { var followings = new Array(); for(var i=0;i").attr("class","responsive_left").append($(".right_column").children())); $(".right_column").remove(); } else { responsive_design = false; } if (Notification.permission === 'default') { Notification.requestPermission(function(p) { if (p === 'denied') { localStorage.setItem("setting_desktop_notifications","false"); } }); } else if(Notification.permission == "denied") { localStorage.setItem("setting_desktop_notifications","false"); } if(localStorage.setting_who_to_follow == "true") { setWhoToFollow(); } if(!localStorage.hide_firefox_download || localStorage.hide_firefox_download != "true") $("#widget_ffdl").show(); replace_emoji(); } function putMessage(Message) { $('#overlay_message').addClass('view'); $('#overlay_message section span').text(Message); setTimeout(function(){ $("#overlay_message").removeClass("view"); },3000); }; function pushNotification(title,message) { if (window.Notification && localStorage.setting_desktop_notifications == "true") { if (Notification.permission === 'granted') { notify = new Notification(title, { body: message, icon: '/assets/images/halcyon_logo.png' }); } } } function getRandom() { var s4 = function() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } function randomNumber(min,max) { return Math.floor(Math.random() * (max - min)) + min; } function setWhoToFollow(sanimate) { if(sanimate == true) { $(".follow_opt_in").slideUp(function() {$(".follow_loading").slideDown()}); } else { $(".follow_opt_in").hide(); $(".follow_loading").show(); } if(localStorage.current_follow_loaded == "true") { if(localStorage.who_to_follow) { follow_loaded = 0; var wtflist = JSON.parse(localStorage.who_to_follow); addFollowProfile(0,wtflist[randomNumber(0,wtflist.length)]); addFollowProfile(1,wtflist[randomNumber(0,wtflist.length)]); addFollowProfile(2,wtflist[randomNumber(0,wtflist.length)]); var checkload = setInterval(function() { if(follow_loaded == 3) { clearInterval(checkload); $(".follow_loading").hide(); $(".what_to_follow").show(); replace_emoji(); } },100); } else { $("#follow_icon").removeClass("fa-circle-o-notch").removeClass("fa-spin").addClass("fa-id-card-o").addClass("fa-stack-1x").after($("").addClass("fa").addClass("fa-ban").addClass("fa-stack-2x")); } } else { var url = $("#who-to-follow-provider").html(); url = url.replace(/{{host}}/g, encodeURIComponent(current_instance)); url = url.replace(/{{user}}/g, encodeURIComponent(current_acct)); $.ajax(url).done(function(data) { localStorage.current_follow_loaded = true; if(data.status == 200) { var wtflist = new Array(); for(i=0;i"); } if(search.accounts[0].display_name.length == 0) { search.accounts[0].display_name = search.accounts[0].username; } var wtf_account_link; if(search.accounts[0].acct.indexOf("@") == -1) wtf_account_link = "/@"+search.accounts[0].acct+"@"+current_instance+"?mid="+search.accounts[0].id; else wtf_account_link = "/@"+search.accounts[0].acct+"?mid="+search.accounts[0].id; $('.what_to_follow_'+id+' > .icon_box img').attr('src',search.accounts[0].avatar); $('.what_to_follow_'+id+' .label_box > a').attr('href',wtf_account_link); $('.what_to_follow_'+id+' .label_box > a > h3 .dn').addClass("emoji_poss").html(search.accounts[0].display_name); $('.what_to_follow_'+id+' .label_box > a > h3 .un').text('@'+search.accounts[0].username); $('.what_to_follow_'+id+' .label_box > .follow_button').attr('mid',search.accounts[0].id); $('.what_to_follow_'+id+' .label_box > .follow_button').attr('data',search.accounts[0].url); follow_loaded++; }); } function checkEmojiSupport() { var ctx = document.createElement("canvas").getContext("2d"); ctx.fillText("😗",-2,4); return ctx.getImageData(0,0,1,1).data[3] > 0; } function openStatus(link) { api.get("search?q="+link,function(response) { if(response.statuses.length > 0) { var data = response.statuses[0]; if(data.account.acct.indexOf("@") == -1) { data.account.acct = data.account.acct+"@"+current_instance; } window.location.href = "/@"+data.account.acct+"/status/"+data.id+"&mid="+data.account.id; } else { window.location.href = "/404"; } }); } function embedMedia(source,element,watchid) { if(element.children(".media_views").length == 0) { let media_views = `
`; if(source == "youtube" && server_setting_youplay == true && localStorage.setting_play_youplay == "true") { media_views += (`
`); } else if( source == "youtube" && localStorage.setting_play_invidious == "true") { media_views += (`
`); } else if(source == "vimeo" && server_setting_vimeo == true && localStorage.setting_play_vimeo == "true") { media_views += (`
`); } else if(source == "peertube" && localStorage.setting_play_peertube == "true") { media_views += (`
`); } media_views += "
"; if($(media_views).children().length != 0) element.append(media_views); } } function enableAutoComplete(textarea) { if(localStorage.setting_compose_autocomplete == "true") { textarea.autoCompleteToken({instance:1,startkey:"@",endkey:" ",arrayname:"accounts",resultname:"acct"}); textarea.autoCompleteToken({instance:2,startkey:"#",endkey:" ",arrayname:"hashtags"}); textarea.autoCompleteToken({instance:3,startkey:":",endkey:";",source:actEmojiData,resultname:"name",callback:function() { textarea.trigger({"type":"keyup","key":":"}); }}); } } function submitStatusArray(params,callback) { var statuses = params.status; params.status = params.status.first().val(); api.post("statuses",params,function(data) { statuses = statuses.filter(function(index) {return index != 0}); if(statuses.length == 0) { callback(); } else { var nparams = new Object(); nparams.status = statuses; nparams.visibility = params.visibility; nparams.spoiler_text = params.spoiler_text; nparams.in_reply_to_id = data.id; submitStatusArray(nparams,callback); } }); }