From aed03fe15789d5b55b75103d2fa3810d4c0478b8 Mon Sep 17 00:00:00 2001 From: lartsch Date: Mon, 12 Dec 2022 04:25:42 -0500 Subject: [PATCH] use animation for fav button --- src/inject.js | 8 ++++++-- src/inject.min.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/inject.js b/src/inject.js index 810eb85..9ee7f42 100644 --- a/src/inject.js +++ b/src/inject.js @@ -610,7 +610,8 @@ async function processToots() { // if the action was successfully executed, update the element styles if (action == "boost" || action == "unboost") { // toggle inline css styles - toggleInlineCss($(e.currentTarget).find("i"),[["color","!remove","rgb(140, 141, 255)"],["transition-duration", "!remove", "0.9s"],["background-position", "!remove", "0px 100%"]], "fediactive") + toggleInlineCss($(e.currentTarget),[["color","!remove","rgb(140, 141, 255)"]], "fediactive") + toggleInlineCss($(e.currentTarget).find("i"),[["transition-duration", "!remove", "0.9s"],["background-position", "!remove", "0px 100%"]], "fediactive") // update element in cache if exists if (cacheIndex) { processed[cacheIndex][3] = !processed[cacheIndex][3] @@ -618,6 +619,7 @@ async function processToots() { // same for favourite, bookmarked.... } else if (action == "favourite" || action == "unfavourite") { toggleInlineCss($(e.currentTarget),[["color","!remove","rgb(202, 143, 4)"]], "fediactive") + toggleInlineCss($(e.currentTarget).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]], "fediactive") if (cacheIndex) { processed[cacheIndex][4] = !processed[cacheIndex][4] } @@ -655,12 +657,14 @@ async function processToots() { if (tootdata[4]) { if (!$(favButton).hasClass("fediactive")) { toggleInlineCss($(favButton),[["color","!remove","rgb(202, 143, 4)"]], "fediactive") + toggleInlineCss($(favButton).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]], "fediactive") } } // repeat for other buttons if (tootdata[3]) { if (!$(boostButton).find("i.fediactive").length) { - toggleInlineCss($(boostButton).find("i"),[["color","!remove","rgb(140, 141, 255)"],["transition-duration", "!remove", "0.9s"],["background-position", "!remove", "0px 100%"]], "fediactive") + toggleInlineCss($(boostButton),[["color","!remove","rgb(140, 141, 255)"]], "fediactive") + toggleInlineCss($(boostButton).find("i"),[["transition-duration", "!remove", "0.9s"],["background-position", "!remove", "0px 100%"]], "fediactive") } } if (tootdata[5]) { diff --git a/src/inject.min.js b/src/inject.min.js index f44f9f7..f509f9d 100644 --- a/src/inject.min.js +++ b/src/inject.min.js @@ -1 +1 @@ -const a=["div.account__header button.logo-button","div.public-account-header a.logo-button","div.account-card a.logo-button","div.directory-card a.icon-button","div.detailed-status a.logo-button"],c=["div.account__header__tabs__name small","div.public-account-header__tabs__name small","div.detailed-status span.display-name__account","div.display-name > span"],i=/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/,R=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,D=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?\w+)(?:(?:\/statuses\/)(?\d+))?\/?$/,e=!0,n="[FediAct]",o="/api/v1/instance",r="/api/v1/statuses",s="/api/v2/search",d="/api/v1/accounts",l=500,u=200;var browser,chrome,f,h,N={};const t={fediact_homeinstance:null,fediact_alert:!1,fediact_mode:"blacklist",fediact_whitelist:null,fediact_blacklist:null,fediact_target:"_self",fediact_autoaction:!0,fediact_token:null,fediact_showfollows:!0,fediact_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1,fediact_mutesblocks:[],fediact_domainblocks:[]};var[I,p,m]=[[],[],[]];function M(t){e&&console.log(n+" "+t)}!function(i){i.fn.DOMNodeAppear=function(e,a){if(!a)return!1;i(document).on("animationstart webkitAnimationStart oanimationstart MSAnimationStart",function(t){"nodeInserted"==t.originalEvent.animationName&&i(t.target).is(a)&&"function"==typeof e&&e(t)})},jQuery.fn.onAppear=jQuery.fn.DOMNodeAppear}(jQuery);var g=function(t){for(var e,a=window.location.search.substring(1).split("&"),i=0;i{setTimeout(function(){t()},l-e)}),f=t),new Promise(function(t){let e=new XMLHttpRequest;if(e.open(i,n),e.timeout=3e3,o)for(var a in o)e.setRequestHeader(a,o[a]);e.onload=function(){200<=this.status&&this.status<300?t(e.responseText):t(!1)},e.onerror=function(){M("Request to "+n+" failed."),t(!1)},e.send()})}function b(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _(t,e,a){return t.replace(new RegExp(b(e),"g"),a)}function P(t){var e;N.fediact_redirects?(N.fediact_alert&&alert("Redirecting..."),e=window.open(t,N.fediact_target),M("Redirected to "+t),e?e.focus():M("Could not open new window. Please allow popups for this website.")):M("Redirects disabled.")}async function S(t,e){var a,i;switch(e){case"follow":a="https://"+N.fediact_homeinstance+d+"/"+t+"/follow",i=function(t){return t.following||t.requested};break;case"boost":a="https://"+N.fediact_homeinstance+r+"/"+t+"/reblog",i=function(t){return t.reblogged};break;case"favourite":a="https://"+N.fediact_homeinstance+r+"/"+t+"/favourite",i=function(t){return t.favourited};break;case"bookmark":a="https://"+N.fediact_homeinstance+r+"/"+t+"/bookmark",i=function(t){return t.bookmarked};break;case"unfollow":a="https://"+N.fediact_homeinstance+d+"/"+t+"/unfollow",i=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+N.fediact_homeinstance+r+"/"+t+"/unreblog",i=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+N.fediact_homeinstance+r+"/"+t+"/unfavourite",i=function(t){return!t.favourited};break;case"unbookmark":a="https://"+N.fediact_homeinstance+r+"/"+t+"/unbookmark",i=function(t){return!t.bookmarked};break;default:M("No valid action specified.")}if(a){var n=await v("POST",a,N.tokenheader);if(n&&i(JSON.parse(n)))return!0}M(e+" action failed.")}async function w(t){var e="https://"+N.fediact_homeinstance+d+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var a=await v("GET",e,N.tokenheader),i=Array(t.length).fill(!1);if(a)for(var a=JSON.parse(a),n=0;nN.fediact_mutesblocks.includes(t))||E(e)||n.some(t=>N.fediact_domainblocks.includes(t.split("@")[1]))?($(t).hide(),a&&$(a).hide(),1):void 0}}(e,t)){i=$(e);var a=$(i).is(".detailed-status__wrapper")?(a=window.location.href.split("?")[0].split("/")).pop()||a.pop():$(i).attr("data-id")?$(i).attr("data-id").split("-").slice(-1)[0]:$(i).closest("article[data-id], div[data-id]").length?$(i).closest("article[data-id], div[data-id]").first().attr("data-id").split("-").slice(-1)[0]:void 0,[i,n]=(i=$(e),$(i).find("a.status__relative-time").length?O($(i).find("a.status__relative-time").first().attr("href").split("?")[0]):$(i).find("a.detailed-status__datetime").length?O($(i).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(i).find("a.modal-button").length?O($(i).find("a.modal-button").first().attr("href").split("?")[0]):void 0),o=a||n;if(o){var r=[],s=W(o),c=$(e).find("button:has(i.fa-star), a.icon-button:has(i.fa-star)").first(),d=$(e).find("button:has(i.fa-retweet), a.icon-button:has(i.fa-retweet)").first(),l=$(e).find("button:has(i.fa-bookmark)").first(),u=$(e).find("button:has(i.fa-reply), button:has(i.fa-reply-all), a.icon-button:has(i.fa-reply), a.icon-button:has(i.fa-reply-all)").first();async function f(t,e){if(!N.fediact_autoaction)return M("Auto-action disabled."),!0;i=e,a=!1,$(i.currentTarget).children("i.fa-retweet").length?a=$(i.currentTarget).children("i.fa-retweet").hasClass("fediactive")?"unboost":"boost":$(i.currentTarget).children("i.fa-star").length?a=$(i.currentTarget).hasClass("fediactive")?"unfavourite":"favourite":$(i.currentTarget).children("i.fa-bookmark").length?a=$(i.currentTarget).hasClass("fediactive")?"unbookmark":"bookmark":$(i.currentTarget).attr("href")&&(~$(i.currentTarget).attr("href").indexOf("type=reblog")?a=$(i.currentTarget).hasClass("fediactive")?"unboost":"boost":~$(i.currentTarget).attr("href").indexOf("type=favourite")&&(a=$(i.currentTarget).hasClass("fediactive")?"unfavourite":"favourite"));var a,i=a;if(i){if(await S(t,i))return"boost"==i||"unboost"==i?(z($(e.currentTarget).find("i"),[["color","!remove","rgb(140, 141, 255)"],["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive"),s&&(I[s][3]=!I[s][3])):"favourite"==i||"unfavourite"==i?(z($(e.currentTarget),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),s&&(I[s][4]=!I[s][4])):(z($(e.currentTarget),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),s&&(I[s][5]=!I[s][5])),!0;M("Could not execute action on home instance.")}else M("Could not determine action.")}function h(t){$(e).find(".feditriggered").remove(),t[1]?($(l).removeClass("disabled").removeAttr("disabled"),t[4]&&!$(c).hasClass("fediactive")&&z($(c),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),t[3]&&!$(d).find("i.fediactive").length&&z($(d).find("i"),[["color","!remove","rgb(140, 141, 255)"],["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive"),t[5]&&!$(l).hasClass("fediactive")&&z($(l),[["color","!remove","rgb(255, 80, 80)"]],"fediactive")):$("Unresolved").insertAfter($(c))}function p(i){$(u).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),P(i[6]+"?fedireply")}),$([c,d,l]).each(function(){var e,a=0;$(this).on("click",async function(t){t.preventDefault(),t.stopImmediatePropagation(),1==++a?e=setTimeout(async function(){await f(i[2],t)||M("Action failed."),a=0},350):(clearTimeout(e),await f(i[2],t)?P(i[6]):M("Action failed."),a=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(s){var m=I[s];h(m),m[1]&&p(m)}else{if(i&&r.push(n),t){var g,v,b,_=t.match(R),[w,k]=[!1,!1],y=(!_.groups.handledomain||~location.hostname.indexOf(_.groups.handledomain)||(w=!0),[a]);i||y.push(n);for(g of y=y.filter((t,e)=>void 0!==t&&y.indexOf(t)==e))w?k||((v=await J(location.protocol+"//"+location.hostname+"/"+t+"/"+g))&&(k=!0,r.push(v),D.test(v)?(b=v.match(D)).groups.handle&&b.groups.tootid&&b.groups.domain&&r.push(b.groups.domain+"/@"+b.groups.handle+"/"+b.groups.tootid):R.test(v)&&(b=v.match(R)).groups.handle&&b.groups.tootid&&b.groups.domain&&r.push(b.groups.domain+"/users/"+b.groups.handle+"/statuses/"+b.groups.tootid)),r.push(location.protocol+"//"+location.hostname+"/"+t+"/"+g)):(r.push(location.protocol+"//"+location.hostname+"/users/"+_.groups.handle+"/statuses/"+g),r.push(location.protocol+"//"+location.hostname+"/@"+_.groups.handle+"/"+g))}if(r.length){var x,T,A,C=!1;for(x of r=r.filter((t,e)=>r.indexOf(t)==e))C||(T=await U(x))&&(C=!0,A="https://"+N.fediact_homeinstance+"/@"+T[0]+"/"+T[1],fullEntry=[o,...T,A,!0]);C?(q(fullEntry),p(fullEntry),h(fullEntry)):(M("Failed to resolve: "+r),q([o,!1]),h([o,!1]))}else M("Could not identify a post URI for home resolving."),q([o,!1]),h([o,!1])}}else M("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){m.includes($(t.target).get(0))||(m.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){m.includes($(this).get(0))||(m.push($(this).get(0)),e($(this)))})}async function O(){async function e(i){var t,n,o,r,e="follow";async function s(t){return N.fediact_autoaction?(t=await S(t,e),"follow"==e&&t?($(i).text("Unfollow"),e="unfollow",!0):"unfollow"==e&&t?($(i).text("Follow"),e="follow",!0):void 0):(M("Auto-action disabled."),!0)}if($(i).closest("div.account-card").length)t=$(i).closest("div.account-card").find("div.display-name > span").text().trim();else for(const a of c)if($(a).length){t=$(a).text().trim();break}t&&!p.includes(t)&&((n=await k(t))?(p.push(t),N.fediact_showfollows&&(await w([n[0]]))[0]&&($(i).text("Unfollow"),e="unfollow"),o=0,$(i).on("click",async function(t){var e,a;t.preventDefault(),t.stopImmediatePropagation(),1==++o?r=setTimeout(async function(){s(n[0]),o=0},350):(clearTimeout(r),await s(n[0])?(e=$(i).text(),a="https://"+N.fediact_homeinstance+"/@"+n[1],$(i).text("Redirecting..."),setTimeout(function(){P(a),$(i).text(e)},1e3)):M("Action failed."),o=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})):M("Could not resolve user home ID."))}var t=a.join(",");$(document).DOMNodeAppear(async function(t){m.includes($(t.target).get(0))||(m.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){m.includes($(this).get(0))||(m.push($(this).get(0)),e($(this)))})}function y(t){var e,a=[];for(e of t.split(/\r?\n/))(e=e.trim()).length&&(i.test(e)?a.push(e):M("Removed invalid domain "+e+" from blacklist/whitelist."));return[...new Set(a)]}function j(){if(null==N.fediact_homeinstance||!N.fediact_homeinstance)return M("Mastodon home instance is not set."),!1;if(!N.fediact_token)return M("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(N.tokenheader={Authorization:"Bearer "+N.fediact_token},!i.test(N.fediact_homeinstance))return M("Instance setting is not a valid domain name."),!1;if("whitelist"==N.fediact_mode){if(N.fediact_whitelist=y(N.fediact_whitelist),N.fediact_whitelist.length<1)return M("Whitelist is empty or invalid."),!1}else N.fediact_blacklist=y(N.fediact_blacklist);return!0}async function F(){if(location.hostname!=N.fediact_homeinstance||(h=g("fedireply"))){if("whitelist"==N.fediact_mode){if($.inArray(location.hostname,N.fediact_whitelist)<0)return M("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,N.fediact_blacklist))return M("Current site is in blacklist."),!1;var t=await v("GET",location.protocol+"//"+location.hostname+o,null);if(t){t=JSON.parse(t).uri;if(t)return N.fediact_exturi=t,!0}M("Does not look like a Mastodon instance.")}else M("Current site is your home instance.");return!1}async function G(){chrome.runtime.onMessage.addListener(async function(t,e,a){t.urlchanged&&(I=[],p=[],m=[],await x()||location.reload()),t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){M(t)}return!1}function x(){return new Promise(async function(e){try{N=await(browser||chrome).storage.local.get(t)}catch(t){M(t),e(!1)}N&&j()?e(!0):e(!1)})}async function L(){await x()?await F()?h?A():G()?(O(),C()):M("Failed to initialize background script."):M("Will not process this site."):M("Could not load settings.")}L(); \ No newline at end of file +const i=["div.account__header button.logo-button","div.public-account-header a.logo-button","div.account-card a.logo-button","div.directory-card a.icon-button","div.detailed-status a.logo-button"],c=["div.account__header__tabs__name small","div.public-account-header__tabs__name small","div.detailed-status span.display-name__account","div.display-name > span"],a=/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/,R=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,D=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?\w+)(?:(?:\/statuses\/)(?\d+))?\/?$/,e=!0,n="[FediAct]",o="/api/v1/instance",r="/api/v1/statuses",s="/api/v2/search",d="/api/v1/accounts",l=500,u=200;var browser,chrome,f,h,N={};const t={fediact_homeinstance:null,fediact_alert:!1,fediact_mode:"blacklist",fediact_whitelist:null,fediact_blacklist:null,fediact_target:"_self",fediact_autoaction:!0,fediact_token:null,fediact_showfollows:!0,fediact_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1,fediact_mutesblocks:[],fediact_domainblocks:[]};var[I,p,m]=[[],[],[]];function M(t){e&&console.log(n+" "+t)}!function(a){a.fn.DOMNodeAppear=function(e,i){if(!i)return!1;a(document).on("animationstart webkitAnimationStart oanimationstart MSAnimationStart",function(t){"nodeInserted"==t.originalEvent.animationName&&a(t.target).is(i)&&"function"==typeof e&&e(t)})},jQuery.fn.onAppear=jQuery.fn.DOMNodeAppear}(jQuery);var g=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{setTimeout(function(){t()},l-e)}),f=t),new Promise(function(t){let e=new XMLHttpRequest;if(e.open(a,n),e.timeout=3e3,o)for(var i in o)e.setRequestHeader(i,o[i]);e.onload=function(){200<=this.status&&this.status<300?t(e.responseText):t(!1)},e.onerror=function(){M("Request to "+n+" failed."),t(!1)},e.send()})}function b(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _(t,e,i){return t.replace(new RegExp(b(e),"g"),i)}function P(t){var e;N.fediact_redirects?(N.fediact_alert&&alert("Redirecting..."),e=window.open(t,N.fediact_target),M("Redirected to "+t),e?e.focus():M("Could not open new window. Please allow popups for this website.")):M("Redirects disabled.")}async function S(t,e){var i,a;switch(e){case"follow":i="https://"+N.fediact_homeinstance+d+"/"+t+"/follow",a=function(t){return t.following||t.requested};break;case"boost":i="https://"+N.fediact_homeinstance+r+"/"+t+"/reblog",a=function(t){return t.reblogged};break;case"favourite":i="https://"+N.fediact_homeinstance+r+"/"+t+"/favourite",a=function(t){return t.favourited};break;case"bookmark":i="https://"+N.fediact_homeinstance+r+"/"+t+"/bookmark",a=function(t){return t.bookmarked};break;case"unfollow":i="https://"+N.fediact_homeinstance+d+"/"+t+"/unfollow",a=function(t){return!t.following&&!t.requested};break;case"unboost":i="https://"+N.fediact_homeinstance+r+"/"+t+"/unreblog",a=function(t){return!t.reblogged};break;case"unfavourite":i="https://"+N.fediact_homeinstance+r+"/"+t+"/unfavourite",a=function(t){return!t.favourited};break;case"unbookmark":i="https://"+N.fediact_homeinstance+r+"/"+t+"/unbookmark",a=function(t){return!t.bookmarked};break;default:M("No valid action specified.")}if(i){var n=await v("POST",i,N.tokenheader);if(n&&a(JSON.parse(n)))return!0}M(e+" action failed.")}async function w(t){var e="https://"+N.fediact_homeinstance+d+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await v("GET",e,N.tokenheader),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;nN.fediact_mutesblocks.includes(t))||E(e)||n.some(t=>N.fediact_domainblocks.includes(t.split("@")[1]))?($(t).hide(),i&&$(i).hide(),1):void 0}}(e,t)){a=$(e);var i=$(a).is(".detailed-status__wrapper")?(i=window.location.href.split("?")[0].split("/")).pop()||i.pop():$(a).attr("data-id")?$(a).attr("data-id").split("-").slice(-1)[0]:$(a).closest("article[data-id], div[data-id]").length?$(a).closest("article[data-id], div[data-id]").first().attr("data-id").split("-").slice(-1)[0]:void 0,[a,n]=(a=$(e),$(a).find("a.status__relative-time").length?O($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?O($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?O($(a).find("a.modal-button").first().attr("href").split("?")[0]):void 0),o=i||n;if(o){var r=[],s=W(o),c=$(e).find("button:has(i.fa-star), a.icon-button:has(i.fa-star)").first(),d=$(e).find("button:has(i.fa-retweet), a.icon-button:has(i.fa-retweet)").first(),l=$(e).find("button:has(i.fa-bookmark)").first(),u=$(e).find("button:has(i.fa-reply), button:has(i.fa-reply-all), a.icon-button:has(i.fa-reply), a.icon-button:has(i.fa-reply-all)").first();async function f(t,e){if(!N.fediact_autoaction)return M("Auto-action disabled."),!0;a=e,i=!1,$(a.currentTarget).children("i.fa-retweet").length?i=$(a.currentTarget).children("i.fa-retweet").hasClass("fediactive")?"unboost":"boost":$(a.currentTarget).children("i.fa-star").length?i=$(a.currentTarget).hasClass("fediactive")?"unfavourite":"favourite":$(a.currentTarget).children("i.fa-bookmark").length?i=$(a.currentTarget).hasClass("fediactive")?"unbookmark":"bookmark":$(a.currentTarget).attr("href")&&(~$(a.currentTarget).attr("href").indexOf("type=reblog")?i=$(a.currentTarget).hasClass("fediactive")?"unboost":"boost":~$(a.currentTarget).attr("href").indexOf("type=favourite")&&(i=$(a.currentTarget).hasClass("fediactive")?"unfavourite":"favourite"));var i,a=i;if(a){if(await S(t,a))return"boost"==a||"unboost"==a?(z($(e.currentTarget),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),z($(e.currentTarget).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive"),s&&(I[s][3]=!I[s][3])):"favourite"==a||"unfavourite"==a?(z($(e.currentTarget),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),z($(e.currentTarget).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive"),s&&(I[s][4]=!I[s][4])):(z($(e.currentTarget),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),s&&(I[s][5]=!I[s][5])),!0;M("Could not execute action on home instance.")}else M("Could not determine action.")}function h(t){$(e).find(".feditriggered").remove(),t[1]?($(l).removeClass("disabled").removeAttr("disabled"),t[4]&&!$(c).hasClass("fediactive")&&(z($(c),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),z($(c).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive")),t[3]&&!$(d).find("i.fediactive").length&&(z($(d),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),z($(d).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive")),t[5]&&!$(l).hasClass("fediactive")&&z($(l),[["color","!remove","rgb(255, 80, 80)"]],"fediactive")):$("Unresolved").insertAfter($(c))}function p(a){$(u).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),P(a[6]+"?fedireply")}),$([c,d,l]).each(function(){var e,i=0;$(this).on("click",async function(t){t.preventDefault(),t.stopImmediatePropagation(),1==++i?e=setTimeout(async function(){await f(a[2],t)||M("Action failed."),i=0},350):(clearTimeout(e),await f(a[2],t)?P(a[6]):M("Action failed."),i=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(s){var m=I[s];h(m),m[1]&&p(m)}else{if(a&&r.push(n),t){var g,v,b,_=t.match(R),[w,k]=[!1,!1],y=(!_.groups.handledomain||~location.hostname.indexOf(_.groups.handledomain)||(w=!0),[i]);a||y.push(n);for(g of y=y.filter((t,e)=>void 0!==t&&y.indexOf(t)==e))w?k||((v=await J(location.protocol+"//"+location.hostname+"/"+t+"/"+g))&&(k=!0,r.push(v),D.test(v)?(b=v.match(D)).groups.handle&&b.groups.tootid&&b.groups.domain&&r.push(b.groups.domain+"/@"+b.groups.handle+"/"+b.groups.tootid):R.test(v)&&(b=v.match(R)).groups.handle&&b.groups.tootid&&b.groups.domain&&r.push(b.groups.domain+"/users/"+b.groups.handle+"/statuses/"+b.groups.tootid)),r.push(location.protocol+"//"+location.hostname+"/"+t+"/"+g)):(r.push(location.protocol+"//"+location.hostname+"/users/"+_.groups.handle+"/statuses/"+g),r.push(location.protocol+"//"+location.hostname+"/@"+_.groups.handle+"/"+g))}if(r.length){var x,T,A,C=!1;for(x of r=r.filter((t,e)=>r.indexOf(t)==e))C||(T=await U(x))&&(C=!0,A="https://"+N.fediact_homeinstance+"/@"+T[0]+"/"+T[1],fullEntry=[o,...T,A,!0]);C?(q(fullEntry),p(fullEntry),h(fullEntry)):(M("Failed to resolve: "+r),q([o,!1]),h([o,!1]))}else M("Could not identify a post URI for home resolving."),q([o,!1]),h([o,!1])}}else M("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){m.includes($(t.target).get(0))||(m.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){m.includes($(this).get(0))||(m.push($(this).get(0)),e($(this)))})}async function O(){async function e(a){var t,n,o,r,e="follow";async function s(t){return N.fediact_autoaction?(t=await S(t,e),"follow"==e&&t?($(a).text("Unfollow"),e="unfollow",!0):"unfollow"==e&&t?($(a).text("Follow"),e="follow",!0):void 0):(M("Auto-action disabled."),!0)}if($(a).closest("div.account-card").length)t=$(a).closest("div.account-card").find("div.display-name > span").text().trim();else for(const i of c)if($(i).length){t=$(i).text().trim();break}t&&!p.includes(t)&&((n=await k(t))?(p.push(t),N.fediact_showfollows&&(await w([n[0]]))[0]&&($(a).text("Unfollow"),e="unfollow"),o=0,$(a).on("click",async function(t){var e,i;t.preventDefault(),t.stopImmediatePropagation(),1==++o?r=setTimeout(async function(){s(n[0]),o=0},350):(clearTimeout(r),await s(n[0])?(e=$(a).text(),i="https://"+N.fediact_homeinstance+"/@"+n[1],$(a).text("Redirecting..."),setTimeout(function(){P(i),$(a).text(e)},1e3)):M("Action failed."),o=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})):M("Could not resolve user home ID."))}var t=i.join(",");$(document).DOMNodeAppear(async function(t){m.includes($(t.target).get(0))||(m.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){m.includes($(this).get(0))||(m.push($(this).get(0)),e($(this)))})}function y(t){var e,i=[];for(e of t.split(/\r?\n/))(e=e.trim()).length&&(a.test(e)?i.push(e):M("Removed invalid domain "+e+" from blacklist/whitelist."));return[...new Set(i)]}function j(){if(null==N.fediact_homeinstance||!N.fediact_homeinstance)return M("Mastodon home instance is not set."),!1;if(!N.fediact_token)return M("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(N.tokenheader={Authorization:"Bearer "+N.fediact_token},!a.test(N.fediact_homeinstance))return M("Instance setting is not a valid domain name."),!1;if("whitelist"==N.fediact_mode){if(N.fediact_whitelist=y(N.fediact_whitelist),N.fediact_whitelist.length<1)return M("Whitelist is empty or invalid."),!1}else N.fediact_blacklist=y(N.fediact_blacklist);return!0}async function F(){if(location.hostname!=N.fediact_homeinstance||(h=g("fedireply"))){if("whitelist"==N.fediact_mode){if($.inArray(location.hostname,N.fediact_whitelist)<0)return M("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,N.fediact_blacklist))return M("Current site is in blacklist."),!1;var t=await v("GET",location.protocol+"//"+location.hostname+o,null);if(t){t=JSON.parse(t).uri;if(t)return N.fediact_exturi=t,!0}M("Does not look like a Mastodon instance.")}else M("Current site is your home instance.");return!1}async function G(){chrome.runtime.onMessage.addListener(async function(t,e,i){t.urlchanged&&(I=[],p=[],m=[],await x()||location.reload()),t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){M(t)}return!1}function x(){return new Promise(async function(e){try{N=await(browser||chrome).storage.local.get(t)}catch(t){M(t),e(!1)}N&&j()?e(!0):e(!1)})}async function L(){await x()?await F()?h?A():G()?(O(),C()):M("Failed to initialize background script."):M("Will not process this site."):M("Could not load settings.")}L(); \ No newline at end of file