From dbf1813adfd623c0631e1d8dbf86074279721073 Mon Sep 17 00:00:00 2001 From: lartsch Date: Wed, 14 Dec 2022 19:30:40 -0500 Subject: [PATCH] start background processor earlier to react in some conditions --- src/inject.js | 14 ++++++++------ src/inject.min.js | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/inject.js b/src/inject.js index 7871a59..48a29d4 100644 --- a/src/inject.js +++ b/src/inject.js @@ -1176,6 +1176,12 @@ async function checkSite() { } else { settings.fediact_exturi = uri } + // at this point, we know that it's mastodon and the background processor should start running + if (!backgroundProcessor()) { + log("Could not start background process") + return false + } + // if option is enabled, check if logged in on that instance and stop if (!settings.fediact_runifloggedin) { if (await isLoggedIn()) { log("Already logged in to this external instance.") @@ -1251,12 +1257,8 @@ async function run() { if (fedireply) { processReply() } else { - if (backgroundProcessor()) { - processFollow() - processToots() - } else { - log("Failed to initialize background script.") - } + processFollow() + processToots() } } else { log("Will not process this site.") diff --git a/src/inject.min.js b/src/inject.min.js index dbb46a2..4f52c81 100644 --- a/src/inject.min.js +++ b/src/inject.min.js @@ -1 +1 @@ -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","button.remote-button","div.account__header button.button--follow"],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.user-screen-name","div.profile-info-panel small"],a=/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/,P=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,I=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?\w+)(?:(?:\/statuses\/)(?\d+))?\/?$/,e=!1,n="[FediAct]",o="/api/v1/instance",s="/api/v1/statuses",r="/api/v2/search",l="/api/v1/accounts",d="/api/v1/polls",u=500,f=200;var browser,chrome,h,p,M={};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_runifloggedin:!1,fediact_showtoot:!0,fediact_mutesblocks:[],fediact_domainblocks:[]};var[q,g,m]=[[],[],[]];function z(t){e&&console.log(n+" "+t)}function v(){return new Promise(function(e){var t;$(document).find("script#initial-state").length?(t=$(document).find("script#initial-state").first(),JSON.parse($(t).text()).meta.access_token&&e(!0)):$(document).DOMNodeAppear(function(t){t=$(t.target);JSON.parse($(t).text()).meta.access_token&&e(!0)},"script#initial-state"),e(!1)})}!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 _=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{setTimeout(function(){t()},u-e)}),h=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(){z("Request to "+n+" failed."),t(!1)},r?(e.setRequestHeader("Content-Type","application/json"),e.send(JSON.stringify(r))):e.send()})}function w(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function y(t,e,i){return t.replace(new RegExp(w(e),"g"),i)}function J(t){var e;M.fediact_redirects?M.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,M.fediact_target),z("Redirected to "+t),e?e.focus():z("Could not open new window. Please allow popups for this website.")):z("Redirects disabled.")}async function U(t,e,i){var a,n,o;switch(e){case"vote":a="https://"+M.fediact_homeinstance+d+"/"+t+"/votes",n=function(t){return t.voted},o=i;break;case"follow":a="https://"+M.fediact_homeinstance+l+"/"+t+"/follow",n=function(t){return t.following||t.requested};break;case"boost":a="https://"+M.fediact_homeinstance+s+"/"+t+"/reblog",n=function(t){return t.reblogged};break;case"favourite":a="https://"+M.fediact_homeinstance+s+"/"+t+"/favourite",n=function(t){return t.favourited};break;case"bookmark":a="https://"+M.fediact_homeinstance+s+"/"+t+"/bookmark",n=function(t){return t.bookmarked};break;case"unfollow":a="https://"+M.fediact_homeinstance+l+"/"+t+"/unfollow",n=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+M.fediact_homeinstance+s+"/"+t+"/unreblog",n=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+M.fediact_homeinstance+s+"/"+t+"/unfavourite",n=function(t){return!t.favourited};break;case"unbookmark":a="https://"+M.fediact_homeinstance+s+"/"+t+"/unbookmark",n=function(t){return!t.bookmarked};break;default:z("No valid action specified.")}if(a){var r=await b("POST",a,M.tokenheader,o);if(r&&n(JSON.parse(r)))return!0}z(e+" action failed.")}async function k(t){var e="https://"+M.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await b("GET",e,M.tokenheader,null),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;nM.fediact_mutesblocks.includes(t))||j(e)||o.some(t=>M.fediact_domainblocks.includes(t.split("@")[1]))?($(t).hide(),i&&$(i).hide(),1):void 0}}(e,t)){var i=function(t){if($(t).is(".detailed-status__wrapper"))return(e=window.location.href.split("?")[0].split("/")).pop()||e.pop();if($(t).attr("data-id"))return $(t).attr("data-id").split("-").slice(-1)[0];if($(t).closest("article[data-id], div[data-id]").length)return $(t).closest("article[data-id], div[data-id]").first().attr("data-id").split("-").slice(-1)[0];if($(t).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)").length){var e=$(t).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)").first();if($(e).attr("href")){t=$(e).attr("href");if(~t.indexOf("interact/"))return(e=t.split("?")[0].split("/")).pop()||e.pop()}}}($(e)),[a,n]=(a=$(e),$(a).find("a.status__relative-time").length?D($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?D($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?D($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var r=[],s=G(o),c=$(e).find("button:has(i.fa-star)").first(),l=($(c).length||(c=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),$(e).find("button:has(i.fa-retweet)").first()),d=($(l).length||(l=$(e).find("a.icon-button:has(i.fa-retweet), a.detailed-status__link:has(i.fa-retweet)")),$(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(),f=$(e).find("div.poll button").first();async function h(t,e,i){if(M.fediact_autoaction){for(var a={choices:[]},n=$(i.currentTarget).closest("div.poll"),o=$(n).find("li"),r=0;rView the results on your home instance.

