2019-02-03 19:56:49 +01:00
$ ( 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 ) ;
2019-07-17 17:52:20 +02:00
$ . extend ( $ . expr [ ':' ] , {
blank : function ( el ) {
return $ ( el ) . val ( ) . match ( /^\s*$/ ) ;
}
} ) ;
2019-02-03 19:56:49 +01:00
} ) ;
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 ;
}
2018-03-11 12:07:57 +01:00
function getLinkFromXHRHeader ( xhrheaderstring ) {
2018-03-26 18:26:44 +02:00
const re = xhrheaderstring . match ( /link: <.+api\/v1\/(.+?)>; rel="(.+?)", <.+api\/v1\/(.+?)>; rel="(.+?)"/i ) ;
2018-03-11 12:07:57 +01:00
let di = new Object ( ) ;
if ( re ) {
di [ re [ 2 ] ] = re [ 1 ] ;
di [ re [ 4 ] ] = re [ 3 ] ;
}
return di ;
}
2019-08-21 18:25:27 +02:00
function replaceInternalLink ( ) {
2020-03-29 20:17:40 +02:00
$ ( ".toot_article a,.profile_bio a,.follows_profile_bio a,.announcement_text a" ) . each ( function ( i ) {
2019-01-13 19:02:16 +01:00
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)" ) ;
2019-08-21 18:25:27 +02:00
const ytcom = $ ( this ) . attr ( 'href' ) . match ( /https?:\/\/(www\.)?youtube\.com\/watch\?v=([a-zA-Z\d_-]+)/ ) ;
if ( ytcom ) $ ( this ) . attr ( 'target' , '_self' ) . attr ( 'href' , "javascript:openVideo('" + ytcom [ 2 ] + "');void(0)" ) ;
const ytbe = $ ( this ) . attr ( 'href' ) . match ( /https?:\/\/(www\.)?youtu\.be\/([a-zA-Z\d_-]+)/ ) ;
if ( ytbe ) $ ( this ) . attr ( 'target' , '_self' ) . attr ( 'href' , "javascript:openVideo('" + ytbe [ 2 ] + "');void(0)" ) ;
2019-09-21 17:13:45 +02:00
const twcom = $ ( this ) . attr ( 'href' ) . match ( /https?:\/\/(www\.)?twitter\.com\/(.*)/ ) ;
if ( twcom ) $ ( this ) . attr ( 'target' , '_self' ) . attr ( 'href' , "javascript:openNitter('" + twcom [ 2 ] + "');void(0)" ) ;
2020-02-09 19:26:29 +01:00
const igpost = $ ( this ) . attr ( 'href' ) . match ( /https?:\/\/(www\.)?instagram\.com\/p\/([a-zA-Z\d_-]+)/ ) ;
if ( igpost ) $ ( this ) . attr ( 'target' , '_self' ) . attr ( 'href' , "javascript:openBibliogram('p/" + igpost [ 2 ] + "');void(0)" ) ;
const igacc = $ ( this ) . attr ( 'href' ) . match ( /https?:\/\/(www\.)?instagram\.com\/([a-zA-Z\d_\.]+)/ ) ;
if ( igacc ) $ ( this ) . attr ( 'target' , '_self' ) . attr ( 'href' , "javascript:openBibliogram('u/" + igacc [ 2 ] + "');void(0)" ) ;
const fbcom = $ ( this ) . attr ( 'href' ) . match ( /https?:\/\/(www\.)?facebook\.com\/(.*)/ ) ;
if ( fbcom ) $ ( this ) . attr ( 'target' , '_self' ) . attr ( 'href' , "javascript:openNoFB('" + fbcom [ 2 ] + "');void(0)" ) ;
2019-08-21 18:25:27 +02:00
if ( server _setting _unshorten && checkURLshortener ( $ ( this ) . attr ( 'href' ) ) ) {
var linkrand = Math . round ( Math . random ( ) * 1000000 ) ;
$ ( this ) . attr ( "data-random" , linkrand ) ;
$ . ajax ( "/unshorten.php?url=" + encodeURIComponent ( $ ( this ) . attr ( 'href' ) ) ) . done ( function ( data ) {
$ ( ".toot_article a,.profile_bio a,.follows_profile_bio a" ) . filter ( "[data-random=" + linkrand + "]" ) . attr ( "href" , data ) ;
$ ( ".toot_article a,.profile_bio a,.follows_profile_bio a" ) . filter ( "[data-random=" + linkrand + "]" ) . children ( ) . eq ( 1 ) . text ( data . split ( "//" ) [ 0 ] ) ;
link = data . replace ( "https://" , "" ) ;
link = link . replace ( "http://" , "" ) ;
if ( link . length > 30 ) $ ( ".toot_article a,.profile_bio a,.follows_profile_bio a" ) . filter ( "[data-random=" + linkrand + "]" ) . children ( ) . eq ( 1 ) . addClass ( "ellipsis" ) ;
else $ ( ".toot_article a,.profile_bio a,.follows_profile_bio a" ) . filter ( "[data-random=" + linkrand + "]" ) . children ( ) . eq ( 1 ) . removeClass ( "ellipsis" ) ;
$ ( ".toot_article a,.profile_bio a,.follows_profile_bio a" ) . filter ( "[data-random=" + linkrand + "]" ) . children ( ) . eq ( 1 ) . text ( link . substr ( 0 , 30 ) ) ;
$ ( ".toot_article a,.profile_bio a,.follows_profile_bio a" ) . filter ( "[data-random=" + linkrand + "]" ) . children ( ) . eq ( 2 ) . text ( link . substr ( 30 ) ) ;
} ) ;
}
2019-01-13 19:02:16 +01:00
} ) ;
2018-03-11 12:07:57 +01:00
}
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 ) ;
}
2018-11-25 19:14:16 +01:00
function getRelativeDatetime ( current _time , posted _time , withdot = true , future = false ) {
2018-08-04 15:52:34 +02:00
const calendar = [ _ _ ( "Jan" ) , _ _ ( "Feb" ) , _ _ ( "Mar" ) , _ _ ( "Apr" ) , _ _ ( "May" ) , _ _ ( "Jun" ) , _ _ ( "Jul" ) , _ _ ( "Aug" ) , _ _ ( "Sep" ) , _ _ ( "Oct" ) , _ _ ( "Nov" ) , _ _ ( "Dec" ) ] ;
2018-03-11 12:07:57 +01:00
var posted _time _original = posted _time ,
2018-11-25 19:14:16 +01:00
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" ;
2018-03-11 12:07:57 +01:00
return datetime ;
}
else if ( elapsedTime < 120 ) {
2018-11-25 19:14:16 +01:00
const datetime = dot + "1m" ;
2018-03-11 12:07:57 +01:00
return datetime ;
}
else if ( elapsedTime < ( 60 * 60 ) ) {
2018-11-25 19:14:16 +01:00
const datetime = dot + ( Math . floor ( elapsedTime / 60 ) < 10 ? " " : "" ) + Math . floor ( elapsedTime / 60 ) + "m" ;
2018-03-11 12:07:57 +01:00
return datetime ;
}
else if ( elapsedTime < ( 120 * 60 ) ) {
2018-11-25 19:14:16 +01:00
const datetime = dot + "1h" ;
2018-03-11 12:07:57 +01:00
return datetime ;
}
else if ( elapsedTime < ( 24 * 60 * 60 ) ) {
2018-11-25 19:14:16 +01:00
const datetime = dot + ( Math . floor ( elapsedTime / 3600 ) < 10 ? " " : "" ) + Math . floor ( elapsedTime / 3600 ) + "h" ;
2018-03-11 12:07:57 +01:00
return datetime ;
}
else {
2018-11-25 19:14:16 +01:00
const datetime = dot + calendar [ posted _time _original . getMonth ( ) ] + " " + posted _time _original . getDate ( ) ;
2018-03-11 12:07:57 +01:00
return datetime ;
}
}
2018-05-06 16:08:50 +02:00
function htmlEscape ( strings , ... values ) {
var handleString = function ( str ) {
return str . replace ( /&/g , '&' )
. replace ( />/g , '>' )
. replace ( /</g , '<' )
. replace ( /"/g , '"' )
. replace ( /'/g , ''' )
. replace ( /`/g , '`' ) ;
} ;
var res = '' ;
for ( var i = 0 , l = strings . length ; i < l ; i += 1 ) {
res += handleString ( strings [ i ] ) ;
if ( i < values . length ) {
res += handleString ( values [ i ] ) ;
}
}
return res ;
}
2018-03-11 12:07:57 +01:00
function resetApp ( ) {
2019-06-20 16:50:42 +02:00
current _id = localStorage . getItem ( "current_id" ) ;
2018-03-11 12:07:57 +01:00
current _instance = localStorage . getItem ( "current_instance" ) ;
authtoken = localStorage . getItem ( "current_authtoken" ) ;
api = new MastodonAPI ( {
instance : 'https://' + current _instance ,
api _user _token : authtoken
} ) ;
2018-06-09 17:29:25 +02:00
api . get ( "accounts/verify_credentials" , function ( AccountObj ) {
2019-01-31 17:53:40 +01:00
AccountObj . display _name = htmlEscape ( AccountObj . display _name ) ;
for ( var i = 0 ; i < AccountObj . emojis . length ; i ++ ) {
AccountObj . display _name = AccountObj . display _name . replace ( new RegExp ( ":" + AccountObj . emojis [ i ] . shortcode + ":" , "g" ) , "<img src='" + AccountObj . emojis [ i ] . url + "' class='emoji'>" ) ;
2019-07-17 17:52:20 +02:00
current _filters = new Array ;
2019-01-31 17:53:40 +01:00
}
2018-06-09 17:29:25 +02:00
localStorage . setItem ( "current_display_name" , AccountObj [ "display_name" ] ) ;
localStorage . setItem ( "current_acct" , AccountObj [ "acct" ] ) ;
localStorage . setItem ( "current_header" , AccountObj [ "header" ] ) ;
localStorage . setItem ( "current_avatar" , AccountObj [ "avatar" ] ) ;
2018-10-14 15:37:55 +02:00
localStorage . setItem ( "current_locked" , AccountObj [ "locked" ] ) ;
2018-06-09 17:29:25 +02:00
localStorage . setItem ( "current_statuses_count" , AccountObj [ "statuses_count" ] ) ;
localStorage . setItem ( "current_following_count" , AccountObj [ "following_count" ] ) ;
localStorage . setItem ( "current_followers_count" , AccountObj [ "followers_count" ] ) ;
2018-05-19 19:52:19 +02:00
localStorage . setItem ( "current_follow_loaded" , "false" ) ;
2018-03-11 12:07:57 +01:00
current _display _name = localStorage . getItem ( "current_display_name" ) ;
current _acct = localStorage . getItem ( "current_acct" ) ;
current _header = localStorage . getItem ( "current_header" ) ;
current _avatar = localStorage . getItem ( "current_avatar" ) ;
2018-10-14 15:37:55 +02:00
current _locked = localStorage . getItem ( "current_locked" ) ;
2018-03-11 12:07:57 +01:00
current _statuses _count = localStorage . getItem ( "current_statuses_count" ) ;
current _following _count = localStorage . getItem ( "current_following_count" ) ;
current _followers _count = localStorage . getItem ( "current_followers_count" ) ;
2018-12-02 15:01:21 +01:00
current _search _history = JSON . parse ( localStorage . getItem ( "current_search_history" ) ) ;
2018-05-19 19:52:19 +02:00
setCurrentProfile ( ) ;
2018-03-11 12:07:57 +01:00
} ) ;
2018-04-01 19:30:47 +02:00
api . get ( "accounts/" + current _id + "/following" , function ( data ) {
2018-10-14 15:37:55 +02:00
var followings = new Array ( ) ;
for ( var i = 0 ; i < data . length ; i ++ ) {
2018-05-19 19:52:19 +02:00
if ( data [ i ] . acct . indexOf ( "@" ) == - 1 ) {
data [ i ] . acct = data [ i ] . acct + "@" + current _instance ;
}
followings . push ( data [ i ] . acct ) ;
2018-04-01 19:30:47 +02:00
}
2018-05-19 19:52:19 +02:00
localStorage . setItem ( "current_following_accts" , JSON . stringify ( followings ) ) ;
current _following _accts = followings ;
2018-04-01 19:30:47 +02:00
} ) ;
2018-10-14 15:37:55 +02:00
api . get ( "blocks" , function ( data ) {
var blocks = new Array ( ) ;
for ( i = 0 ; i < data . length ; i ++ ) {
if ( data [ i ] . acct . indexOf ( "@" ) == - 1 ) {
data [ i ] . acct = data [ i ] . acct + "@" + current _instance ;
}
blocks . push ( data [ i ] . acct ) ;
}
localStorage . setItem ( "current_blocked_accts" , JSON . stringify ( blocks ) ) ;
current _blocked _accts = blocks ;
} ) ;
api . get ( "mutes" , function ( data ) {
var mutes = new Array ( ) ;
for ( i = 0 ; i < data . length ; i ++ ) {
if ( data [ i ] . acct . indexOf ( "@" ) == - 1 ) {
data [ i ] . acct = data [ i ] . acct + "@" + current _instance ;
}
mutes . push ( data [ i ] . acct ) ;
}
localStorage . setItem ( "current_muted_accts" , JSON . stringify ( mutes ) ) ;
current _muted _accts = mutes ;
} ) ;
2018-04-01 19:30:47 +02:00
api . get ( "instance" , function ( data ) {
2019-07-17 17:52:20 +02:00
if ( ! data . max _toot _chars ) data . max _toot _chars = 500 ;
if ( ! data . poll _limits ) {
data . poll _limits = new Object ( ) ;
2020-07-22 18:11:54 +02:00
data . poll _limits . max _options = 4 ;
data . poll _limits . max _option _chars = 25 ;
data . poll _limits . min _expiration = 300 ;
data . poll _limits . max _expiration = 2629746 ;
2019-07-17 17:52:20 +02:00
}
2018-04-01 19:30:47 +02:00
localStorage . setItem ( "current_instance_charlimit" , data . max _toot _chars ) ;
current _instance _charlimit = data . max _toot _chars ;
2019-07-17 17:52:20 +02:00
localStorage . setItem ( "current_instance_poll_limits" , JSON . stringify ( data . poll _limits ) ) ;
current _instance _poll _limits = data . poll _limits ;
2018-04-01 19:30:47 +02:00
} ) ;
2018-07-01 17:07:18 +02:00
api . get ( "custom_emojis" , function ( data ) {
var emojis = new Array ( ) ;
for ( i = 0 ; i < data . length ; i ++ ) {
var emoji = new Object ( ) ;
emoji . code = data [ i ] . shortcode ;
emoji . url = data [ i ] . url ;
2019-10-13 18:34:02 +02:00
if ( data [ i ] . category ) emoji . category = data [ i ] . category ;
2018-07-01 17:07:18 +02:00
emojis . push ( emoji ) ;
}
localStorage . setItem ( "current_custom_emojis" , JSON . stringify ( emojis ) ) ;
2019-02-25 18:18:21 +01:00
$ ( document ) . trigger ( "emojiready" ) ;
2018-07-01 17:07:18 +02:00
} ) ;
2018-11-25 19:14:16 +01:00
api . get ( "filters" , function ( data ) {
localStorage . setItem ( "current_filters" , JSON . stringify ( data ) ) ;
current _filters = data ;
} ) ;
2018-04-01 19:30:47 +02:00
$ . cookie ( "session" , "true" , { path : '/' } ) ;
2018-03-11 12:07:57 +01:00
}
function refreshApp ( ) {
2019-06-20 16:50:42 +02:00
current _id = localStorage . getItem ( "current_id" ) ;
2018-03-11 12:07:57 +01:00
current _instance = localStorage . getItem ( "current_instance" ) ;
authtoken = localStorage . getItem ( "current_authtoken" ) ;
api = new MastodonAPI ( {
instance : "https://" + current _instance ,
api _user _token : authtoken
} ) ;
current _display _name = localStorage . getItem ( "current_display_name" ) ;
current _acct = localStorage . getItem ( "current_acct" ) ;
current _header = localStorage . getItem ( "current_header" ) ;
current _avatar = localStorage . getItem ( "current_avatar" ) ;
2018-10-14 15:37:55 +02:00
current _locked = localStorage . getItem ( "current_locked" ) ;
2018-03-11 12:07:57 +01:00
current _statuses _count = localStorage . getItem ( "current_statuses_count" ) ;
2018-04-01 19:30:47 +02:00
current _following _count = localStorage . getItem ( "current_following_count" ) ;
current _followers _count = localStorage . getItem ( "current_followers_count" ) ;
2018-05-19 19:52:19 +02:00
current _following _accts = localStorage . getItem ( "current_following_accts" ) ;
2018-04-01 19:30:47 +02:00
current _instance _charlimit = localStorage . getItem ( "current_instance_charlimit" ) ;
2019-07-17 17:52:20 +02:00
current _instance _poll _limits = JSON . parse ( localStorage . getItem ( "current_instance_poll_limits" ) ) ;
2018-10-14 15:37:55 +02:00
current _blocked _accts = localStorage . getItem ( "current_blocked_accts" ) ;
current _muted _accts = localStorage . getItem ( "current_muted_accts" ) ;
2018-11-25 19:14:16 +01:00
current _filters = JSON . parse ( localStorage . getItem ( "current_filters" ) ) ;
2018-12-02 15:01:21 +01:00
current _search _history = JSON . parse ( localStorage . getItem ( "current_search_history" ) ) ;
2019-02-25 18:18:21 +01:00
$ ( document ) . trigger ( "emojiready" ) ;
2018-05-19 19:52:19 +02:00
$ ( function ( ) { setCurrentProfile ( ) } ) ;
2018-03-11 12:07:57 +01:00
}
function setCurrentProfile ( ) {
2018-10-14 15:37:55 +02:00
var is _account _locked = "" ;
if ( current _locked == "true" ) {
is _account _locked = " <i class='fa fa-lock'></i>" ;
}
2019-01-31 17:53:40 +01:00
$ ( ".js_current_profile_displayname" ) . html ( current _display _name ) ;
2018-10-14 15:37:55 +02:00
$ ( ".js_current_profile_username" ) . html ( current _acct + is _account _locked ) ;
2019-08-21 18:25:27 +02:00
$ ( ".js_current_profile_link" ) . attr ( "href" , "/@" + current _acct + "@" + current _instance + "?mid=" + current _id ) ;
2018-03-11 12:07:57 +01:00
$ ( ".js_current_header_image" ) . attr ( "src" , current _header ) ;
$ ( ".js_current_profile_image" ) . attr ( "src" , current _avatar ) ;
$ ( ".js_current_toots_count" ) . text ( current _statuses _count ) ;
$ ( ".js_current_following_count" ) . text ( current _following _count ) ;
$ ( ".js_current_followers_count" ) . text ( current _followers _count ) ;
2019-08-21 18:25:27 +02:00
$ ( ".current_toots_count_link" ) . attr ( "href" , "/@" + current _acct + "@" + current _instance + "?mid=" + current _id ) ;
$ ( ".current_following_count_link" ) . attr ( "href" , "/@" + current _acct + "@" + current _instance + "/following?mid=" + current _id ) ;
$ ( ".current_followers_count_link" ) . attr ( "href" , "/@" + current _acct + "@" + current _instance + "/followers?mid=" + current _id ) ;
2018-09-03 17:04:14 +02:00
if ( $ ( window ) . width ( ) < 1200 ) {
responsive _design = true ;
$ ( ".left_column" ) . append ( $ ( "<div>" ) . attr ( "class" , "responsive_left" ) . append ( $ ( ".right_column" ) . children ( ) ) ) ;
$ ( ".right_column" ) . remove ( ) ;
}
else {
responsive _design = false ;
}
2018-05-01 18:51:00 +02:00
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" ) ;
}
2018-05-19 19:52:19 +02:00
if ( localStorage . setting _who _to _follow == "true" ) {
setWhoToFollow ( ) ;
}
2019-08-21 18:25:27 +02:00
setTrendingHashtags ( ) ;
2019-07-17 17:52:20 +02:00
if ( ! localStorage . hide _firefox _download || localStorage . hide _firefox _download != "true" ) $ ( "#widget_ffdl" ) . show ( ) ;
2018-03-11 12:07:57 +01:00
replace _emoji ( ) ;
}
function putMessage ( Message ) {
$ ( '#overlay_message' ) . addClass ( 'view' ) ;
$ ( '#overlay_message section span' ) . text ( Message ) ;
setTimeout ( function ( ) {
$ ( "#overlay_message" ) . removeClass ( "view" ) ;
} , 3000 ) ;
2018-03-26 18:26:44 +02:00
} ;
2018-05-01 18:51:00 +02:00
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'
} ) ;
}
}
}
2018-05-06 16:08:50 +02:00
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 ( ) ;
}
2018-05-19 19:52:19 +02:00
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 ( ) ;
2018-07-01 17:07:18 +02:00
replace _emoji ( ) ;
2018-05-19 19:52:19 +02:00
}
} , 100 ) ;
}
else {
$ ( "#follow_icon" ) . removeClass ( "fa-circle-o-notch" ) . removeClass ( "fa-spin" ) . addClass ( "fa-id-card-o" ) . addClass ( "fa-stack-1x" ) . after ( $ ( "<i>" ) . 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 < data . ids . length ; i ++ ) {
2018-10-14 15:37:55 +02:00
if ( current _following _accts . indexOf ( data . ids [ i ] . to _id ) == - 1 && current _blocked _accts . indexOf ( data . ids [ i ] . to _id ) == - 1 && current _muted _accts . indexOf ( data . ids [ i ] . to _id ) == - 1 ) {
2018-05-19 19:52:19 +02:00
wtflist . push ( data . ids [ i ] . to _id ) ;
}
}
localStorage . who _to _follow = JSON . stringify ( wtflist ) ;
}
setWhoToFollow ( ) ;
} ) . fail ( function ( xhr ) {
if ( xhr . readyState == 0 ) {
setWhoToFollow ( ) ;
}
} ) ;
}
}
function addFollowProfile ( id , account ) {
2019-12-23 14:58:06 +01:00
api . search ( 'q=' + encodeURIComponent ( "@" + account ) + "&limit=1&resolve=true" , function ( search ) {
2018-07-13 19:37:22 +02:00
search . accounts [ 0 ] . display _name = htmlEscape ( search . accounts [ 0 ] . display _name ) ;
for ( i = 0 ; i < search . accounts [ 0 ] . emojis . length ; i ++ ) {
search . accounts [ 0 ] . display _name = search . accounts [ 0 ] . display _name . replace ( new RegExp ( ":" + search . accounts [ 0 ] . emojis [ i ] . shortcode + ":" , "g" ) , "<img src='" + search . accounts [ 0 ] . emojis [ i ] . url + "' class='emoji'>" ) ;
}
2018-05-19 19:52:19 +02:00
if ( search . accounts [ 0 ] . display _name . length == 0 ) {
search . accounts [ 0 ] . display _name = search . accounts [ 0 ] . username ;
}
2019-01-31 17:53:40 +01:00
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 ;
2018-05-19 19:52:19 +02:00
$ ( '.what_to_follow_' + id + ' > .icon_box img' ) . attr ( 'src' , search . accounts [ 0 ] . avatar ) ;
2019-01-31 17:53:40 +01:00
$ ( '.what_to_follow_' + id + ' .label_box > a' ) . attr ( 'href' , wtf _account _link ) ;
2018-07-13 19:37:22 +02:00
$ ( '.what_to_follow_' + id + ' .label_box > a > h3 .dn' ) . addClass ( "emoji_poss" ) . html ( search . accounts [ 0 ] . display _name ) ;
2018-05-19 19:52:19 +02:00
$ ( '.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 ++ ;
} ) ;
}
2019-08-21 18:25:27 +02:00
function setTrendingHashtags ( ) {
api . get ( "trends" , function ( data ) {
if ( data . length == 0 ) $ ( "#trends_icon" ) . removeClass ( "fa-circle-o-notch" ) . removeClass ( "fa-spin" ) . addClass ( "fa-hashtag" ) . addClass ( "fa-stack-1x" ) . after ( $ ( "<i>" ) . addClass ( "fa" ) . addClass ( "fa-ban" ) . addClass ( "fa-stack-2x" ) ) ;
else {
for ( var i = 0 ; i < 5 ; i ++ ) {
if ( i < data . length ) {
var ht _toots = 0 ;
var ht _users = 0 ;
for ( var a = 0 ; a < data [ i ] . history . length ; a ++ ) {
ht _toots += parseInt ( data [ i ] . history [ a ] . uses ) ;
ht _users += parseInt ( data [ i ] . history [ a ] . accounts ) ;
}
$ ( ".trending_hashtags .trending_" + i + " a" ) . attr ( "href" , "/search?q=" + data [ i ] . name ) ;
$ ( ".trending_hashtags .trending_" + i + " .dn" ) . text ( "#" + data [ i ] . name ) ;
$ ( ".trending_hashtags .trending_" + i + " .un" ) . text ( ht _toots + " " + _ _ ( "toots by" ) + " " + ht _users + " " + _ _ ( "users" ) ) ;
}
else {
$ ( ".trending_hashtags .trending_" + i ) . remove ( ) ;
}
}
$ ( ".trends_loading" ) . hide ( ) ;
$ ( ".trending_hashtags" ) . show ( ) ;
}
} , function ( ) {
$ ( "#trends_icon" ) . removeClass ( "fa-circle-o-notch" ) . removeClass ( "fa-spin" ) . addClass ( "fa-hashtag" ) . addClass ( "fa-stack-1x" ) . after ( $ ( "<i>" ) . addClass ( "fa" ) . addClass ( "fa-ban" ) . addClass ( "fa-stack-2x" ) ) ;
} ) ;
}
2018-07-01 17:07:18 +02:00
function checkEmojiSupport ( ) {
var ctx = document . createElement ( "canvas" ) . getContext ( "2d" ) ;
2018-07-25 17:31:54 +02:00
ctx . fillText ( "😗" , - 2 , 4 ) ;
2018-07-01 17:07:18 +02:00
return ctx . getImageData ( 0 , 0 , 1 , 1 ) . data [ 3 ] > 0 ;
2018-08-04 15:52:34 +02:00
}
2018-09-03 17:04:14 +02:00
function openStatus ( link ) {
2020-07-22 18:11:54 +02:00
api . search ( "q=" + encodeURIComponent ( link ) + "&resolve=true" , function ( response ) {
2018-09-03 17:04:14 +02:00
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" ;
}
} ) ;
}
2019-08-21 18:25:27 +02:00
function openVideo ( video ) {
if ( localStorage . setting _redirect _invidious == "true" ) window . open ( "https://" + server _setting _invidious + "/watch?v=" + video , "_blank" ) ;
else if ( localStorage . setting _redirect _invidious == "false" ) window . open ( "https://www.youtube.com/watch?v=" + video , "_blank" ) ;
else {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_redirect_invidious' ) . data ( "video" , video ) ;
$ ( '.overlay_redirect_invidious' ) . removeClass ( 'invisible' ) ;
}
}
2019-09-21 17:13:45 +02:00
function openNitter ( path ) {
if ( localStorage . setting _redirect _nitter == "true" ) window . open ( "https://" + server _setting _nitter + "/" + path , "_blank" ) ;
else if ( localStorage . setting _redirect _nitter == "false" ) window . open ( "https://twitter.com/" + path , "_blank" ) ;
else {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_redirect_nitter' ) . data ( "path" , path ) ;
$ ( '.overlay_redirect_nitter' ) . removeClass ( 'invisible' ) ;
}
}
2020-02-09 19:26:29 +01:00
function openBibliogram ( path ) {
if ( localStorage . setting _redirect _bibliogram == "true" ) window . open ( "https://" + server _setting _bibliogram + "/" + path , "_blank" ) ;
else if ( localStorage . setting _redirect _bibliogram == "false" ) window . open ( "https://www.instagram.com/" + path , "_blank" ) ;
else {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_redirect_bibliogram' ) . data ( "path" , path ) ;
$ ( '.overlay_redirect_bibliogram' ) . removeClass ( 'invisible' ) ;
}
}
function openNoFB ( path ) {
if ( localStorage . setting _redirect _nofb == "true" ) window . open ( "https://nofb.pw/?p=" + encodeURIComponent ( "https://www.facebook.com/" + path ) , "_blank" ) ;
else if ( localStorage . setting _redirect _nofb == "false" ) window . open ( "https://www.facebook.com/" + path , "_blank" ) ;
else {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_redirect_nofb' ) . data ( "path" , path ) ;
$ ( '.overlay_redirect_nofb' ) . removeClass ( 'invisible' ) ;
}
}
2019-08-30 16:58:17 +02:00
function checkStatusLinks ( text ) {
2019-09-07 15:35:12 +02:00
$ ( "<span>" + text + "</span>" ) . find ( "a" ) . each ( function ( i ) {
2019-08-30 16:58:17 +02:00
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 ) text += embedMedia ( "youtube" , ytcom [ 2 ] ) ;
else if ( htcom ) text += embedMedia ( "youtube" , htcom [ 2 ] ) ;
else if ( ivcom ) text += embedMedia ( "youtube" , ivcom [ 2 ] ) ;
else if ( ytbe ) text += embedMedia ( "youtube" , ytbe [ 2 ] ) ;
else if ( htbe ) text += embedMedia ( "youtube" , htbe [ 2 ] ) ;
else if ( vimeo ) text += embedMedia ( "vimeo" , vimeo [ 2 ] ) ;
else if ( peertube ) text += embedMedia ( "peertube" , peertube [ 0 ] . replace ( "/watch/" , "/embed/" ) ) ;
} ) ;
return text ;
}
function embedMedia ( source , watchid ) {
let media _views = ` <div class='media_views' media_length='1' style="border:0;border-radius:0"> ` ;
2019-01-13 19:02:16 +01:00
if ( source == "youtube" && server _setting _youplay == true && localStorage . setting _play _youplay == "true" ) {
media _views += ( `
< div class = "media_attachment" otype = "video/gifv" mediacount = "0" >
< iframe src = "/media/youplay.php?id=${watchid}" frameborder = "0" allowfullscreen > < / i f r a m e >
< / d i v > ` ) ;
}
2019-08-30 16:58:17 +02:00
else if ( source == "youtube" && localStorage . setting _play _invidious == "true" ) {
2019-01-13 19:02:16 +01:00
media _views += ( `
< div class = "media_attachment" otype = "video/gifv" mediacount = "0" >
2020-02-09 19:26:29 +01:00
< iframe src = "/media/invidious.php?server=${server_setting_invidious}&id=${watchid}" frameborder = "0" allowfullscreen > < / i f r a m e >
2019-01-13 19:02:16 +01:00
< / d i v > ` ) ;
}
else if ( source == "vimeo" && server _setting _vimeo == true && localStorage . setting _play _vimeo == "true" ) {
media _views += ( `
< div class = "media_attachment" otype = "video/gifv" mediacount = "0" >
< iframe src = "/media/vimeo.php?id=${watchid}" frameborder = "0" allowfullscreen > < / i f r a m e >
< / d i v > ` ) ;
}
else if ( source == "peertube" && localStorage . setting _play _peertube == "true" ) {
media _views += ( `
< div class = "media_attachment" otype = "video/gifv" mediacount = "0" >
< iframe src = "${watchid}" frameborder = "0" allowfullscreen > < / i f r a m e >
< / d i v > ` ) ;
}
media _views += "</div>" ;
2019-08-30 16:58:17 +02:00
if ( $ ( media _views ) . children ( ) . length != 0 ) return media _views ;
else return "" ;
2019-01-13 19:02:16 +01:00
}
2019-05-07 19:19:29 +02:00
function enableAutoComplete ( textarea ) {
if ( localStorage . setting _compose _autocomplete == "true" ) {
textarea . autoCompleteToken ( { instance : 1 , startkey : "@" , endkey : " " , arrayname : "accounts" , resultname : "acct" } ) ;
2019-12-23 14:58:06 +01:00
textarea . autoCompleteToken ( { instance : 2 , startkey : "#" , endkey : " " , arrayname : "hashtags" , resultname : "name" } ) ;
2019-05-07 19:19:29 +02:00
textarea . autoCompleteToken ( { instance : 3 , startkey : ":" , endkey : ";" , source : actEmojiData , resultname : "name" , callback : function ( ) {
textarea . trigger ( { "type" : "keyup" , "key" : ":" } ) ;
} } ) ;
}
}
2020-02-09 19:26:29 +01:00
function submitStatusArray ( params , callback , invidious = "unset" , nitter = "unset" , bibliogram = "unset" , nofb = "unset" ) {
2019-10-13 18:34:02 +02:00
const ytcom = params . status . first ( ) . val ( ) . match ( /https?:\/\/(www\.)?youtube\.com\/watch\?v=([a-zA-Z\d_-]+)/ ) ;
const ytbe = params . status . first ( ) . val ( ) . match ( /https?:\/\/(www\.)?youtu\.be\/([a-zA-Z\d_-]+)/ ) ;
const twcom = params . status . first ( ) . val ( ) . match ( /https?:\/\/(www\.)?twitter\.com\/(.*)/ ) ;
2020-02-09 19:26:29 +01:00
const igpost = params . status . first ( ) . val ( ) . match ( /https?:\/\/(www\.)?instagram\.com\/p\/([a-zA-Z\d_-]+)/ ) ;
const igacc = params . status . first ( ) . val ( ) . match ( /https?:\/\/(www\.)?instagram\.com\/([a-zA-Z\d_\.]+)/ ) ;
const fbcom = params . status . first ( ) . val ( ) . match ( /https?:\/\/(www\.)?facebook\.com\/(.*)/ ) ;
2019-10-13 18:34:02 +02:00
if ( ( ytcom || ytbe ) && localStorage . setting _rewrite _invidious == "unset" && invidious == "unset" ) {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_rewrite_invidious' ) . data ( "params" , params ) ;
$ ( '.overlay_rewrite_invidious' ) . data ( "callback" , callback ) ;
$ ( '.overlay_rewrite_invidious' ) . data ( "nitter" , nitter ) ;
2020-02-09 19:26:29 +01:00
$ ( '.overlay_rewrite_invidious' ) . data ( "bibliogram" , bibliogram ) ;
$ ( '.overlay_rewrite_invidious' ) . data ( "nofb" , nofb ) ;
2019-10-13 18:34:02 +02:00
$ ( '.overlay_rewrite_invidious' ) . removeClass ( 'invisible' ) ;
}
else if ( twcom && localStorage . setting _rewrite _nitter == "unset" && nitter == "unset" ) {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_rewrite_nitter' ) . data ( "params" , params ) ;
$ ( '.overlay_rewrite_nitter' ) . data ( "callback" , callback ) ;
$ ( '.overlay_rewrite_nitter' ) . data ( "invidious" , invidious ) ;
2020-02-09 19:26:29 +01:00
$ ( '.overlay_rewrite_nitter' ) . data ( "bibliogram" , bibliogram ) ;
$ ( '.overlay_rewrite_nitter' ) . data ( "nofb" , nofb ) ;
2019-10-13 18:34:02 +02:00
$ ( '.overlay_rewrite_nitter' ) . removeClass ( 'invisible' ) ;
}
2020-02-09 19:26:29 +01:00
else if ( ( igpost || igacc ) && localStorage . setting _rewrite _bibliogram == "unset" && bibliogram == "unset" ) {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_rewrite_bibliogram' ) . data ( "params" , params ) ;
$ ( '.overlay_rewrite_bibliogram' ) . data ( "callback" , callback ) ;
$ ( '.overlay_rewrite_bibliogram' ) . data ( "invidious" , invidious ) ;
$ ( '.overlay_rewrite_bibliogram' ) . data ( "nitter" , nitter ) ;
$ ( '.overlay_rewrite_bibliogram' ) . data ( "nofb" , nofb ) ;
$ ( '.overlay_rewrite_bibliogram' ) . removeClass ( 'invisible' ) ;
}
else if ( fbcom && localStorage . setting _rewrite _nofb == "unset" && nofb == "unset" ) {
$ ( "#js-overlay_content_wrap .temporary_object" ) . empty ( ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'view' ) ;
$ ( '#js-overlay_content_wrap' ) . addClass ( 'black_08' ) ;
$ ( '.overlay_rewrite_nofb' ) . data ( "params" , params ) ;
$ ( '.overlay_rewrite_nofb' ) . data ( "callback" , callback ) ;
$ ( '.overlay_rewrite_nofb' ) . data ( "invidious" , invidious ) ;
$ ( '.overlay_rewrite_nofb' ) . data ( "nitter" , nitter ) ;
$ ( '.overlay_rewrite_nofb' ) . data ( "bibliogram" , bibliogram ) ;
$ ( '.overlay_rewrite_nofb' ) . removeClass ( 'invisible' ) ;
}
2019-10-13 18:34:02 +02:00
if ( ytcom && ( localStorage . setting _rewrite _invidious == "true" || invidious == "true" ) ) {
params . status . first ( ) . val ( params . status . first ( ) . val ( ) . replace ( /https?:\/\/(www\.)?youtube\.com\/watch\?v=([a-zA-Z\d_-]+)/ , "https://" + server _setting _invidious + "/watch?v=$2" ) ) ;
2020-02-09 19:26:29 +01:00
submitStatusArray ( params , callback , invidious , nitter , bibliogram , nofb ) ;
2019-10-13 18:34:02 +02:00
}
else if ( ytbe && ( localStorage . setting _rewrite _invidious == "true" || invidious == "true" ) ) {
params . status . first ( ) . val ( params . status . first ( ) . val ( ) . replace ( /https?:\/\/(www\.)?youtu\.be\/([a-zA-Z\d_-]+)/ , "https://" + server _setting _invidious + "/watch?v=$2" ) ) ;
2020-02-09 19:26:29 +01:00
submitStatusArray ( params , callback , invidious , nitter , bibliogram , nofb ) ;
2019-10-13 18:34:02 +02:00
}
else if ( twcom && ( localStorage . setting _rewrite _nitter == "true" || nitter == "true" ) ) {
params . status . first ( ) . val ( params . status . first ( ) . val ( ) . replace ( /https?:\/\/(www\.)?twitter\.com\/(.*)/ , "https://" + server _setting _nitter + "/$2" ) ) ;
2020-02-09 19:26:29 +01:00
submitStatusArray ( params , callback , invidious , nitter , bibliogram , nofb ) ;
}
else if ( igpost && ( localStorage . setting _rewrite _bibliogram == "true" || bibliogram == "true" ) ) {
params . status . first ( ) . val ( params . status . first ( ) . val ( ) . replace ( /https?:\/\/(www\.)?instagram\.com\/p\/([a-zA-Z\d_-]+)/ , "https://" + server _setting _bibliogram + "/p/$2" ) ) ;
submitStatusArray ( params , callback , invidious , nitter , bibliogram , nofb ) ;
}
else if ( igacc && ( localStorage . setting _rewrite _bibliogram == "true" || bibliogram == "true" ) ) {
params . status . first ( ) . val ( params . status . first ( ) . val ( ) . replace ( /https?:\/\/(www\.)?instagram\.com\/([a-zA-Z\d_\.]+)/ , "https://" + server _setting _bibliogram + "/u/$2" ) ) ;
submitStatusArray ( params , callback , invidious , nitter , bibliogram , nofb ) ;
}
else if ( fbcom && ( localStorage . setting _rewrite _nofb == "true" || nofb == "true" ) ) {
params . status . first ( ) . val ( params . status . first ( ) . val ( ) . replace ( /https?:\/\/(www\.)?facebook\.com\/(.*)/ , "https://nofb.pw/?p=https%3A%2F%2Fwww.facebook.com%2F$2" ) ) ;
submitStatusArray ( params , callback , invidious , nitter , bibliogram , nofb ) ;
2019-10-13 18:34:02 +02:00
}
2020-02-09 19:26:29 +01:00
else if ( ( ( ! ytcom && ! ytbe ) || localStorage . setting _rewrite _invidious == "false" || invidious == "false" ) && ( ! twcom || localStorage . setting _rewrite _nitter == "false" || nitter == "false" ) && ( ( ! igpost && ! igacc ) || localStorage . setting _rewrite _bibliogram == "false" || bibliogram == "false" ) && ( ! fbcom || localStorage . setting _rewrite _nofb == "false" || nofb == "false" ) ) submitStatusArrayNow ( params , callback , invidious , nitter , bibliogram , nofb ) ;
2019-10-13 18:34:02 +02:00
}
2020-02-09 19:26:29 +01:00
function submitStatusArrayNow ( params , callback , invidious , nitter , bibliogram , nofb ) {
2019-05-07 19:19:29 +02:00
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 ;
2020-02-09 19:26:29 +01:00
submitStatusArray ( nparams , callback , invidious , nitter , bibliogram , nofb ) ;
2019-05-07 19:19:29 +02:00
}
} ) ;
}
2019-08-21 18:25:27 +02:00
function checkURLshortener ( link ) {
var short = true ;
if ( link . indexOf ( "https://" ) != - 1 || link . indexOf ( "http://" ) != - 1 ) {
if ( link . indexOf ( "://www." ) != - 1 ) short = false ;
link = link . replace ( "https://" , "" ) ;
link = link . replace ( "http://" , "" ) ;
var short _handle = link . split ( "/" ) ;
var domain = link . split ( "." ) ;
if ( domain . length == 2 ) var sld = domain [ 0 ] ;
else var sld = domain [ 1 ] ;
if ( sld . length < 1 || sld . length > 7 ) short = false ;
if ( short _handle . length != 2 ) short = false ;
else if ( ! short _handle [ 1 ] . match ( /^[a-zA-Z0-9_-]+$/ ) ) short = false ;
else if ( short _handle [ 1 ] . length > 10 ) short = false ;
}
else short = false ;
return short ;
}
2019-08-30 16:58:17 +02:00
function prepareStatus ( status ) {
if ( status . reblog === null ) {
status . halcyon = new Object ( ) ;
for ( i = 0 ; i < status . emojis . length ; i ++ ) {
status . content = status . content . replace ( new RegExp ( ":" + status . emojis [ i ] . shortcode + ":" , "g" ) , "<img src='" + status . emojis [ i ] . url + "' class='emoji'>" ) ;
}
status . account . display _name = htmlEscape ( status . account . display _name ) ;
for ( var i = 0 ; i < status . account . emojis . length ; i ++ ) {
status . account . display _name = status . account . display _name . replace ( new RegExp ( ":" + status . account . emojis [ i ] . shortcode + ":" , "g" ) , "<img src='" + status . account . emojis [ i ] . url + "' class='emoji'>" ) ;
}
for ( var i = 0 ; i < status . mentions . length ; i ++ ) {
if ( status . mentions [ i ] . acct . indexOf ( "@" ) == - 1 ) status . content = status . content . replace ( new RegExp ( 'href="' + status . mentions [ i ] . url + '"' , "g" ) , 'href="/@' + status . mentions [ i ] . acct + '@' + current _instance + '?mid=' + status . mentions [ i ] . id + '" data-mid="' + status . mentions [ i ] . id + '"' ) ;
else status . content = status . content . replace ( new RegExp ( 'href="' + status . mentions [ i ] . url + '"' , "g" ) , 'href="/@' + status . mentions [ i ] . acct + '?mid=' + status . mentions [ i ] . id + '" data-mid="' + status . mentions [ i ] . id + '"' ) ;
}
if ( ! status . mentions . find ( function ( account ) {
return account . id == this ;
} , status . account . id ) ) {
var writtenby = new Object ( ) ;
writtenby . id = status . account . id ;
writtenby . username = status . account . username ;
writtenby . url = status . account . url ;
writtenby . acct = status . account . acct ;
status . mentions . push ( writtenby ) ;
}
if ( status . account . acct . indexOf ( "@" ) == - 1 ) status . halcyon . account _link = "/@" + status . account . acct + "@" + current _instance + "?mid=" + status . account . id ;
else status . halcyon . account _link = "/@" + status . account . acct + "?mid=" + status . account . id ;
status . halcyon . datetime = getRelativeDatetime ( Date . now ( ) , getConversionedDate ( null , status . created _at ) ) ;
status . halcyon . attr _datetime = getConversionedDate ( null , status . created _at ) ;
status . halcyon . alert _text = "" ;
status . halcyon . article _option = "" ;
status . halcyon . media _views = "" ;
status . halcyon . poll _object = "" ;
status . halcyon . preview _object = "" ;
if ( status . spoiler _text && localStorage . setting _show _content _warning == "false" ) {
status . halcyon . alert _text = "<span>" + status . spoiler _text + "</span><button class='cw_button'>" + _ _ ( 'SHOW MORE' ) + "</button>" ,
2019-10-13 18:34:02 +02:00
status . halcyon . article _option = "content_warning" ;
2019-08-30 16:58:17 +02:00
}
else if ( status . spoiler _text && localStorage . setting _show _content _warning == "true" )
status . halcyon . alert _text = "<span>" + status . spoiler _text + "</span><button class='cw_button'>" + _ _ ( 'SHOW LESS' ) + "</button>" ;
if ( ! status . replies _count ) status . replies _count = "" ;
if ( ! status . reblogs _count ) status . reblogs _count = "" ;
if ( ! status . favourites _count ) status . favourites _count = "" ;
if ( status . media _attachments . length ) status . halcyon . media _views = mediaattachments _template ( status ) ;
if ( status . poll ) status . halcyon . poll _object = poll _template ( status . poll ) ;
if ( status . card ) status . halcyon . preview _object = link _preview _template ( status . card ) ;
if ( status . account . display _name . length == 0 ) status . account . display _name = status . account . username ;
status . halcyon . checked _public = "" ;
status . halcyon . checked _unlisted = "" ;
status . halcyon . checked _private = "" ;
status . halcyon . checked _direct = "" ;
switch ( status . visibility ) {
case "public" : status . halcyon . privacy _mode = _ _ ( "Public" ) ; status . halcyon . privacy _icon = "globe" ; status . halcyon . checked _public = " checked" ; break ;
case "unlisted" : status . halcyon . privacy _mode = _ _ ( "Unlisted" ) ; status . halcyon . privacy _icon = "unlock-alt" ; status . halcyon . checked _unlisted = " checked" ; break ;
case "private" : status . halcyon . privacy _mode = _ _ ( "Followers-only" ) ; status . halcyon . privacy _icon = "lock" ; status . halcyon . checked _private = " checked" ; break ;
case "direct" : status . halcyon . privacy _mode = _ _ ( "Direct" ) ; status . halcyon . privacy _icon = "envelope" ; status . halcyon . checked _direct = " checked" ; break ;
}
if ( status . halcyon . privacy _icon == "globe" || status . halcyon . privacy _icon == "unlock-alt" ) {
2020-03-29 20:17:40 +02:00
status . halcyon . footer _width = " style='width:400px'" ;
2019-08-30 16:58:17 +02:00
status . halcyon . reblog _button = ( ` <div class="toot_reaction">
< button class = "boost_button" tid = "${status.id}" reblogged = "${status.reblogged}" >
< i class = "fa fa-fw fa-retweet" > < / i >
< span class = "reaction_count boost_count" > $ { status . reblogs _count } < / s p a n >
< / b u t t o n >
< / d i v > ` ) ;
}
else {
status . halcyon . footer _width = "" ;
status . halcyon . reblog _button = "" ;
}
if ( status . account . acct == current _acct ) {
status . halcyon . own _toot _buttons = ( ` <li><a class="delete_button" tid=" ${ status . id } "> ${ _ _ ( 'Delete Toot' ) } </a></li> ` ) ;
if ( status . pinned == true ) status . halcyon . own _toot _buttons += ( ` <li><a class="unpin_button" tid=" ${ status . id } "> ${ _ _ ( 'Unpin Toot' ) } </a></li> ` ) ;
else status . halcyon . own _toot _buttons += ( ` <li><a class="pin_button" tid=" ${ status . id } "> ${ _ _ ( 'Pin Toot' ) } </a></li> ` ) ;
}
else {
status . halcyon . own _toot _buttons = ( ` <li><a class="mute_button" mid=" ${ status . account . id } " sid=" ${ status . id } "> ${ _ _ ( 'Mute' ) } @ ${ status . account . username } </a></li>
< li > < a class = "block_button" mid = "${status.account.id}" sid = "${status.id}" > $ { _ _ ( 'Block' ) } @ $ { status . account . username } < / a > < / l i >
< li > < a class = "addlist_button" mid = "${status.account.id}" sid = "${status.id}" display _name = "${status.account.display_name}" > $ { _ _ ( 'Add to list' ) } @ $ { status . account . username } < / a > < / l i >
< li > < a class = "report_button" mid = "${status.account.id}" sid = "${status.id}" display _name = "${status.account.display_name}" > $ { _ _ ( 'Report this Toot' ) } < / a > < / l i > ` ) ;
2019-10-13 18:34:02 +02:00
if ( localStorage . setting _show _admin && localStorage . setting _show _admin == "true" ) {
status . halcyon . own _toot _buttons += ( ` </ul><ul><li><a href="https:// ${ current _instance } /admin/accounts/ ${ status . account . id } " target="_blank" class="admin_user_button"> ${ _ _ ( 'Open user as admin' ) } </a></li>
< li > < a href = "https://${current_instance}/admin/accounts/${status.account.id}/statuses/${status.id}" target = "_blank" class = "admin_post_button" > $ { _ _ ( 'Open post as admin' ) } < / a > < / l i > ` ) ;
}
2019-08-30 16:58:17 +02:00
}
status . halcyon . account _state _icons = "" ;
if ( status . account . locked == true ) status . halcyon . account _state _icons += " <i class='fa fa-lock'></i>" ;
if ( status . account . bot == true ) status . halcyon . account _state _icons += " <img src='/assets/images/robot.svg' class='emoji'>" ;
2020-03-29 20:17:40 +02:00
status . halcyon . reactions = "" ;
if ( status . pleroma && status . pleroma . emoji _reactions ) status . halcyon . reactions = ( ` <div class="status_reactions"> ${ parse _reactions ( status . pleroma . emoji _reactions ) } </div> ` ) ;
2019-08-30 16:58:17 +02:00
status . content = checkStatusLinks ( status . content ) ;
return status ;
}
else {
status . reblog = prepareStatus ( status . reblog ) ;
status . halcyon = new Object ( ) ;
status . account . display _name = htmlEscape ( status . account . display _name ) ;
for ( i = 0 ; i < status . account . emojis . length ; i ++ ) {
status . account . display _name = status . account . display _name . replace ( new RegExp ( ":" + status . account . emojis [ i ] . shortcode + ":" , "g" ) , "<img src='" + status . account . emojis [ i ] . url + "' class='emoji'>" ) ;
}
if ( status . account . acct . indexOf ( "@" ) == - 1 ) status . halcyon . account _link = "/@" + status . account . acct + "@" + current _instance + "?mid=" + status . account . id ;
else status . halcyon . account _link = "/@" + status . account . acct + "?mid=" + status . account . id ;
if ( status . account . display _name . length == 0 ) status . account . display _name = status . account . username ;
}
return status ;
}
2019-12-23 14:58:06 +01:00
function renderTimeline ( statuses , show _replies , level ) {
for ( let i in statuses ) {
var filterstatus = false ;
for ( var a = 0 ; a < current _filters . length ; a ++ ) {
if ( ( ( level == "timelines/home" || level . indexOf ( "timelines/list/" ) != - 1 ) && current _filters [ a ] . context . indexOf ( "home" ) != - 1 && current _filters [ a ] . irreversible == false ) || ( ! ( level == "timelines/home" || level . indexOf ( "timelines/list/" ) != - 1 ) && current _filters [ a ] . context . indexOf ( "public" ) != - 1 ) ) {
if ( current _filters [ a ] . whole _word == false ) {
if ( statuses [ i ] . content . match ( new RegExp ( current _filters [ a ] . phrase ) ) ) filterstatus = true ;
}
else {
if ( statuses [ i ] . content . match ( new RegExp ( "[^a-zA-Z1-9]" + current _filters [ a ] . phrase + "[^a-zA-Z1-9]" ) ) ) filterstatus = true ;
}
}
}
if ( filterstatus == false && ! ( show _replies == "false" && statuses [ i ] . in _reply _to _id ) && ! ( localStorage . setting _show _bots == "false" && statuses [ i ] . account . bot == true && ! level . match ( /accounts\/\d+\/statuses/ ) ) && ! ( statuses [ i ] . visibility == "direct" && level == "timelines/home" ) ) {
timeline _template ( statuses [ i ] ) . appendTo ( "#js-timeline" ) ;
if ( statuses [ i ] . in _reply _to _id && level === "timelines/home" | level === "timelines/public" ) {
if ( localStorage . setting _thread _view == "true" ) {
( function ( this _id ) {
api . get ( 'statuses/' + statuses [ i ] . id + "/context" , function ( context ) {
for ( var b = 0 ; b < context . ancestors . length ; b ++ ) {
var filterreplystatus = false ;
for ( var a = 0 ; a < current _filters . length ; a ++ ) {
if ( current _filters [ a ] . context . indexOf ( "thread" ) != - 1 ) {
if ( current _filters [ a ] . whole _word == false ) {
if ( context . ancestors [ b ] . content . match ( new RegExp ( current _filters [ a ] . phrase ) ) ) filterreplystatus = true ;
}
else {
if ( context . ancestors [ b ] . content . match ( new RegExp ( "[^a-zA-Z1-9]" + current _filters [ a ] . phrase + "[^a-zA-Z1-9]" ) ) ) filterreplystatus = true ;
}
}
}
if ( filterreplystatus == false ) {
$ ( "#js-timeline .toot_entry[sid='" + context . ancestors [ b ] . id + "']" ) . remove ( ) ;
$ ( "#js-timeline .toot_entry[sid='" + this _id + "']" ) . before ( context _template ( context . ancestors [ b ] , 'ancestors_status default_padding' ) ) ;
timeline _hide _status . push ( context . ancestors [ b ] . id ) ;
replace _emoji ( ) ;
}
}
} ) ;
} ) ( statuses [ i ] . id ) ;
}
}
}
}
}
2020-03-29 20:17:40 +02:00
function prepareAnnouncement ( announcement ) {
for ( i = 0 ; i < announcement . emojis . length ; i ++ ) {
announcement . content = announcement . content . replace ( new RegExp ( ":" + announcement . emojis [ i ] . shortcode + ":" , "g" ) , "<img src='" + announcement . emojis [ i ] . url + "' class='emoji'>" ) ;
}
for ( var i = 0 ; i < announcement . mentions . length ; i ++ ) {
if ( announcement . mentions [ i ] . acct . indexOf ( "@" ) == - 1 ) announcement . content = announcement . content . replace ( new RegExp ( 'href="' + announcement . mentions [ i ] . url + '"' , "g" ) , 'href="/@' + announcement . mentions [ i ] . acct + '@' + current _instance + '?mid=' + announcement . mentions [ i ] . id + '" data-mid="' + announcement . mentions [ i ] . id + '"' ) ;
else announcement . content = announcement . content . replace ( new RegExp ( 'href="' + announcement . mentions [ i ] . url + '"' , "g" ) , 'href="/@' + announcement . mentions [ i ] . acct + '?mid=' + announcement . mentions [ i ] . id + '" data-mid="' + announcement . mentions [ i ] . id + '"' ) ;
}
return announcement ;
}
function parse _reactions ( reaction _data ) {
var reactions = ( ` <div class="emoreact_wrap"> ` ) ;
for ( var i = 0 ; i < reaction _data . length ; i ++ ) {
var is _active = "" ;
if ( reaction _data [ i ] . me ) is _active = " active" ;
var emoji ;
if ( reaction _data [ i ] . url ) emoji = ( ` <span><img class="emoji" src=" ${ reaction _data [ i ] . url } "></span> ` ) ;
else emoji = ( ` <span class="emoji_poss"> ${ reaction _data [ i ] . name } </span> ` ) ;
reactions += ( ` <span class="emoreact ${ is _active } " emoji=" ${ reaction _data [ i ] . name } "> ${ emoji } <span class="emoreact_count"> ${ reaction _data [ i ] . count } </span></span> ` ) ;
}
reactions += ( ` <span class="emoreact_add"><i class="fa fa-smile-o"></i></span> ` ) ;
reactions += ( ` </div> ` ) ;
return reactions ;
}
function enableReactionPicker ( that ) {
$ ( that ) . find ( ".emoreact_add" ) . click ( function ( ) {
$ ( this ) . off ( "click" ) ;
( function ( that ) {
$ ( that ) . lsxEmojiPicker ( {
closeOnSelect : true ,
twemoji : ! checkEmojiSupport ( ) ,
onSelect : function ( emoji ) {
api . put ( "announcements/" + $ ( that ) . closest ( ".announcement" ) . attr ( "aid" ) + "/reactions/" + emoji . value , function ( ) { } ) ;
} ,
onClose : function ( ) {
$ ( that ) . lsxEmojiPicker ( "destroy" ) ;
setTimeout ( function ( ) { enableReactionPicker ( $ ( that ) . closest ( ".announcement" ) ) } , 0 ) ;
}
} ) . click ( ) ;
} ) ( this ) ;
} ) ;
}
function addZero ( num ) {
if ( num < 10 ) return "0" + num ;
else return num ;
}