diff --git a/src/inject.js b/src/inject.js index 90ca0ea..416adec 100644 --- a/src/inject.js +++ b/src/inject.js @@ -575,9 +575,11 @@ function showModal(settings) { function addFediElements() { if (!$(".fediactrunning").length) { if ($("div.ui__header").is(":visible")) { + $("a.ui__header__logo").remove() $("div.ui__header__links").prepend("FediAct running") $("div.ui__header__links").append("Go home") } else if ($("nav.header").length) { + $("nav.header a.brand").remove() $("nav.header div.nav-right").prepend("FediAct running") $("nav.header div.nav-right").append("Go home") } else if ($("div.sign-in-banner").length) { diff --git a/src/inject.min.js b/src/inject.min.js index c54c1dd..4fd3215 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"],u=["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,}$/,S=/^(?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",d="/api/v1/statuses",s="/api/v2/search",l="/api/v1/accounts",r="/api/v1/mutes",c="/api/v1/blocks",f="/api/v1/domain_blocks",p="/api/v1/polls",h=500,_=200,k='
    ',w=15e3;var browser,chrome,q={};const y={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_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1,fediact_runifloggedin:!1,fediact_mutes:[],fediact_blocks:[],fediact_domainblocks:[]},M={fedireply:void 0,lasthomerequest:void 0,whitelist:void 0,blacklist:void 0,exturi:void 0,tokenheader:void 0,processed:[],processedFollow:[],isProcessing:[]};function z(t){e&&console.log(n+" "+t)}function T(){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 A=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{setTimeout(function(){t()},h-e)}),M.lasthomerequest=t),new Promise(function(t){let e=new XMLHttpRequest;if(e.open(a,n),e.timeout=w,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.ontimeout=function(){z("Timed out"),t(!1)},e.onerror=function(){z("Request to "+n+" failed."),t(!1)},s?(e.setRequestHeader("Content-Type","application/json"),e.send(JSON.stringify(s))):e.send()})}function x(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function C(t,e,i){return t.replace(new RegExp(x(e),"g"),i)}function F(t){var e;q.fediact_redirects?q.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,q.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,s,r="POST";switch(e){case"domainblock":a="https://"+q.fediact_homeinstance+f+"?domain="+t,n=function(t){if(t)return!0},s=function(){v()};break;case"domainunblock":a="https://"+q.fediact_homeinstance+f+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=function(){v()};break;case"mute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=function(){v()};break;case"unmute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=function(){v()};break;case"block":a="https://"+q.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=function(){v()};break;case"unblock":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=function(){v()};break;case"vote":a="https://"+q.fediact_homeinstance+p+"/"+t+"/votes",n=function(t){return t.voted},o=i;break;case"follow":a="https://"+q.fediact_homeinstance+l+"/"+t+"/follow",n=function(t){return t.following||t.requested};break;case"boost":a="https://"+q.fediact_homeinstance+d+"/"+t+"/reblog",n=function(t){return t.reblogged};break;case"favourite":a="https://"+q.fediact_homeinstance+d+"/"+t+"/favourite",n=function(t){return t.favourited};break;case"bookmark":a="https://"+q.fediact_homeinstance+d+"/"+t+"/bookmark",n=function(t){return t.bookmarked};break;case"unfollow":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unfollow",n=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+q.fediact_homeinstance+d+"/"+t+"/unreblog",n=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+q.fediact_homeinstance+d+"/"+t+"/unfavourite",n=function(t){return!t.favourited};break;case"unbookmark":a="https://"+q.fediact_homeinstance+d+"/"+t+"/unbookmark",n=function(t){return!t.bookmarked};break;default:z("No valid action specified.")}if(a){var c=await m(r,a,M.tokenheader,o);if(c&&n(JSON.parse(c)))return void 0!==s&&s(),!0}z(e+" action failed.")}async function P(t){var e="https://"+q.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,M.tokenheader,null),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;nt.json()),fetch("https://"+q.fediact_homeinstance+c,{headers:{Authorization:"Bearer "+q.fediact_token}}).then(t=>t.json()),fetch("https://"+q.fediact_homeinstance+f,{headers:{Authorization:"Bearer "+q.fediact_token}}).then(t=>t.json())]);t.length&&q.fediact_mutes.push(...t.map(t=>t.acct)),e.length&&q.fediact_blocks.push(...e.map(t=>t.acct)),i.length&&(q.fediact_domainblocks=i),tt()}function H(t){var i=$(k),e=$(i).find("ul");for(const n of t){var a=n[0].charAt(0).toUpperCase()+n[0].slice(1),a="
  • "+a+"
  • ";$(e).append($(a))}$("body").append($(i)),$("body").on("click",function(t){var e;t.originalEvent.isTrusted&&(!$(t.target).is(".fediactmodal li, .fediactmodal li a")||($(t.target).is(".fediactmodal li")&&(t.target=$(t.target).find("a")),e=$(t.target).attr("fediactaction"),U($(t.target).attr("fediactid"),e,null))?($(i).remove(),$("body").off()):alert("Failed to "+e))})}function Q(){$(".fediactrunning").length||($("div.ui__header").is(":visible")?($("div.ui__header__links").prepend("FediAct running"),$("div.ui__header__links").append("Go home")):$("nav.header").length?($("nav.header div.nav-right").prepend("FediAct running"),$("nav.header div.nav-right").append("Go home")):$("div.sign-in-banner").length&&($("div.sign-in-banner").append("Go home"),$("div.sign-in-banner").append("FediAct running

    ")))}async function N(){$(document).DOMNodeAppear(function(t){$(t.target).find("button:has(i.fa-reply), button:has(i.fa-reply-all)").click()},"div.detailed-status__action-bar")}async function R(){function E(t){var e;return!t.startsWith("http")||(e=new URL(t),location.hostname==e.hostname)?[!1,(t=t.split("/")).pop()||t.pop()]:[!0,t]}async function e(e){Q(),$(e).is("div.detailed-status")&&$(e).closest("div.focusable").length&&(e=$(e).closest("div.focusable"));var t=function(t){if($(t).find("span.display-name__account").length)return $(t).find("span.display-name__account").first().text().trim()}($(e));if(!function(t,e){if(q.fediact_hidemuted){var i,a,n=[],o=($(t).siblings(".status__prepend").length&&(i=$(t).siblings(".status__prepend").first(),$(i).find("a").attr("href"))&&n.push($(i).find("a").attr("href").split("?")[0]),$(t).find("span.h-card").each(function(){n.push($(this).find("a").attr("href").split("?")[0])}),[]);for(a of n){var s,r=a.split("/"),r=(r=r.pop()||r.pop()).slice(1);a.startsWith("http")&&(s=new URL(a)).hostname!=M.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+M.exturi)}return o.some(t=>G(t))||G(e)?($(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?E($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?E($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?E($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var s=[],r=K(o),c=$(e).find("button:has(i.fa-star)").first(),d=($(c).length||(c=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),$("Resolving...").insertAfter($(c)),$(e).find("button:has(i.fa-retweet)").first()),l=($(d).length||(d=$(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(),p=$(e).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first();async function h(t,e,i){if(q.fediact_autoaction){for(var a={choices:[]},n=$(i.currentTarget).closest("div.poll"),o=$(n).find("li"),s=0;sView the results on your home instance.

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

    View the results on your home instance.

    "))):$("Unresolved").insertAfter($(c))}function v(n){var t=n[1].split("@"),e=t.pop()||t.pop();$(u).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&F(n[7]+"?fedireply")}),$(p).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],j(n[1])?t.push(["unblock",n[6]]):t.push(["block",n[6]]),J(n[1])?t.push(["unmute",n[6]]):t.push(["mute",n[6]]),W(n[1])?t.push(["domainunblock",e]):t.push(["domainblock",e]),H(t))}),$([c,d,l,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(),t.originalEvent.isTrusted&&(1==++a?i=setTimeout(async function(){(e&&!n[10]?h(n[9],n[7],t):await m(n[2],t))||z("Action failed."),a=0},350):(clearTimeout(i),(e?h(n[9],n[7],t):await m(n[2],t))?F(n[7]):z("Action failed."),a=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(r){var b=M.processed[r];g(b),b[1]&&v(b)}else{if(a&&s.push(n),t){var _,k,w,y=t.match(S),[T,A]=[!1,!1],x=(!y.groups.handledomain||~location.hostname.indexOf(y.groups.handledomain)||(T=!0),[i]);a||x.push(n);for(_ of x=x.filter((t,e)=>void 0!==t&&x.indexOf(t)==e))T?A||((k=await X(location.protocol+"//"+location.hostname+"/"+t+"/"+_))&&(A=!0,s.push(k),I.test(k)?(w=k.match(I)).groups.handle&&w.groups.tootid&&w.groups.domain&&s.push(w.groups.domain+"/@"+w.groups.handle+"/"+w.groups.tootid):S.test(k)&&(w=k.match(S)).groups.handle&&w.groups.tootid&&w.groups.domain&&s.push(w.groups.domain+"/users/"+w.groups.handle+"/statuses/"+w.groups.tootid)),s.push(location.protocol+"//"+location.hostname+"/"+t+"/"+_)):(s.push(location.protocol+"//"+location.hostname+"/users/"+y.groups.handle+"/statuses/"+_),s.push(location.protocol+"//"+location.hostname+"/@"+y.groups.handle+"/"+_))}if(s.length){var C,P,O,N,R,D=!1;for(C of s=s.filter((t,e)=>s.indexOf(t)==e))D||([P,O]=await V(C),P&&(D=!0,N="https://"+q.fediact_homeinstance+"/@"+P[0]+"/"+P[1],R=[o,...P,N,!0,...O,!1]));D?(r=B(R),g(R),v(R)):(z("Failed to resolve: "+s),r=B([o,!1]),g([o,!1]))}else z("Could not identify a post URI for home resolving."),r=B([o,!1]),g([o,!1])}}else z("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){M.isProcessing.includes($(t.target).get(0))||(M.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){M.isProcessing.includes($(this).get(0))||(M.isProcessing.push($(this).get(0)),e($(this)))})}async function D(){async function e(a){Q();var e,n,t,i,o,s,r="follow",c=$(a).siblings("button:has(i.fa-ellipsis-fw,i.fa-ellipsis-v,i.fa-ellipsis-h)");async function d(t){return q.fediact_autoaction?(t=await U(t,r,null),"follow"==r&&t?($(a).text("Unfollow"),r="unfollow",!0):"unfollow"==r&&t?($(a).text("Follow"),r="follow",!0):void 0):(z("Auto-action disabled."),!0)}if($(a).closest("div.account-card").length)e=$(a).closest("div.account-card").find("div.display-name > span").text().trim();else for(const l of u)if($(l).length){(e=$(l).text().trim()).split("@").length-1==1&&(e=e+"@"+M.exturi);break}e&&!M.processedFollow.includes(e)&&($("Resolving...  ").insertBefore($(a)),(n=await O(e))?(M.processedFollow.push(e),$(c).length&&$(c).removeClass("disabled").removeAttr("disabled"),t=e.split("@"),i=t.pop()||t.pop(),(await P([n[0]]))[0]&&($(a).text("Unfollow"),r="unfollow"),$(c).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],j(e)?t.push(["unblock",n[0]]):t.push(["block",n[0]]),J(e)?t.push(["unmute",n[0]]):t.push(["mute",n[0]]),W(e)?t.push(["domainunblock",i]):t.push(["domainblock",i]),H(t))}),o=0,$(a).on("click",async function(t){var e,i;t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(1==++o?s=setTimeout(async function(){d(n[0]),o=0},350):(clearTimeout(s),await d(n[0])?(e=$(a).text(),i="https://"+q.fediact_homeinstance+"/@"+n[1],$(a).text("Redirecting..."),setTimeout(function(){F(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."),$(a).siblings(".fediactprocessing").remove())}var t=i.join(",");$(document).DOMNodeAppear(async function(t){M.isProcessing.includes($(t.target).get(0))||(M.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){M.isProcessing.includes($(this).get(0))||(M.isProcessing.push($(this).get(0)),e($(this)))})}function t(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 E(){if(null==q.fediact_homeinstance||!q.fediact_homeinstance)return z("Mastodon home instance is not set."),!1;if(!q.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 "+q.fediact_token},!a.test(q.fediact_homeinstance))return z("Instance setting is not a valid domain name."),!1;if("whitelist"==q.fediact_mode){if(M.whitelist=t(q.fediact_whitelist),M.whitelist.length<1)return z("Whitelist is empty or invalid."),!1}else M.blacklist=t(q.fediact_blacklist);return!0}async function Y(){if(location.hostname==q.fediact_homeinstance&&(M.fedireply=A("fedireply"),!M.fedireply))return z("Current site is your home instance."),!1;if("whitelist"==q.fediact_mode){if($.inArray(location.hostname,M.whitelist)<0)return z("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,M.blacklist))return z("Current site is in blacklist."),!1;var t=await m("GET",location.protocol+"//"+location.hostname+o,null,null);return!!t&&!(!(t=JSON.parse(t).uri)||(t.startsWith("http")?(t=new URL(t),M.exturi=t.hostname):M.exturi=t,Z()?!q.fediact_runifloggedin&&!M.fedireply&&await T()&&(z("Already logged in to this external instance."),1):(z("Could not start background process"),1)))}async function Z(){chrome.runtime.onMessage.addListener(async function(t,e,i){t.urlchanged&&(M.processed=[],M.processedFollow=[],M.isProcessing=[],$(".fediactrunning").remove(),$(".fediactgohome").remove(),await b()||location.reload()),t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){z(t)}return!1}function b(){return new Promise(async function(e){try{q=await(browser||chrome).storage.local.get(y)}catch(t){z(t),e(!1)}q&&E()?e(!0):e(!1)})}async function tt(){await(browser||chrome).storage.local.set(q),await b()||location.reload()}async function et(){await b()?await Y()?(M.fedireply?N:(D(),R))():z("Will not process this site."):z("Could not load settings.")}et(); \ 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"],u=["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,}$/,S=/^(?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",d="/api/v1/statuses",s="/api/v2/search",l="/api/v1/accounts",r="/api/v1/mutes",c="/api/v1/blocks",f="/api/v1/domain_blocks",p="/api/v1/polls",h=500,_=200,k='

      ',w=15e3;var browser,chrome,q={};const y={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_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1,fediact_runifloggedin:!1,fediact_mutes:[],fediact_blocks:[],fediact_domainblocks:[]},M={fedireply:void 0,lasthomerequest:void 0,whitelist:void 0,blacklist:void 0,exturi:void 0,tokenheader:void 0,processed:[],processedFollow:[],isProcessing:[]};function z(t){e&&console.log(n+" "+t)}function T(){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 A=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{setTimeout(function(){t()},h-e)}),M.lasthomerequest=t),new Promise(function(t){let e=new XMLHttpRequest;if(e.open(a,n),e.timeout=w,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.ontimeout=function(){z("Timed out"),t(!1)},e.onerror=function(){z("Request to "+n+" failed."),t(!1)},s?(e.setRequestHeader("Content-Type","application/json"),e.send(JSON.stringify(s))):e.send()})}function x(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function C(t,e,i){return t.replace(new RegExp(x(e),"g"),i)}function F(t){var e;q.fediact_redirects?q.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,q.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,s,r="POST";switch(e){case"domainblock":a="https://"+q.fediact_homeinstance+f+"?domain="+t,n=function(t){if(t)return!0},s=function(){v()};break;case"domainunblock":a="https://"+q.fediact_homeinstance+f+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=function(){v()};break;case"mute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=function(){v()};break;case"unmute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=function(){v()};break;case"block":a="https://"+q.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=function(){v()};break;case"unblock":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=function(){v()};break;case"vote":a="https://"+q.fediact_homeinstance+p+"/"+t+"/votes",n=function(t){return t.voted},o=i;break;case"follow":a="https://"+q.fediact_homeinstance+l+"/"+t+"/follow",n=function(t){return t.following||t.requested};break;case"boost":a="https://"+q.fediact_homeinstance+d+"/"+t+"/reblog",n=function(t){return t.reblogged};break;case"favourite":a="https://"+q.fediact_homeinstance+d+"/"+t+"/favourite",n=function(t){return t.favourited};break;case"bookmark":a="https://"+q.fediact_homeinstance+d+"/"+t+"/bookmark",n=function(t){return t.bookmarked};break;case"unfollow":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unfollow",n=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+q.fediact_homeinstance+d+"/"+t+"/unreblog",n=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+q.fediact_homeinstance+d+"/"+t+"/unfavourite",n=function(t){return!t.favourited};break;case"unbookmark":a="https://"+q.fediact_homeinstance+d+"/"+t+"/unbookmark",n=function(t){return!t.bookmarked};break;default:z("No valid action specified.")}if(a){var c=await m(r,a,M.tokenheader,o);if(c&&n(JSON.parse(c)))return void 0!==s&&s(),!0}z(e+" action failed.")}async function P(t){var e="https://"+q.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,M.tokenheader,null),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;nt.json()),fetch("https://"+q.fediact_homeinstance+c,{headers:{Authorization:"Bearer "+q.fediact_token}}).then(t=>t.json()),fetch("https://"+q.fediact_homeinstance+f,{headers:{Authorization:"Bearer "+q.fediact_token}}).then(t=>t.json())]);t.length&&q.fediact_mutes.push(...t.map(t=>t.acct)),e.length&&q.fediact_blocks.push(...e.map(t=>t.acct)),i.length&&(q.fediact_domainblocks=i),tt()}function H(t){var i=$(k),e=$(i).find("ul");for(const n of t){var a=n[0].charAt(0).toUpperCase()+n[0].slice(1),a="
    • "+a+"
    • ";$(e).append($(a))}$("body").append($(i)),$("body").on("click",function(t){var e;t.originalEvent.isTrusted&&(!$(t.target).is(".fediactmodal li, .fediactmodal li a")||($(t.target).is(".fediactmodal li")&&(t.target=$(t.target).find("a")),e=$(t.target).attr("fediactaction"),U($(t.target).attr("fediactid"),e,null))?($(i).remove(),$("body").off()):alert("Failed to "+e))})}function Q(){$(".fediactrunning").length||($("div.ui__header").is(":visible")?($("a.ui__header__logo").remove(),$("div.ui__header__links").prepend("FediAct running"),$("div.ui__header__links").append("Go home")):$("nav.header").length?($("nav.header a.brand").remove(),$("nav.header div.nav-right").prepend("FediAct running"),$("nav.header div.nav-right").append("Go home")):$("div.sign-in-banner").length&&($("div.sign-in-banner").append("Go home"),$("div.sign-in-banner").append("FediAct running

      ")))}async function N(){$(document).DOMNodeAppear(function(t){$(t.target).find("button:has(i.fa-reply), button:has(i.fa-reply-all)").click()},"div.detailed-status__action-bar")}async function R(){function E(t){var e;return!t.startsWith("http")||(e=new URL(t),location.hostname==e.hostname)?[!1,(t=t.split("/")).pop()||t.pop()]:[!0,t]}async function e(e){Q(),$(e).is("div.detailed-status")&&$(e).closest("div.focusable").length&&(e=$(e).closest("div.focusable"));var t=function(t){if($(t).find("span.display-name__account").length)return $(t).find("span.display-name__account").first().text().trim()}($(e));if(!function(t,e){if(q.fediact_hidemuted){var i,a,n=[],o=($(t).siblings(".status__prepend").length&&(i=$(t).siblings(".status__prepend").first(),$(i).find("a").attr("href"))&&n.push($(i).find("a").attr("href").split("?")[0]),$(t).find("span.h-card").each(function(){n.push($(this).find("a").attr("href").split("?")[0])}),[]);for(a of n){var s,r=a.split("/"),r=(r=r.pop()||r.pop()).slice(1);a.startsWith("http")&&(s=new URL(a)).hostname!=M.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+M.exturi)}return o.some(t=>G(t))||G(e)?($(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?E($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?E($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?E($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var s=[],r=K(o),c=$(e).find("button:has(i.fa-star)").first(),d=($(c).length||(c=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),$("Resolving...").insertAfter($(c)),$(e).find("button:has(i.fa-retweet)").first()),l=($(d).length||(d=$(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(),p=$(e).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first();async function h(t,e,i){if(q.fediact_autoaction){for(var a={choices:[]},n=$(i.currentTarget).closest("div.poll"),o=$(n).find("li"),s=0;sView the results on your home instance.

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

      View the results on your home instance.

      "))):$("Unresolved").insertAfter($(c))}function v(n){var t=n[1].split("@"),e=t.pop()||t.pop();$(u).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&F(n[7]+"?fedireply")}),$(p).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],j(n[1])?t.push(["unblock",n[6]]):t.push(["block",n[6]]),J(n[1])?t.push(["unmute",n[6]]):t.push(["mute",n[6]]),W(n[1])?t.push(["domainunblock",e]):t.push(["domainblock",e]),H(t))}),$([c,d,l,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(),t.originalEvent.isTrusted&&(1==++a?i=setTimeout(async function(){(e&&!n[10]?h(n[9],n[7],t):await m(n[2],t))||z("Action failed."),a=0},350):(clearTimeout(i),(e?h(n[9],n[7],t):await m(n[2],t))?F(n[7]):z("Action failed."),a=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(r){var b=M.processed[r];g(b),b[1]&&v(b)}else{if(a&&s.push(n),t){var _,k,w,y=t.match(S),[T,A]=[!1,!1],x=(!y.groups.handledomain||~location.hostname.indexOf(y.groups.handledomain)||(T=!0),[i]);a||x.push(n);for(_ of x=x.filter((t,e)=>void 0!==t&&x.indexOf(t)==e))T?A||((k=await X(location.protocol+"//"+location.hostname+"/"+t+"/"+_))&&(A=!0,s.push(k),I.test(k)?(w=k.match(I)).groups.handle&&w.groups.tootid&&w.groups.domain&&s.push(w.groups.domain+"/@"+w.groups.handle+"/"+w.groups.tootid):S.test(k)&&(w=k.match(S)).groups.handle&&w.groups.tootid&&w.groups.domain&&s.push(w.groups.domain+"/users/"+w.groups.handle+"/statuses/"+w.groups.tootid)),s.push(location.protocol+"//"+location.hostname+"/"+t+"/"+_)):(s.push(location.protocol+"//"+location.hostname+"/users/"+y.groups.handle+"/statuses/"+_),s.push(location.protocol+"//"+location.hostname+"/@"+y.groups.handle+"/"+_))}if(s.length){var C,P,O,N,R,D=!1;for(C of s=s.filter((t,e)=>s.indexOf(t)==e))D||([P,O]=await V(C),P&&(D=!0,N="https://"+q.fediact_homeinstance+"/@"+P[0]+"/"+P[1],R=[o,...P,N,!0,...O,!1]));D?(r=B(R),g(R),v(R)):(z("Failed to resolve: "+s),r=B([o,!1]),g([o,!1]))}else z("Could not identify a post URI for home resolving."),r=B([o,!1]),g([o,!1])}}else z("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){M.isProcessing.includes($(t.target).get(0))||(M.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){M.isProcessing.includes($(this).get(0))||(M.isProcessing.push($(this).get(0)),e($(this)))})}async function D(){async function e(a){Q();var e,n,t,i,o,s,r="follow",c=$(a).siblings("button:has(i.fa-ellipsis-fw,i.fa-ellipsis-v,i.fa-ellipsis-h)");async function d(t){return q.fediact_autoaction?(t=await U(t,r,null),"follow"==r&&t?($(a).text("Unfollow"),r="unfollow",!0):"unfollow"==r&&t?($(a).text("Follow"),r="follow",!0):void 0):(z("Auto-action disabled."),!0)}if($(a).closest("div.account-card").length)e=$(a).closest("div.account-card").find("div.display-name > span").text().trim();else for(const l of u)if($(l).length){(e=$(l).text().trim()).split("@").length-1==1&&(e=e+"@"+M.exturi);break}e&&!M.processedFollow.includes(e)&&($("Resolving...  ").insertBefore($(a)),(n=await O(e))?(M.processedFollow.push(e),$(c).length&&$(c).removeClass("disabled").removeAttr("disabled"),t=e.split("@"),i=t.pop()||t.pop(),(await P([n[0]]))[0]&&($(a).text("Unfollow"),r="unfollow"),$(c).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],j(e)?t.push(["unblock",n[0]]):t.push(["block",n[0]]),J(e)?t.push(["unmute",n[0]]):t.push(["mute",n[0]]),W(e)?t.push(["domainunblock",i]):t.push(["domainblock",i]),H(t))}),o=0,$(a).on("click",async function(t){var e,i;t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(1==++o?s=setTimeout(async function(){d(n[0]),o=0},350):(clearTimeout(s),await d(n[0])?(e=$(a).text(),i="https://"+q.fediact_homeinstance+"/@"+n[1],$(a).text("Redirecting..."),setTimeout(function(){F(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."),$(a).siblings(".fediactprocessing").remove())}var t=i.join(",");$(document).DOMNodeAppear(async function(t){M.isProcessing.includes($(t.target).get(0))||(M.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){M.isProcessing.includes($(this).get(0))||(M.isProcessing.push($(this).get(0)),e($(this)))})}function t(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 E(){if(null==q.fediact_homeinstance||!q.fediact_homeinstance)return z("Mastodon home instance is not set."),!1;if(!q.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 "+q.fediact_token},!a.test(q.fediact_homeinstance))return z("Instance setting is not a valid domain name."),!1;if("whitelist"==q.fediact_mode){if(M.whitelist=t(q.fediact_whitelist),M.whitelist.length<1)return z("Whitelist is empty or invalid."),!1}else M.blacklist=t(q.fediact_blacklist);return!0}async function Y(){if(location.hostname==q.fediact_homeinstance&&(M.fedireply=A("fedireply"),!M.fedireply))return z("Current site is your home instance."),!1;if("whitelist"==q.fediact_mode){if($.inArray(location.hostname,M.whitelist)<0)return z("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,M.blacklist))return z("Current site is in blacklist."),!1;var t=await m("GET",location.protocol+"//"+location.hostname+o,null,null);return!!t&&!(!(t=JSON.parse(t).uri)||(t.startsWith("http")?(t=new URL(t),M.exturi=t.hostname):M.exturi=t,Z()?!q.fediact_runifloggedin&&!M.fedireply&&await T()&&(z("Already logged in to this external instance."),1):(z("Could not start background process"),1)))}async function Z(){chrome.runtime.onMessage.addListener(async function(t,e,i){t.urlchanged&&(M.processed=[],M.processedFollow=[],M.isProcessing=[],$(".fediactrunning").remove(),$(".fediactgohome").remove(),await b()||location.reload()),t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){z(t)}return!1}function b(){return new Promise(async function(e){try{q=await(browser||chrome).storage.local.get(y)}catch(t){z(t),e(!1)}q&&E()?e(!0):e(!1)})}async function tt(){await(browser||chrome).storage.local.set(q),await b()||location.reload()}async function et(){await b()?await Y()?(M.fedireply?N:(D(),R))():z("Will not process this site."):z("Could not load settings.")}et(); \ No newline at end of file