"),s)&&(q[s][9]=!q[s][9],q[s][9]=!0),t}}async function p(t,e){if(!M.fediact_autoaction)return z("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 U(t,a,null))return s&&(q[s][10]=!0),"boost"==a||"unboost"==a?(W($(e.currentTarget),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),W($(e.currentTarget).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive"),s&&(q[s][3]=!q[s][3])):"favourite"==a||"unfavourite"==a?(W($(e.currentTarget),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),W($(e.currentTarget).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive"),s&&(q[s][4]=!q[s][4])):(W($(e.currentTarget),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),s&&(q[s][5]=!q[s][5])),!0;z("Could not execute action on home instance.")}else z("Could not determine action.")}function g(t){$(e).find(".feditriggered").remove(),t[1]?($(d).removeClass("disabled").removeAttr("disabled"),$(f).removeAttr("disabled"),(M.fediact_showtoot||t[10])&&(t[4]&&!$(c).hasClass("fediactive")&&(W($(c),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),W($(c).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive")),t[3]&&!$(l).find("i.fediactive").length&&(W($(l),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),W($(l).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive")),t[5]&&!$(d).hasClass("fediactive")&&W($(d),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),t[9])&&($(f).hide(),$(f).closest("div.poll").find("ul").replaceWith("

View the results on your home instance.

"))):$("Unresolved").insertAfter($(c))}function m(n){$(u).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),J(n[6]+"?fedireply")}),$([c,l,d,f]).each(function(){$(f).length&&$(f).get(0).isEqualNode($(this).get(0))&&(e=!0);var e,i,a=0;$(this).on("click",async function(t){t.preventDefault(),t.stopImmediatePropagation(),1==++a?i=setTimeout(async function(){(e&&!n[9]?h(n[8],n[6],t):await p(n[2],t))||z("Action failed."),a=0},350):(clearTimeout(i),(e?h(n[8],n[6],t):await p(n[2],t))?J(n[6]):z("Action failed."),a=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(s){var v=q[s];g(v),v[1]&&m(v)}else{if(a&&r.push(n),t){var _,b,w,y=t.match(P),[k,x]=[!1,!1],T=(!y.groups.handledomain||~location.hostname.indexOf(y.groups.handledomain)||(k=!0),[i]);a||T.push(n);for(_ of T=T.filter((t,e)=>void 0!==t&&T.indexOf(t)==e))k?x||((b=await F(location.protocol+"//"+location.hostname+"/"+t+"/"+_))&&(x=!0,r.push(b),I.test(b)?(w=b.match(I)).groups.handle&&w.groups.tootid&&w.groups.domain&&r.push(w.groups.domain+"/@"+w.groups.handle+"/"+w.groups.tootid):P.test(b)&&(w=b.match(P)).groups.handle&&w.groups.tootid&&w.groups.domain&&r.push(w.groups.domain+"/users/"+w.groups.handle+"/statuses/"+w.groups.tootid)),r.push(location.protocol+"//"+location.hostname+"/"+t+"/"+_)):(r.push(location.protocol+"//"+location.hostname+"/users/"+y.groups.handle+"/statuses/"+_),r.push(location.protocol+"//"+location.hostname+"/@"+y.groups.handle+"/"+_))}if(r.length){var A,C,O,N,R,S=!1;for(A of r=r.filter((t,e)=>r.indexOf(t)==e))S||([C,O]=await L(A),C&&(S=!0,N="https://"+M.fediact_homeinstance+"/@"+C[0]+"/"+C[1],R=[o,...C,N,!0,...O,!1]));S?(s=E(R),g(R),m(R)):(z("Failed to resolve: "+r),s=E([o,!1]),g([o,!1]))}else z("Could not identify a post URI for home resolving."),s=E([o,!1]),g([o,!1])}}else z("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 N(){async function e(a){var t,n,o,r,e="follow";async function s(t){return M.fediact_autoaction?(t=await U(t,e,null),"follow"==e&&t?($(a).text("Unfollow"),e="unfollow",!0):"unfollow"==e&&t?($(a).text("Follow"),e="follow",!0):void 0):(z("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()).split("@").length-1==1&&(t=t+"@"+M.fediact_exturi);break}t&&!g.includes(t)&&((n=await A(t))?(g.push(t),M.fediact_showfollows&&(await k([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://"+M.fediact_homeinstance+"/@"+n[1],$(a).text("Redirecting..."),setTimeout(function(){J(i),$(a).text(e)},1e3)):z("Action failed."),o=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})):z("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 x(t){var e,i=[];for(e of t.split(/\r?\n/))(e=e.trim()).length&&(a.test(e)?i.push(e):z("Removed invalid domain "+e+" from blacklist/whitelist."));return[...new Set(i)]}function R(){if(null==M.fediact_homeinstance||!M.fediact_homeinstance)return z("Mastodon home instance is not set."),!1;if(!M.fediact_token)return z("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(M.tokenheader={Authorization:"Bearer "+M.fediact_token},!a.test(M.fediact_homeinstance))return z("Instance setting is not a valid domain name."),!1;if("whitelist"==M.fediact_mode){if(M.fediact_whitelist=x(M.fediact_whitelist),M.fediact_whitelist.length<1)return z("Whitelist is empty or invalid."),!1}else M.fediact_blacklist=x(M.fediact_blacklist);return!0}async function S(){if(location.hostname==M.fediact_homeinstance&&!(p=_("fedireply")))return z("Current site is your home instance."),!1;if("whitelist"==M.fediact_mode){if($.inArray(location.hostname,M.fediact_whitelist)<0)return z("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,M.fediact_blacklist))return z("Current site is in blacklist."),!1;var t=await b("GET",location.protocol+"//"+location.hostname+o,null,null);return!!t&&!(!(t=JSON.parse(t).uri)||(t.startsWith("http")?(t=new URL(t),M.fediact_exturi=t.hostname):M.fediact_exturi=t,!M.fediact_runifloggedin&&await v()&&(z("Already logged in to this external instance."),1)))}async function D(){chrome.runtime.onMessage.addListener(async function(t,e,i){t.urlchanged&&(q=[],g=[],m=[],await T()||location.reload()),t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){z(t)}return!1}function T(){return new Promise(async function(e){try{M=await(browser||chrome).storage.local.get(t)}catch(t){z(t),e(!1)}M&&R()?e(!0):e(!1)})}async function H(){await T()?await S()?p?C():D()?(N(),O()):z("Failed to initialize background script."):z("Will not process this site."):z("Could not load settings.")}H(); \ 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","button.remote-button","div.account__header button.button--follow"],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.user-screen-name","div.profile-info-panel small"],a=/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/,P=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,I=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?\w+)(?:(?:\/statuses\/)(?\d+))?\/?$/,e=!1,n="[FediAct]",o="/api/v1/instance",s="/api/v1/statuses",r="/api/v2/search",l="/api/v1/accounts",d="/api/v1/polls",u=500,f=200;var browser,chrome,h,p,M={};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_runifloggedin:!1,fediact_showtoot:!0,fediact_mutesblocks:[],fediact_domainblocks:[]};var[q,g,m]=[[],[],[]];function z(t){e&&console.log(n+" "+t)}function v(){return new Promise(function(e){var t;$(document).find("script#initial-state").length?(t=$(document).find("script#initial-state").first(),JSON.parse($(t).text()).meta.access_token&&e(!0)):$(document).DOMNodeAppear(function(t){t=$(t.target);JSON.parse($(t).text()).meta.access_token&&e(!0)},"script#initial-state"),e(!1)})}!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 _=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{setTimeout(function(){t()},u-e)}),h=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(){z("Request to "+n+" failed."),t(!1)},r?(e.setRequestHeader("Content-Type","application/json"),e.send(JSON.stringify(r))):e.send()})}function w(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function y(t,e,i){return t.replace(new RegExp(w(e),"g"),i)}function J(t){var e;M.fediact_redirects?M.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,M.fediact_target),z("Redirected to "+t),e?e.focus():z("Could not open new window. Please allow popups for this website.")):z("Redirects disabled.")}async function U(t,e,i){var a,n,o;switch(e){case"vote":a="https://"+M.fediact_homeinstance+d+"/"+t+"/votes",n=function(t){return t.voted},o=i;break;case"follow":a="https://"+M.fediact_homeinstance+l+"/"+t+"/follow",n=function(t){return t.following||t.requested};break;case"boost":a="https://"+M.fediact_homeinstance+s+"/"+t+"/reblog",n=function(t){return t.reblogged};break;case"favourite":a="https://"+M.fediact_homeinstance+s+"/"+t+"/favourite",n=function(t){return t.favourited};break;case"bookmark":a="https://"+M.fediact_homeinstance+s+"/"+t+"/bookmark",n=function(t){return t.bookmarked};break;case"unfollow":a="https://"+M.fediact_homeinstance+l+"/"+t+"/unfollow",n=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+M.fediact_homeinstance+s+"/"+t+"/unreblog",n=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+M.fediact_homeinstance+s+"/"+t+"/unfavourite",n=function(t){return!t.favourited};break;case"unbookmark":a="https://"+M.fediact_homeinstance+s+"/"+t+"/unbookmark",n=function(t){return!t.bookmarked};break;default:z("No valid action specified.")}if(a){var r=await b("POST",a,M.tokenheader,o);if(r&&n(JSON.parse(r)))return!0}z(e+" action failed.")}async function k(t){var e="https://"+M.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await b("GET",e,M.tokenheader,null),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;nM.fediact_mutesblocks.includes(t))||j(e)||o.some(t=>M.fediact_domainblocks.includes(t.split("@")[1]))?($(t).hide(),i&&$(i).hide(),1):void 0}}(e,t)){var i=function(t){if($(t).is(".detailed-status__wrapper"))return(e=window.location.href.split("?")[0].split("/")).pop()||e.pop();if($(t).attr("data-id"))return $(t).attr("data-id").split("-").slice(-1)[0];if($(t).closest("article[data-id], div[data-id]").length)return $(t).closest("article[data-id], div[data-id]").first().attr("data-id").split("-").slice(-1)[0];if($(t).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)").length){var e=$(t).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)").first();if($(e).attr("href")){t=$(e).attr("href");if(~t.indexOf("interact/"))return(e=t.split("?")[0].split("/")).pop()||e.pop()}}}($(e)),[a,n]=(a=$(e),$(a).find("a.status__relative-time").length?D($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?D($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?D($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var r=[],s=F(o),c=$(e).find("button:has(i.fa-star)").first(),l=($(c).length||(c=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),$(e).find("button:has(i.fa-retweet)").first()),d=($(l).length||(l=$(e).find("a.icon-button:has(i.fa-retweet), a.detailed-status__link:has(i.fa-retweet)")),$(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(),f=$(e).find("div.poll button").first();async function h(t,e,i){if(M.fediact_autoaction){for(var a={choices:[]},n=$(i.currentTarget).closest("div.poll"),o=$(n).find("li"),r=0;rView the results on your home instance.

"),s)&&(q[s][9]=!q[s][9],q[s][9]=!0),t}}async function p(t,e){if(!M.fediact_autoaction)return z("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 U(t,a,null))return s&&(q[s][10]=!0),"boost"==a||"unboost"==a?(W($(e.currentTarget),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),W($(e.currentTarget).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive"),s&&(q[s][3]=!q[s][3])):"favourite"==a||"unfavourite"==a?(W($(e.currentTarget),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),W($(e.currentTarget).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive"),s&&(q[s][4]=!q[s][4])):(W($(e.currentTarget),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),s&&(q[s][5]=!q[s][5])),!0;z("Could not execute action on home instance.")}else z("Could not determine action.")}function g(t){$(e).find(".feditriggered").remove(),t[1]?($(d).removeClass("disabled").removeAttr("disabled"),$(f).removeAttr("disabled"),(M.fediact_showtoot||t[10])&&(t[4]&&!$(c).hasClass("fediactive")&&(W($(c),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),W($(c).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive")),t[3]&&!$(l).find("i.fediactive").length&&(W($(l),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),W($(l).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive")),t[5]&&!$(d).hasClass("fediactive")&&W($(d),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),t[9])&&($(f).hide(),$(f).closest("div.poll").find("ul").replaceWith("

View the results on your home instance.

"))):$("Unresolved").insertAfter($(c))}function m(n){$(u).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),J(n[6]+"?fedireply")}),$([c,l,d,f]).each(function(){$(f).length&&$(f).get(0).isEqualNode($(this).get(0))&&(e=!0);var e,i,a=0;$(this).on("click",async function(t){t.preventDefault(),t.stopImmediatePropagation(),1==++a?i=setTimeout(async function(){(e&&!n[9]?h(n[8],n[6],t):await p(n[2],t))||z("Action failed."),a=0},350):(clearTimeout(i),(e?h(n[8],n[6],t):await p(n[2],t))?J(n[6]):z("Action failed."),a=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(s){var v=q[s];g(v),v[1]&&m(v)}else{if(a&&r.push(n),t){var _,b,w,y=t.match(P),[k,x]=[!1,!1],T=(!y.groups.handledomain||~location.hostname.indexOf(y.groups.handledomain)||(k=!0),[i]);a||T.push(n);for(_ of T=T.filter((t,e)=>void 0!==t&&T.indexOf(t)==e))k?x||((b=await G(location.protocol+"//"+location.hostname+"/"+t+"/"+_))&&(x=!0,r.push(b),I.test(b)?(w=b.match(I)).groups.handle&&w.groups.tootid&&w.groups.domain&&r.push(w.groups.domain+"/@"+w.groups.handle+"/"+w.groups.tootid):P.test(b)&&(w=b.match(P)).groups.handle&&w.groups.tootid&&w.groups.domain&&r.push(w.groups.domain+"/users/"+w.groups.handle+"/statuses/"+w.groups.tootid)),r.push(location.protocol+"//"+location.hostname+"/"+t+"/"+_)):(r.push(location.protocol+"//"+location.hostname+"/users/"+y.groups.handle+"/statuses/"+_),r.push(location.protocol+"//"+location.hostname+"/@"+y.groups.handle+"/"+_))}if(r.length){var A,C,O,N,R,S=!1;for(A of r=r.filter((t,e)=>r.indexOf(t)==e))S||([C,O]=await L(A),C&&(S=!0,N="https://"+M.fediact_homeinstance+"/@"+C[0]+"/"+C[1],R=[o,...C,N,!0,...O,!1]));S?(s=E(R),g(R),m(R)):(z("Failed to resolve: "+r),s=E([o,!1]),g([o,!1]))}else z("Could not identify a post URI for home resolving."),s=E([o,!1]),g([o,!1])}}else z("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 N(){async function e(a){var t,n,o,r,e="follow";async function s(t){return M.fediact_autoaction?(t=await U(t,e,null),"follow"==e&&t?($(a).text("Unfollow"),e="unfollow",!0):"unfollow"==e&&t?($(a).text("Follow"),e="follow",!0):void 0):(z("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()).split("@").length-1==1&&(t=t+"@"+M.fediact_exturi);break}t&&!g.includes(t)&&((n=await A(t))?(g.push(t),M.fediact_showfollows&&(await k([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://"+M.fediact_homeinstance+"/@"+n[1],$(a).text("Redirecting..."),setTimeout(function(){J(i),$(a).text(e)},1e3)):z("Action failed."),o=0)}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})):z("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 x(t){var e,i=[];for(e of t.split(/\r?\n/))(e=e.trim()).length&&(a.test(e)?i.push(e):z("Removed invalid domain "+e+" from blacklist/whitelist."));return[...new Set(i)]}function R(){if(null==M.fediact_homeinstance||!M.fediact_homeinstance)return z("Mastodon home instance is not set."),!1;if(!M.fediact_token)return z("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(M.tokenheader={Authorization:"Bearer "+M.fediact_token},!a.test(M.fediact_homeinstance))return z("Instance setting is not a valid domain name."),!1;if("whitelist"==M.fediact_mode){if(M.fediact_whitelist=x(M.fediact_whitelist),M.fediact_whitelist.length<1)return z("Whitelist is empty or invalid."),!1}else M.fediact_blacklist=x(M.fediact_blacklist);return!0}async function S(){if(location.hostname==M.fediact_homeinstance&&!(p=_("fedireply")))return z("Current site is your home instance."),!1;if("whitelist"==M.fediact_mode){if($.inArray(location.hostname,M.fediact_whitelist)<0)return z("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,M.fediact_blacklist))return z("Current site is in blacklist."),!1;var t=await b("GET",location.protocol+"//"+location.hostname+o,null,null);return!!t&&!(!(t=JSON.parse(t).uri)||(t.startsWith("http")?(t=new URL(t),M.fediact_exturi=t.hostname):M.fediact_exturi=t,D()?!M.fediact_runifloggedin&&await v()&&(z("Already logged in to this external instance."),1):(z("Could not start background process"),1)))}async function D(){chrome.runtime.onMessage.addListener(async function(t,e,i){t.urlchanged&&(q=[],g=[],m=[],await T()||location.reload()),t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){z(t)}return!1}function T(){return new Promise(async function(e){try{M=await(browser||chrome).storage.local.get(t)}catch(t){z(t),e(!1)}M&&R()?e(!0):e(!1)})}async function H(){await T()?await S()?(p?C:(N(),O))():z("Will not process this site."):z("Could not load settings.")}H(); \ No newline at end of file