From f23e7be502269f68d89c861ce93ae75fdfde183e Mon Sep 17 00:00:00 2001 From: lartsch Date: Thu, 29 Dec 2022 10:10:59 -0500 Subject: [PATCH] improve 429 prevention (async limit), add ua --- src/background.js | 8 +++++++- src/background.min.js | 2 +- src/inject.js | 34 ++++++++++++++++++++++++++-------- src/inject.min.js | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/background.js b/src/background.js index d888102..f3a6ac3 100644 --- a/src/background.js +++ b/src/background.js @@ -53,14 +53,19 @@ async function generalRequest(data) { controller.abort() }, timeout) if (data[3]) { + // json body provided, post as body to target + data[2]["User-Agent"] = "FediAct Service" data[2]["Content-Type"] = "application/json" var res = await fetch(data[1], { method: data[0], signal: controller.signal, + // if json body is provided, there is also header data headers: data[2], body: JSON.stringify(data[3]) }) } else if (data[2]) { + // header data provided + data[2]["User-Agent"] = "FediAct Service" var res = await fetch(data[1], { method: data[0], signal: controller.signal, @@ -69,7 +74,8 @@ async function generalRequest(data) { } else { var res = await fetch(data[1], { method: data[0], - signal: controller.signal + signal: controller.signal, + headers: {"User-Agent": "FediAct Service"} }) } clearTimeout(timeoutId) diff --git a/src/background.min.js b/src/background.min.js index fea6515..466307b 100644 --- a/src/background.min.js +++ b/src/background.min.js @@ -1 +1 @@ -var browser,chrome,c;const a=!1,n="[FediAct]",t=1,i="/api/v1/mutes",o="/api/v1/blocks",s="/api/v1/domain_blocks",r=15e3,d=/"access_token":".*?",/gm,u={fediact_homeinstance:null,fediact_token:null};function h(t){a&&console.log(n+" "+t)}async function f(i){return new Promise(async function(e){try{const n=new AbortController;var t=setTimeout(()=>{h("Timed out"),n.abort()},r),a=await fetch(i,{method:"HEAD",signal:n.signal});clearTimeout(t),a.redirected?e(a.url):e(!1)}catch(t){h(t),e(!1)}})}async function l(c){return new Promise(async function(e){try{const i=new AbortController;var t,a,n=setTimeout(()=>{h("Timed out"),i.abort()},r);t=c[3]?(c[2]["Content-Type"]="application/json",await fetch(c[1],{method:c[0],signal:i.signal,headers:c[2],body:JSON.stringify(c[3])})):c[2]?await fetch(c[1],{method:c[0],signal:i.signal,headers:c[2]}):await fetch(c[1],{method:c[0],signal:i.signal}),clearTimeout(n),200<=t.status&&t.status<300&&(a=t.headers.get("content-type"))&&-1!==a.indexOf("application/json")?e(await t.text()):e(!1)}catch(t){h(t),e(!1)}})}async function m(){return new Promise(async function(e){var t="https://"+c.fediact_homeinstance;try{var a=await(await fetch(t)).text()}catch(t){return h(t),void e(!1)}if(a){t=a.match(d);if(t){var a=t[0].search(/"access_token":"/),n=t[0].search(/",/);if(-1t.json()),fetch("https://"+c.fediact_homeinstance+o,{headers:{Authorization:"Bearer "+c.fediact_token}}).then(t=>t.json()),fetch("https://"+c.fediact_homeinstance+s,{headers:{Authorization:"Bearer "+c.fediact_token}}).then(t=>t.json())]);e.length&&c.fediact_mutes.push(...e.map(t=>t.acct)),a.length&&c.fediact_blocks.push(...a.map(t=>t.acct)),n.length&&(c.fediact_domainblocks=n),t(!0)}catch{t(!1)}})}async function y(n,i){return new Promise(async function(t){var a=!1;try{if((c=await(browser||chrome).storage.local.get(u)).fediact_homeinstance){if(n||i){!n&&c.fediact_token||await m(),i&&await g();try{await(browser||chrome).storage.local.set(c),a=!0}catch{h(e)}}}else h("Home instance not set")}catch(t){h(t)}t(a)})}async function p(){chrome.tabs.query({},async function(t){for(var e=0;et.externaltoot?(f(t.externaltoot).then(e),!0):t.requestdata?(l(t.requestdata).then(e),!0):t.updatedsettings?(y(!0,!0).then(p),!0):t.updatemutedblocked?(y(!1,!0).then(e),!0):void(t.running&&chrome.tabs.onUpdated.addListener(async function(t,e,a){if(t===n.tab.id&&e.url)try{await chrome.tabs.sendMessage(t,{urlchanged:e.url})}catch(t){h(t)}}))); \ No newline at end of file +var browser,chrome,c;const a=!1,n="[FediAct]",t=1,i="/api/v1/mutes",s="/api/v1/blocks",o="/api/v1/domain_blocks",r=15e3,d=/"access_token":".*?",/gm,u={fediact_homeinstance:null,fediact_token:null};function h(t){a&&console.log(n+" "+t)}async function f(i){return new Promise(async function(e){try{const n=new AbortController;var t=setTimeout(()=>{h("Timed out"),n.abort()},r),a=await fetch(i,{method:"HEAD",signal:n.signal});clearTimeout(t),a.redirected?e(a.url):e(!1)}catch(t){h(t),e(!1)}})}async function l(c){return new Promise(async function(e){try{const i=new AbortController;var t,a,n=setTimeout(()=>{h("Timed out"),i.abort()},r);t=c[3]?(c[2]["User-Agent"]="FediAct Service",c[2]["Content-Type"]="application/json",await fetch(c[1],{method:c[0],signal:i.signal,headers:c[2],body:JSON.stringify(c[3])})):c[2]?(c[2]["User-Agent"]="FediAct Service",await fetch(c[1],{method:c[0],signal:i.signal,headers:c[2]})):await fetch(c[1],{method:c[0],signal:i.signal,headers:{"User-Agent":"FediAct Service"}}),clearTimeout(n),200<=t.status&&t.status<300&&(a=t.headers.get("content-type"))&&-1!==a.indexOf("application/json")?e(await t.text()):e(!1)}catch(t){h(t),e(!1)}})}async function m(){return new Promise(async function(e){var t="https://"+c.fediact_homeinstance;try{var a=await(await fetch(t)).text()}catch(t){return h(t),void e(!1)}if(a){t=a.match(d);if(t){var a=t[0].search(/"access_token":"/),n=t[0].search(/",/);if(-1t.json()),fetch("https://"+c.fediact_homeinstance+s,{headers:{Authorization:"Bearer "+c.fediact_token}}).then(t=>t.json()),fetch("https://"+c.fediact_homeinstance+o,{headers:{Authorization:"Bearer "+c.fediact_token}}).then(t=>t.json())]);e.length&&c.fediact_mutes.push(...e.map(t=>t.acct)),a.length&&c.fediact_blocks.push(...a.map(t=>t.acct)),n.length&&(c.fediact_domainblocks=n),t(!0)}catch{t(!1)}})}async function y(n,i){return new Promise(async function(t){var a=!1;try{if((c=await(browser||chrome).storage.local.get(u)).fediact_homeinstance){if(n||i){!n&&c.fediact_token||await m(),i&&await g();try{await(browser||chrome).storage.local.set(c),a=!0}catch{h(e)}}}else h("Home instance not set")}catch(t){h(t)}t(a)})}async function p(){chrome.tabs.query({},async function(t){for(var e=0;et.externaltoot?(f(t.externaltoot).then(e),!0):t.requestdata?(l(t.requestdata).then(e),!0):t.updatedsettings?(y(!0,!0).then(p),!0):t.updatemutedblocked?(y(!1,!0).then(e),!0):void(t.running&&chrome.tabs.onUpdated.addListener(async function(t,e,a){if(t===n.tab.id&&e.url)try{await chrome.tabs.sendMessage(t,{urlchanged:e.url})}catch(t){h(t)}}))); \ No newline at end of file diff --git a/src/inject.js b/src/inject.js index 7a3557d..704d4ad 100644 --- a/src/inject.js +++ b/src/inject.js @@ -17,9 +17,10 @@ const mutesApi = "/api/v1/mutes" const blocksApi = "/api/v1/blocks" const domainBlocksApi = "/api/v1/domain_blocks" const pollsApi = "/api/v1/polls" -const apiDelay = 650 +const apiDelay = 600 const maxTootCache = 200 const modalHtml = '
    ' +const maxAsyncRequests = 10 // settings keys with defauls var settings = {} @@ -124,13 +125,27 @@ var getUrlParameter = function getUrlParameter(sParam) { return false } +const asyncLimit = (fn, n) => { + let pendingPromises = [] + return async function (...args) { + while (pendingPromises.length >= n) { + await Promise.race(pendingPromises).catch(() => {}) + } + const p = fn.apply(this, args) + pendingPromises.push(p) + await p.catch(() => {}) + pendingPromises = pendingPromises.filter(pending => pending !== p) + return p + } + } + // promisified xhr for api calls function makeRequest(method, url, extraheaders, jsonbody) { return new Promise(async function(resolve) { + // get current time + var currenttime = Date.now() // try to prevent error 429 too many request by delaying home instance requests if (~url.indexOf(settings.fediact_homeinstance) && settings.fediact_enabledelay) { - // get current time - var currenttime = Date.now() // get difference of current time and time of last request var difference = currenttime - tmpSettings.lasthomerequest // if difference is smaller than our set api delay value... @@ -162,6 +177,9 @@ function makeRequest(method, url, extraheaders, jsonbody) { }) } +// wrap so there are never more than 10 concurrent requests +const requestAsyncLimited = asyncLimit(makeRequest, maxAsyncRequests) + // Escape characters used for regex function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string @@ -283,7 +301,7 @@ async function executeAction(data, action, polldata) { return } if (requestUrl) { - var response = await makeRequest(method, requestUrl, tmpSettings.tokenheader, jsonbody) + var response = await requestAsyncLimited(method, requestUrl, tmpSettings.tokenheader, jsonbody) if (response) { // convert to json object response = JSON.parse(response) @@ -307,7 +325,7 @@ async function isFollowingHomeInstance(ids) { requestUrl += "id[]=" + id.toString() + "&" } // make the request - var responseFollowing = await makeRequest("GET", requestUrl, tmpSettings.tokenheader, null) + var responseFollowing = await requestAsyncLimited("GET", requestUrl, tmpSettings.tokenheader, null) // fill response array according to id amount with false const follows = Array(ids.length).fill(false) // parse the response @@ -379,7 +397,7 @@ function checkAllMutedBlocked(handle) { // Return the user id on the users home instance async function resolveHandleToHome(handle) { var requestUrl = 'https://' + settings.fediact_homeinstance + accountsApi + "/search?q=" + handle + "&resolve=true&limit=1&exclude_unreviewed=false" - var searchResponse = await makeRequest("GET", requestUrl, tmpSettings.tokenheader, null) + var searchResponse = await requestAsyncLimited("GET", requestUrl, tmpSettings.tokenheader, null) if (searchResponse) { searchResponse = JSON.parse(searchResponse) if (searchResponse[0].id) { @@ -393,7 +411,7 @@ async function resolveHandleToHome(handle) { // resolve a toot to the users home instance async function resolveTootToHome(searchstring) { var requestUrl = 'https://' + settings.fediact_homeinstance + searchApi + "/?q=" + searchstring + "&resolve=true&limit=1&exclude_unreviewed=false" - var response = await makeRequest("GET", requestUrl, tmpSettings.tokenheader, null) + var response = await requestAsyncLimited("GET", requestUrl, tmpSettings.tokenheader, null) if (response) { response = JSON.parse(response) // do we have a status as result? @@ -1471,7 +1489,7 @@ async function checkSite() { // last check - and probably the most accurate to determine if it actually is mastadon var requestUrl = location.protocol + '//' + location.hostname + instanceApi // call instance api to confirm its mastodon and get normalized handle uri - var response = await makeRequest("GET", requestUrl, null, null) + var response = await requestAsyncLimited("GET", requestUrl, null, null) // todo: add basic check for "mastodon" string in response if (response) { var uri = JSON.parse(response).uri diff --git a/src/inject.min.js b/src/inject.min.js index f048f69..c208aff 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.directory__card a.icon-button","div.detailed-status a.logo-button","button.remote-button","div.account__header button.button--follow"],p=["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,}$/,M=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,F=/^(?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",_="/api/v1/mutes",w="/api/v1/blocks",u="/api/v1/domain_blocks",f="/api/v1/polls",r=650,c=200,h='
      ';var browser,chrome,q={};const k={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:[]},z={fedireply:void 0,lasthomerequest:void 0,whitelist:void 0,blacklist:void 0,exturi:void 0,tokenheader:void 0,processed:[],processedFollow:[],isProcessing:[]};function L(t){e&&console.log(n+" "+t)}function y(){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 x=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{setTimeout(function(){t()},r-i)}),z.lasthomerequest=Date.now());try{await chrome.runtime.sendMessage({requestdata:[t,a,n,o]},function(t){e(t||!1)})}catch(t){L(t),L("Reloading page, extension likely got updated or reloaded."),location.reload()}})}function T(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function C(t,e,i){return t.replace(new RegExp(T(e),"g"),i)}function W(t){var e;q.fediact_redirects?q.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,q.fediact_target),L("Redirected to "+t),e?e.focus():L("Could not open new window. Please allow popups for this website.")):L("Redirects disabled.")}async function J(t,e,i){var a,n,o,s,r="POST";switch(e){case"copy":return navigator.clipboard.writeText(t),!0;case"domainblock":a="https://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},s=async function(){await v()};break;case"domainunblock":a="https://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=async function(){await v()};break;case"mute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=async function(){await v()};break;case"unmute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=async function(){await v()};break;case"block":a="https://"+q.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=async function(){await v()};break;case"unblock":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=async function(){await v()};break;case"vote":a="https://"+q.fediact_homeinstance+f+"/"+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:return void L("No valid action specified.")}if(a){var c=await m(r,a,z.tokenheader,o);if(c&&n(JSON.parse(c)))return void 0!==s&&await s(),!0}L(e+" action failed.")}async function A(t){var e="https://"+q.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,z.tokenheader,null),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;n"+n[2]+"";$(e).append($(i))}$("body").append($(a)),$("body").on("click",async function t(e){var i;e.originalEvent.isTrusted&&($(e.target).is(".fediactmodal li, .fediactmodal li *")?($(e.target).is(".fediactmodal li a")||($(e.target).find("a").length?e.target=$(e.target).find("a"):e.target=$(e.target).closest("a")),i=$(e.target).attr("fediactaction"),await J($(e.target).attr("fediactdata"),i,null)?($(e.target).addClass("activated"),$(e.target).append("Done!"),$(a).css("animation","fadeOut .2s .7s forwards"),$(a).find(".fediactmodalinner").css("animation","scaleInFade .2s .7s forwards reverse"),await new Promise(t=>{setTimeout(function(){t()},1e3)})):($(e.target).css("--confirmation","red"),$(e.target).addClass("activated"),$(e.target).append("Failed"),$(a).css("animation","fadeOut .2s .7s forwards"),$(a).find(".fediactmodalinner").css("animation","scaleInFade .2s .7s forwards reverse"),await new Promise(t=>{setTimeout(function(){t()},1e3)})),$(a).remove(),$("body").off("click",t)):$(e.target).is(".fediactmodalinner")?$.noop():($(a).remove(),$("body").off("click",t)))})}function K(){$(".fediacticon").length||($("body").append("
      "),$("body").append(""),$("body").on("click",function(t){try{t.originalEvent.isTrusted&&($(t.target).is("div.fediacticon")?($("div.fediacticon").hide(),$("div.fediactsettings_onsite")):($("div.fediactsettings_onsite").hide(),$("div.fediacticon"))).show()}catch{$.noop()}}))}async function O(){$(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 D(){function R(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){K(),$(e).is("div.detailed-status")&&$(e).closest("div.focusable").length&&(i=!0,e=$(e).closest("div.focusable"));var i,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!=z.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+z.exturi)}return o.some(t=>Q(t))||Q(e)?($(t).hide(),i&&$(i).hide(),1):void 0}}(e,t)){var a=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)),[n,o]=(n=$(e),$(n).find("a.status__relative-time").length?R($(n).find("a.status__relative-time").first().attr("href").split("?")[0]):$(n).find("a.detailed-status__datetime").length?R($(n).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(n).find("a.modal-button").length?R($(n).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),s=a||o;if(s){var r=[],c=!1,d=tt(s),l=$(e).find("button:has(i.fa-star)").first(),u=($(l).length||(l=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),i?$("
      ").insertAfter($(l).parent()):$("").insertAfter($(l)),$(e).find("button:has(i.fa-retweet)").first()),f=($(u).length||(u=$(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()),p=$(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(),h=$(e).find('button[class*="show-more"]').first(),m=$(e).find("div.poll button").first(),g=($(h).length&&($(h).click(),$(e).find("div.poll").length&&(c=!0),$(h).click()),$(e).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first());async function v(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.

      "),d)&&(z.processed[d][10]=!0,z.processed[d][11]=!0),t}}async function b(t,e){if(!q.fediact_autoaction)return L("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 J(t,a,null))return d&&(z.processed[d][11]=!0),"boost"==a||"unboost"==a?(V($(e.currentTarget),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),V($(e.currentTarget).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive"),d&&(z.processed[d][3]=!z.processed[d][3])):"favourite"==a||"unfavourite"==a?(V($(e.currentTarget),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),V($(e.currentTarget).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive"),d&&(z.processed[d][4]=!z.processed[d][4])):(V($(e.currentTarget),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),d&&(z.processed[d][5]=!z.processed[d][5])),!0;L("Could not execute action on home instance.")}else L("Could not determine action.")}function _(t){$(e).find(".fediactunresolveddetailed, .fediactunresolved").remove(),$(e).find(".fediactprocessingdetailed, .fediactprocessing").remove(),t[1]?($(f).removeClass("disabled").removeAttr("disabled"),$(g).removeClass("disabled").removeAttr("disabled"),t[13]&&($(h).click(),$(h).find("span").text("Show less"),m=$(e).find("div.poll button").first(),$(h).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation();t=$(h).find("span");"Show less"==$(t).text()?$(t).text("Show more"):$(t).text("Show less"),V($(e).find("div.poll").first(),[["display","block","none"]],"fedihideshow"),V($(e).find("div.status__content__text").first(),[["display","block","none"]],"fedihideshow")}),$(h).click()),$(m).removeAttr("disabled"),t[4]&&!$(l).hasClass("fediactive")&&(V($(l),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),V($(l).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive")),t[3]&&!$(u).find("i.fediactive").length&&(V($(u),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),V($(u).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive")),t[5]&&!$(f).hasClass("fediactive")&&V($(f),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),t[10]&&($(m).hide(),$(m).closest("div.poll").find("ul").replaceWith("

      View the results on your home instance.

      "))):i?$("

      X
      ").insertAfter($(l).parent()):$("X").insertAfter($(l))}function w(n){var t=n[1].split("@"),e=t.pop()||t.pop();$(p).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&W(n[7]+"?fedireply")}),$(g).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],B(n[1])?t.push(["unblock",n[6],"Unblock user"]):t.push(["block",n[6],"Block user"]),G(n[1])?t.push(["unmute",n[6],"Unmute user"]):t.push(["mute",n[6],"Mute user"]),j(n[1])?t.push(["domainunblock",e,"Unblock domain"]):t.push(["domainblock",e,"Block domain"]),t.push(["copy",n[12],"Copy URL"]),t.push(["copy",n[7],"Copy home URL"]),H(t))}),$([l,u,f,m]).each(function(){$(m).length&&$(m).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]?v(n[9],n[7],t):await b(n[2],t))||L("Action failed."),a=0},350):(clearTimeout(i),(e?v(n[9],n[7],t):await b(n[2],t))?W(n[7]):L("Action failed."),a=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(d){var k=z.processed[d];_(k),k[1]&&w(k)}else{if(n&&r.push(o),t){var y,x,T,C=t.match(M),[A,P]=[!1,!1],O=(!C.groups.handledomain||~location.hostname.indexOf(C.groups.handledomain)||(A=!0),[a]);n||O.push(o);for(y of O=O.filter((t,e)=>void 0!==t&&O.indexOf(t)==e))A?P||((x=await Z(location.protocol+"//"+location.hostname+"/"+t+"/"+y))&&(P=!0,r.push(x),F.test(x)?(T=x.match(F)).groups.handle&&T.groups.tootid&&T.groups.domain&&r.push(T.groups.domain+"/@"+T.groups.handle+"/"+T.groups.tootid):M.test(x)&&(T=x.match(M)).groups.handle&&T.groups.tootid&&T.groups.domain&&r.push(T.groups.domain+"/users/"+T.groups.handle+"/statuses/"+T.groups.tootid)),r.push(location.protocol+"//"+location.hostname+"/"+t+"/"+y)):(r.push(location.protocol+"//"+location.hostname+"/users/"+C.groups.handle+"/statuses/"+y),r.push(location.protocol+"//"+location.hostname+"/@"+C.groups.handle+"/"+y))}if(r.length){var D,S,U,E,I,N=!1;for(D of r=r.filter((t,e)=>r.indexOf(t)==e))N||([S,U]=await Y(D),S&&(N=!0,E="https://"+q.fediact_homeinstance+"/@"+S[0]+"/"+S[1],I=[s,...S,E,!0,...U,!1,D,c]));N?(d=X(I),_(I),w(I)):(L("Failed to resolve: "+r),d=X([s,!1]),_([s,!1]))}else L("Could not identify a post URI for home resolving."),d=X([s,!1]),_([s,!1])}}else L("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){z.isProcessing.includes($(t.target).get(0))||(z.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){z.isProcessing.includes($(this).get(0))||(z.isProcessing.push($(this).get(0)),e($(this)))})}async function S(){async function e(a){K();var e,n,o,t,i,s,r,c,d="follow",l=$(a).siblings("button:has(i.fa-ellipsis-fw,i.fa-ellipsis-v,i.fa-ellipsis-h)");async function u(t){return q.fediact_autoaction?(t=await J(t,d,null),"follow"==d&&t?($(n).length?($(n).removeClass("fa-user-plus").addClass("fa-user"),$(a).append("-"),$(a).attr("title","Unfollow")):$(a).text("Unfollow"),d="unfollow",!0):"unfollow"==d&&t?($(n).length?($(n).removeClass("fa-user").addClass("fa-user-plus"),$(a).contents().filter((t,e)=>3===e.nodeType).remove(),$(a).attr("title","Follow")):$(a).text("Follow"),d="follow",!0):void 0):(L("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 if($(a).closest("div.directory__card").length)e=$(a).closest("div.directory__card").find("div.display-name > span").text().trim(),n=$(a).find("i").first();else for(const f of p)if($(f).length){(e=$(f).text().trim()).split("@").length-1==1&&(e=e+"@"+z.exturi);break}e&&!z.processedFollow.includes(e)&&($("").insertBefore($(a)),(o=await P(e))?(z.processedFollow.push(e),$(l).length&&$(l).removeClass("disabled").removeAttr("disabled"),t=e.split("@"),i=t.pop()||t.pop(),s="https://"+q.fediact_homeinstance+"/@"+o[1],(await A([o[0]]))[0]&&($(n).length?($(n).removeClass("fa-user-plus").addClass("fa-user"),$(a).append("-"),$(a).attr("title","Unfollow")):$(a).text("Unfollow"),d="unfollow"),$(l).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],B(e)?t.push(["unblock",o[0],"Unblock user"]):t.push(["block",o[0],"Block user"]),G(e)?t.push(["unmute",o[0],"Unmute user"]):t.push(["mute",o[0],"Mute user"]),j(e)?t.push(["domainunblock",i,"Unblock domain"]):t.push(["domainblock",i,"Block domain"]),t.push(["copy",s,"Copy home URL"]),H(t))}),r=0,$(a).on("click",async function(t){var e,i;t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(1==++r?c=setTimeout(async function(){u(o[0]),r=0},350):(clearTimeout(c),await u(o[0])?($(n).length?(e=$(n).attr("class"),$(n).removeClass("fa-user").removeClass("fa-user-plus").addClass("fa-arrow-right")):(i=$(a).text(),$(a).text("Redirecting...")),setTimeout(function(){W(s),$(n).length?$(n).attr("class",e):$(a).text(i)},1e3)):L("Action failed."),r=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})):L("Could not resolve user home ID."),$(a).siblings(".fediactprocessing").remove())}var t=i.join(",");$(document).DOMNodeAppear(async function(t){z.isProcessing.includes($(t.target).get(0))||(z.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){z.isProcessing.includes($(this).get(0))||(z.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):L("Removed invalid domain "+e+" from blacklist/whitelist."));return[...new Set(i)]}function U(){if(null==q.fediact_homeinstance||!q.fediact_homeinstance)return L("Mastodon home instance is not set."),!1;if(!q.fediact_token)return L("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(z.tokenheader={Authorization:"Bearer "+q.fediact_token},!a.test(q.fediact_homeinstance))return L("Instance setting is not a valid domain name."),!1;if("whitelist"==q.fediact_mode){if(z.whitelist=t(q.fediact_whitelist),z.whitelist.length<1)return L("Whitelist is empty or invalid."),!1}else z.blacklist=t(q.fediact_blacklist);return!0}async function E(){if(location.hostname==q.fediact_homeinstance&&(z.fedireply=x("fedireply"),!z.fedireply))return L("Current site is your home instance."),!1;if("whitelist"==q.fediact_mode){if($.inArray(location.hostname,z.whitelist)<0)return L("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,z.blacklist))return L("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),z.exturi=t.hostname):z.exturi=t,I()?!q.fediact_runifloggedin&&!z.fedireply&&await y()&&(L("Already logged in to this external instance."),1):(L("Could not start background processor."),1)))}async function I(){chrome.runtime.onMessage.addListener(async function(t,e,i){if(t.urlchanged){z.processed=[],z.processedFollow=[],z.isProcessing=[],$(".fediacticon").remove(),$(".fediactsettings_onsite").remove();try{$("body").off("click",fediSettingsHandler)}catch{$.noop()}await b()||location.reload()}t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){L(t)}return!1}function b(){return new Promise(async function(e){try{q=await(browser||chrome).storage.local.get(k)}catch(t){return L(t),void e(!1)}q&&U()?e(!0):e(!1)})}async function N(){await b()?await E()?(z.fedireply?O:(S(),D))():L("Will not process this site."):L("Could not load settings.")}N(); \ 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.directory__card a.icon-button","div.detailed-status a.logo-button","button.remote-button","div.account__header button.button--follow"],p=["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,}$/,M=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,F=/^(?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",w="/api/v1/mutes",k="/api/v1/blocks",u="/api/v1/domain_blocks",f="/api/v1/polls",r=600,c=200,h='
        ',t=10;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:[]},z={fedireply:void 0,lasthomerequest:void 0,whitelist:void 0,blacklist:void 0,exturi:void 0,tokenheader:void 0,processed:[],processedFollow:[],isProcessing:[]};function L(t){e&&console.log(n+" "+t)}function x(){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 T=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{let n=[];return async function(...t){for(;n.length>=a;)await Promise.race(n).catch(()=>{});const e=i.apply(this,t);return n.push(e),await e.catch(()=>{}),n=n.filter(t=>t!==e),e}};function A(a,n,o,s){return new Promise(async function(e){var i,t=Date.now();~n.indexOf(q.fediact_homeinstance)&&q.fediact_enabledelay&&((i=t-z.lasthomerequest){setTimeout(function(){t()},r-i)}),z.lasthomerequest=Date.now());try{await chrome.runtime.sendMessage({requestdata:[a,n,o,s]},function(t){e(t||!1)})}catch(t){L(t),L("Reloading page, extension likely got updated or reloaded."),location.reload()}})}const m=C(A,t);function P(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function O(t,e,i){return t.replace(new RegExp(P(e),"g"),i)}function W(t){var e;q.fediact_redirects?q.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,q.fediact_target),L("Redirected to "+t),e?e.focus():L("Could not open new window. Please allow popups for this website.")):L("Redirects disabled.")}async function J(t,e,i){var a,n,o,s,r="POST";switch(e){case"copy":return navigator.clipboard.writeText(t),!0;case"domainblock":a="https://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},s=async function(){await v()};break;case"domainunblock":a="https://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=async function(){await v()};break;case"mute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=async function(){await v()};break;case"unmute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=async function(){await v()};break;case"block":a="https://"+q.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=async function(){await v()};break;case"unblock":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=async function(){await v()};break;case"vote":a="https://"+q.fediact_homeinstance+f+"/"+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:return void L("No valid action specified.")}if(a){var c=await m(r,a,z.tokenheader,o);if(c&&n(JSON.parse(c)))return void 0!==s&&await s(),!0}L(e+" action failed.")}async function D(t){var e="https://"+q.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,z.tokenheader,null),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;n"+n[2]+"";$(e).append($(i))}$("body").append($(a)),$("body").on("click",async function t(e){var i;e.originalEvent.isTrusted&&($(e.target).is(".fediactmodal li, .fediactmodal li *")?($(e.target).is(".fediactmodal li a")||($(e.target).find("a").length?e.target=$(e.target).find("a"):e.target=$(e.target).closest("a")),i=$(e.target).attr("fediactaction"),await J($(e.target).attr("fediactdata"),i,null)?($(e.target).addClass("activated"),$(e.target).append("Done!"),$(a).css("animation","fadeOut .2s .7s forwards"),$(a).find(".fediactmodalinner").css("animation","scaleInFade .2s .7s forwards reverse"),await new Promise(t=>{setTimeout(function(){t()},1e3)})):($(e.target).css("--confirmation","red"),$(e.target).addClass("activated"),$(e.target).append("Failed"),$(a).css("animation","fadeOut .2s .7s forwards"),$(a).find(".fediactmodalinner").css("animation","scaleInFade .2s .7s forwards reverse"),await new Promise(t=>{setTimeout(function(){t()},1e3)})),$(a).remove(),$("body").off("click",t)):$(e.target).is(".fediactmodalinner")?$.noop():($(a).remove(),$("body").off("click",t)))})}function K(){$(".fediacticon").length||($("body").append("
        "),$("body").append(""),$("body").on("click",function(t){try{t.originalEvent.isTrusted&&($(t.target).is("div.fediacticon")?($("div.fediacticon").hide(),$("div.fediactsettings_onsite")):($("div.fediactsettings_onsite").hide(),$("div.fediacticon"))).show()}catch{$.noop()}}))}async function U(){$(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 E(){function R(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){K(),$(e).is("div.detailed-status")&&$(e).closest("div.focusable").length&&(i=!0,e=$(e).closest("div.focusable"));var i,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!=z.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+z.exturi)}return o.some(t=>Q(t))||Q(e)?($(t).hide(),i&&$(i).hide(),1):void 0}}(e,t)){var a=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)),[n,o]=(n=$(e),$(n).find("a.status__relative-time").length?R($(n).find("a.status__relative-time").first().attr("href").split("?")[0]):$(n).find("a.detailed-status__datetime").length?R($(n).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(n).find("a.modal-button").length?R($(n).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),s=a||o;if(s){var r=[],c=!1,d=tt(s),l=$(e).find("button:has(i.fa-star)").first(),u=($(l).length||(l=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),i?$("
        ").insertAfter($(l).parent()):$("").insertAfter($(l)),$(e).find("button:has(i.fa-retweet)").first()),f=($(u).length||(u=$(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()),p=$(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(),h=$(e).find('button[class*="show-more"]').first(),m=$(e).find("div.poll button").first(),g=($(h).length&&($(h).click(),$(e).find("div.poll").length&&(c=!0),$(h).click()),$(e).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first());async function v(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.

        "),d)&&(z.processed[d][10]=!0,z.processed[d][11]=!0),t}}async function b(t,e){if(!q.fediact_autoaction)return L("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 J(t,a,null))return d&&(z.processed[d][11]=!0),"boost"==a||"unboost"==a?(V($(e.currentTarget),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),V($(e.currentTarget).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive"),d&&(z.processed[d][3]=!z.processed[d][3])):"favourite"==a||"unfavourite"==a?(V($(e.currentTarget),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),V($(e.currentTarget).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive"),d&&(z.processed[d][4]=!z.processed[d][4])):(V($(e.currentTarget),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),d&&(z.processed[d][5]=!z.processed[d][5])),!0;L("Could not execute action on home instance.")}else L("Could not determine action.")}function _(t){$(e).find(".fediactunresolveddetailed, .fediactunresolved").remove(),$(e).find(".fediactprocessingdetailed, .fediactprocessing").remove(),t[1]?($(f).removeClass("disabled").removeAttr("disabled"),$(g).removeClass("disabled").removeAttr("disabled"),t[13]&&($(h).click(),$(h).find("span").text("Show less"),m=$(e).find("div.poll button").first(),$(h).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation();t=$(h).find("span");"Show less"==$(t).text()?$(t).text("Show more"):$(t).text("Show less"),V($(e).find("div.poll").first(),[["display","block","none"]],"fedihideshow"),V($(e).find("div.status__content__text").first(),[["display","block","none"]],"fedihideshow")}),$(h).click()),$(m).removeAttr("disabled"),t[4]&&!$(l).hasClass("fediactive")&&(V($(l),[["color","!remove","rgb(202, 143, 4)"]],"fediactive"),V($(l).find("i"),[["animation","spring-rotate-out 1s linear","spring-rotate-in 1s linear"]],"fediactive")),t[3]&&!$(u).find("i.fediactive").length&&(V($(u),[["color","!remove","rgb(140, 141, 255)"]],"fediactive"),V($(u).find("i"),[["transition-duration","!remove","0.9s"],["background-position","!remove","0px 100%"]],"fediactive")),t[5]&&!$(f).hasClass("fediactive")&&V($(f),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),t[10]&&($(m).hide(),$(m).closest("div.poll").find("ul").replaceWith("

        View the results on your home instance.

        "))):i?$("

        X
        ").insertAfter($(l).parent()):$("X").insertAfter($(l))}function w(n){var t=n[1].split("@"),e=t.pop()||t.pop();$(p).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&W(n[7]+"?fedireply")}),$(g).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],B(n[1])?t.push(["unblock",n[6],"Unblock user"]):t.push(["block",n[6],"Block user"]),G(n[1])?t.push(["unmute",n[6],"Unmute user"]):t.push(["mute",n[6],"Mute user"]),j(n[1])?t.push(["domainunblock",e,"Unblock domain"]):t.push(["domainblock",e,"Block domain"]),t.push(["copy",n[12],"Copy URL"]),t.push(["copy",n[7],"Copy home URL"]),H(t))}),$([l,u,f,m]).each(function(){$(m).length&&$(m).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]?v(n[9],n[7],t):await b(n[2],t))||L("Action failed."),a=0},350):(clearTimeout(i),(e?v(n[9],n[7],t):await b(n[2],t))?W(n[7]):L("Action failed."),a=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(d){var k=z.processed[d];_(k),k[1]&&w(k)}else{if(n&&r.push(o),t){var y,x,T,C=t.match(M),[A,P]=[!1,!1],O=(!C.groups.handledomain||~location.hostname.indexOf(C.groups.handledomain)||(A=!0),[a]);n||O.push(o);for(y of O=O.filter((t,e)=>void 0!==t&&O.indexOf(t)==e))A?P||((x=await Z(location.protocol+"//"+location.hostname+"/"+t+"/"+y))&&(P=!0,r.push(x),F.test(x)?(T=x.match(F)).groups.handle&&T.groups.tootid&&T.groups.domain&&r.push(T.groups.domain+"/@"+T.groups.handle+"/"+T.groups.tootid):M.test(x)&&(T=x.match(M)).groups.handle&&T.groups.tootid&&T.groups.domain&&r.push(T.groups.domain+"/users/"+T.groups.handle+"/statuses/"+T.groups.tootid)),r.push(location.protocol+"//"+location.hostname+"/"+t+"/"+y)):(r.push(location.protocol+"//"+location.hostname+"/users/"+C.groups.handle+"/statuses/"+y),r.push(location.protocol+"//"+location.hostname+"/@"+C.groups.handle+"/"+y))}if(r.length){var D,S,U,E,I,N=!1;for(D of r=r.filter((t,e)=>r.indexOf(t)==e))N||([S,U]=await Y(D),S&&(N=!0,E="https://"+q.fediact_homeinstance+"/@"+S[0]+"/"+S[1],I=[s,...S,E,!0,...U,!1,D,c]));N?(d=X(I),_(I),w(I)):(L("Failed to resolve: "+r),d=X([s,!1]),_([s,!1]))}else L("Could not identify a post URI for home resolving."),d=X([s,!1]),_([s,!1])}}else L("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){z.isProcessing.includes($(t.target).get(0))||(z.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){z.isProcessing.includes($(this).get(0))||(z.isProcessing.push($(this).get(0)),e($(this)))})}async function I(){async function e(a){K();var e,n,o,t,i,s,r,c,d="follow",l=$(a).siblings("button:has(i.fa-ellipsis-fw,i.fa-ellipsis-v,i.fa-ellipsis-h)");async function u(t){return q.fediact_autoaction?(t=await J(t,d,null),"follow"==d&&t?($(n).length?($(n).removeClass("fa-user-plus").addClass("fa-user"),$(a).append("-"),$(a).attr("title","Unfollow")):$(a).text("Unfollow"),d="unfollow",!0):"unfollow"==d&&t?($(n).length?($(n).removeClass("fa-user").addClass("fa-user-plus"),$(a).contents().filter((t,e)=>3===e.nodeType).remove(),$(a).attr("title","Follow")):$(a).text("Follow"),d="follow",!0):void 0):(L("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 if($(a).closest("div.directory__card").length)e=$(a).closest("div.directory__card").find("div.display-name > span").text().trim(),n=$(a).find("i").first();else for(const f of p)if($(f).length){(e=$(f).text().trim()).split("@").length-1==1&&(e=e+"@"+z.exturi);break}e&&!z.processedFollow.includes(e)&&($("").insertBefore($(a)),(o=await S(e))?(z.processedFollow.push(e),$(l).length&&$(l).removeClass("disabled").removeAttr("disabled"),t=e.split("@"),i=t.pop()||t.pop(),s="https://"+q.fediact_homeinstance+"/@"+o[1],(await D([o[0]]))[0]&&($(n).length?($(n).removeClass("fa-user-plus").addClass("fa-user"),$(a).append("-"),$(a).attr("title","Unfollow")):$(a).text("Unfollow"),d="unfollow"),$(l).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],B(e)?t.push(["unblock",o[0],"Unblock user"]):t.push(["block",o[0],"Block user"]),G(e)?t.push(["unmute",o[0],"Unmute user"]):t.push(["mute",o[0],"Mute user"]),j(e)?t.push(["domainunblock",i,"Unblock domain"]):t.push(["domainblock",i,"Block domain"]),t.push(["copy",s,"Copy home URL"]),H(t))}),r=0,$(a).on("click",async function(t){var e,i;t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(1==++r?c=setTimeout(async function(){u(o[0]),r=0},350):(clearTimeout(c),await u(o[0])?($(n).length?(e=$(n).attr("class"),$(n).removeClass("fa-user").removeClass("fa-user-plus").addClass("fa-arrow-right")):(i=$(a).text(),$(a).text("Redirecting...")),setTimeout(function(){W(s),$(n).length?$(n).attr("class",e):$(a).text(i)},1e3)):L("Action failed."),r=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})):L("Could not resolve user home ID."),$(a).siblings(".fediactprocessing").remove())}var t=i.join(",");$(document).DOMNodeAppear(async function(t){z.isProcessing.includes($(t.target).get(0))||(z.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){z.isProcessing.includes($(this).get(0))||(z.isProcessing.push($(this).get(0)),e($(this)))})}function b(t){var e,i=[];for(e of t.split(/\r?\n/))(e=e.trim()).length&&(a.test(e)?i.push(e):L("Removed invalid domain "+e+" from blacklist/whitelist."));return[...new Set(i)]}function N(){if(null==q.fediact_homeinstance||!q.fediact_homeinstance)return L("Mastodon home instance is not set."),!1;if(!q.fediact_token)return L("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(z.tokenheader={Authorization:"Bearer "+q.fediact_token},!a.test(q.fediact_homeinstance))return L("Instance setting is not a valid domain name."),!1;if("whitelist"==q.fediact_mode){if(z.whitelist=b(q.fediact_whitelist),z.whitelist.length<1)return L("Whitelist is empty or invalid."),!1}else z.blacklist=b(q.fediact_blacklist);return!0}async function R(){if(location.hostname==q.fediact_homeinstance&&(z.fedireply=T("fedireply"),!z.fedireply))return L("Current site is your home instance."),!1;if("whitelist"==q.fediact_mode){if($.inArray(location.hostname,z.whitelist)<0)return L("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,z.blacklist))return L("Current site is in blacklist."),!1;var t=location.protocol+"//"+location.hostname+o,t=await m("GET",t,null,null);return!!t&&!(!(t=JSON.parse(t).uri)||(t.startsWith("http")?(t=new URL(t),z.exturi=t.hostname):z.exturi=t,et()?!q.fediact_runifloggedin&&!z.fedireply&&await x()&&(L("Already logged in to this external instance."),1):(L("Could not start background processor."),1)))}async function et(){chrome.runtime.onMessage.addListener(async function(t,e,i){if(t.urlchanged){z.processed=[],z.processedFollow=[],z.isProcessing=[],$(".fediacticon").remove(),$(".fediactsettings_onsite").remove();try{$("body").off("click",fediSettingsHandler)}catch{$.noop()}await _()||location.reload()}t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){L(t)}return!1}function _(){return new Promise(async function(e){try{q=await(browser||chrome).storage.local.get(y)}catch(t){return L(t),void e(!1)}q&&N()?e(!0):e(!1)})}async function it(){await _()?await R()?(z.fedireply?U:(I(),E))():L("Will not process this site."):L("Could not load settings.")}it(); \ No newline at end of file