diff --git a/src/background.js b/src/background.js index 14cc5ee..0d3e411 100644 --- a/src/background.js +++ b/src/background.js @@ -9,7 +9,8 @@ const timeout = 15000 const tokenRegex = /"access_token":".*?",/gm // required settings keys with defauls const settingsDefaults = { - fediact_homeinstance: null + fediact_homeinstance: null, + fediact_token: null } // wrapper to prepend to log messages @@ -126,51 +127,59 @@ async function fetchBearerToken() { // this is only done here in the bg script so we have data available on load of pages without first performing 3 (!) requests // otherwise this would lead to problems with element detection / low performance (espcially v3 instances) // mutes/blocks are updated in content script on page context changes and after performing mutes/block actions -async function fetchMutesAndBlocks() { +function fetchMutesAndBlocks() { return new Promise(async function(resolve) { - // set empty initially - [settings.fediact_mutes, settings.fediact_blocks, settings.fediact_domainblocks] = [[],[],[]] - var [mutes, blocks, domainblocks] = await Promise.all([ - fetch("https://" + settings.fediact_homeinstance + mutesApi, {headers: {"Authorization": "Bearer "+settings.fediact_token}}).then((response) => response.json()), - fetch("https://" + settings.fediact_homeinstance + blocksApi, {headers: {"Authorization": "Bearer "+settings.fediact_token}}).then((response) => response.json()), - fetch("https://" + settings.fediact_homeinstance + domainBlocksApi, {headers: {"Authorization": "Bearer "+settings.fediact_token}}).then((response) => response.json()) - ]) - if (mutes.length) { - settings.fediact_mutes.push(...mutes.map(acc => acc.acct)) + try { + // set empty initially + [settings.fediact_mutes, settings.fediact_blocks, settings.fediact_domainblocks] = [[],[],[]] + var [mutes, blocks, domainblocks] = await Promise.all([ + fetch("https://" + settings.fediact_homeinstance + mutesApi, {headers: {"Authorization": "Bearer "+settings.fediact_token}}).then((response) => response.json()), + fetch("https://" + settings.fediact_homeinstance + blocksApi, {headers: {"Authorization": "Bearer "+settings.fediact_token}}).then((response) => response.json()), + fetch("https://" + settings.fediact_homeinstance + domainBlocksApi, {headers: {"Authorization": "Bearer "+settings.fediact_token}}).then((response) => response.json()) + ]) + if (mutes.length) { + settings.fediact_mutes.push(...mutes.map(acc => acc.acct)) + } + if (blocks.length) { + settings.fediact_blocks.push(...blocks.map(acc => acc.acct)) + } + if (domainblocks.length) { + settings.fediact_domainblocks = domainblocks + } + resolve(true) + } catch { + resolve(false) } - if (blocks.length) { - settings.fediact_blocks.push(...blocks.map(acc => acc.acct)) - } - if (domainblocks.length) { - settings.fediact_domainblocks = domainblocks - } - resolve(true) }) } -async function fetchData() { +async function fetchData(token, mutesblocks) { return new Promise(async function(resolve) { + var resolved = false try { settings = await (browser || chrome).storage.local.get(settingsDefaults) + if (settings.fediact_homeinstance) { + if (token || mutesblocks) { + if (token || !(settings.fediact_token)) { + await fetchBearerToken() + } + if (mutesblocks) { + await fetchMutesAndBlocks() + } + try { + await (browser || chrome).storage.local.set(settings) + resolved = true + } catch { + log(e) + } + } + } else { + log("Home instance not set") + } } catch(e) { log(e) - resolve(false) - return - } - if (settings.fediact_homeinstance) { - await fetchBearerToken() - await fetchMutesAndBlocks() - } else { - log("Home instance not set") - resolve(false) - return - } - try { - await (browser || chrome).storage.local.set(settings) - resolve(true) - } catch { - log(e) } + resolve(resolved) }) } @@ -188,10 +197,10 @@ async function reloadListeningScripts() { } // fetch api token right after install (mostly for debugging, when the ext. is reloaded) -chrome.runtime.onInstalled.addListener(fetchData) +chrome.runtime.onInstalled.addListener(fetchData(true, true)) // and also every 3 minutes chrome.alarms.create('refresh', { periodInMinutes: tokenInterval }) -chrome.alarms.onAlarm.addListener(fetchData) +chrome.alarms.onAlarm.addListener(fetchData(true, true)) // different listeners for inter-script communication chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { @@ -207,11 +216,11 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { } // immediately fetch api token after settings are updated if (request.updatedsettings) { - fetchData().then(reloadListeningScripts) + fetchData(true, true).then(reloadListeningScripts) return true } if (request.updatemutedblocked) { - fetchMutesAndBlocks().then((browser || chrome).storage.local.set(settings)).then(sendResponse) + fetchData(false, true).then(sendResponse) return true } // when the content script starts to process on a site, listen for tab changes (url) diff --git a/src/background.min.js b/src/background.min.js index 227e1d5..f92ee6e 100644 --- a/src/background.min.js +++ b/src/background.min.js @@ -1 +1 @@ -var browser,chrome,i;const a=!0,n="[FediAct]",t=1,s="/api/v1/mutes",c="/api/v1/blocks",o="/api/v1/domain_blocks",r=15e3,d=/"access_token":".*?",/gm,u={fediact_homeinstance:null};function h(t){a&&console.log(n+" "+t)}async function l(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 f(i){return new Promise(async function(e){try{const n=new AbortController;var t,a=setTimeout(()=>{h("Timed out"),n.abort()},r);t=i[3]?(i[2]["Content-Type"]="application/json",await fetch(i[1],{method:i[0],signal:n.signal,headers:i[2],body:JSON.stringify(i[3])})):i[2]?await fetch(i[1],{method:i[0],signal:n.signal,headers:i[2]}):await fetch(i[1],{method:i[0],signal:n.signal}),clearTimeout(a),200<=t.status&&t.status<300?e(await t.text()):e(!1)}catch(t){h(t),e(!1)}})}async function m(){return new Promise(async function(e){var t="https://"+i.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://"+i.fediact_homeinstance+c,{headers:{Authorization:"Bearer "+i.fediact_token}}).then(t=>t.json()),fetch("https://"+i.fediact_homeinstance+o,{headers:{Authorization:"Bearer "+i.fediact_token}}).then(t=>t.json())]);e.length&&i.fediact_mutes.push(...e.map(t=>t.acct)),a.length&&i.fediact_blocks.push(...a.map(t=>t.acct)),n.length&&(i.fediact_domainblocks=n),t(!0)})}async function y(){return new Promise(async function(a){try{i=await(browser||chrome).storage.local.get(u)}catch(t){return h(t),void a(!1)}if(i.fediact_homeinstance){await m(),await g();try{await(browser||chrome).storage.local.set(i),a(!0)}catch{h(e)}}else h("Home instance not set"),a(!1)})}async function w(){chrome.tabs.query({},async function(t){for(var e=0;et.externaltoot?(l(t.externaltoot).then(e),!0):t.requestdata?(f(t.requestdata).then(e),!0):t.updatedsettings?(y().then(w),!0):t.updatemutedblocked?(g().then((browser||chrome).storage.local.set(i)).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=!0,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 l(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 f(i){return new Promise(async function(e){try{const n=new AbortController;var t,a=setTimeout(()=>{h("Timed out"),n.abort()},r);t=i[3]?(i[2]["Content-Type"]="application/json",await fetch(i[1],{method:i[0],signal:n.signal,headers:i[2],body:JSON.stringify(i[3])})):i[2]?await fetch(i[1],{method:i[0],signal:n.signal,headers:i[2]}):await fetch(i[1],{method:i[0],signal:n.signal}),clearTimeout(a),200<=t.status&&t.status<300?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 _(){chrome.tabs.query({},async function(t){for(var e=0;et.externaltoot?(l(t.externaltoot).then(e),!0):t.requestdata?(f(t.requestdata).then(e),!0):t.updatedsettings?(y(!0,!0).then(_),!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 b8c7a7f..b3bc7b5 100644 --- a/src/inject.js +++ b/src/inject.js @@ -125,26 +125,26 @@ var getUrlParameter = function getUrlParameter(sParam) { } // promisified xhr for api calls -async function makeRequest(method, url, extraheaders, jsonbody) { - // 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... - if (difference < apiDelay) { - // ... then wait the time required to reach the api delay value... - await new Promise(resolve => { - setTimeout(function() { - resolve() - }, apiDelay-difference) - }) - } - // TODO: move this to the top? or get new Date.now() here? - tmpSettings.lasthomerequest = currenttime - } +function makeRequest(method, url, extraheaders, jsonbody) { return new Promise(async function(resolve) { + // 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... + if (difference < apiDelay) { + // ... then wait the time required to reach the api delay value... + await new Promise(resolve => { + setTimeout(function() { + resolve() + }, apiDelay-difference) + }) + } + // TODO: move this to the top? or get new Date.now() here? + tmpSettings.lasthomerequest = currenttime + } try { await chrome.runtime.sendMessage({requestdata: [method, url, extraheaders, jsonbody]}, function(response) { if(response) { @@ -209,37 +209,37 @@ async function executeAction(data, action, polldata) { case 'copy': // special action. only copy to clipboard and return navigator.clipboard.writeText(data) - return + return true case 'domainblock': requestUrl = 'https://' + settings.fediact_homeinstance + domainBlocksApi + "?domain=" + data condition = function(response) {if(response){return true}} - after = function() {updateMutedBlocked()} + after = async function() {await updateMutedBlocked()} break case 'domainunblock': requestUrl = 'https://' + settings.fediact_homeinstance + domainBlocksApi + "?domain=" + data condition = function(response) {if(response){return true}} method = "DELETE" - after = function() {updateMutedBlocked()} + after = async function() {await updateMutedBlocked()} break case 'mute': requestUrl = 'https://' + settings.fediact_homeinstance + accountsApi + "/" + data + "/mute" condition = function(response) {return response.muting} - after = function() {updateMutedBlocked()} + after = async function() {await updateMutedBlocked()} break case 'unmute': requestUrl = 'https://' + settings.fediact_homeinstance + accountsApi + "/" + data + "/unmute" condition = function(response) {return !response.muting} - after = function() {updateMutedBlocked()} + after = async function() {await updateMutedBlocked()} break case 'block': requestUrl = 'https://' + settings.fediact_homeinstance + accountsApi + "/" + data + "/block" condition = function(response) {return response.blocking} - after = function() {updateMutedBlocked()} + after = async function() {await updateMutedBlocked()} break case 'unblock': requestUrl = 'https://' + settings.fediact_homeinstance + accountsApi + "/" + data + "/unblock" condition = function(response) {return !response.blocking} - after = function() {updateMutedBlocked()} + after = async function() {await updateMutedBlocked()} break case 'vote': requestUrl = 'https://' + settings.fediact_homeinstance + pollsApi + "/" + data + "/votes" @@ -279,7 +279,8 @@ async function executeAction(data, action, polldata) { condition = function(response) {return !response.bookmarked} break default: - log("No valid action specified."); break + log("No valid action specified.") + return } if (requestUrl) { var response = await makeRequest(method, requestUrl, tmpSettings.tokenheader, jsonbody) @@ -288,7 +289,7 @@ async function executeAction(data, action, polldata) { response = JSON.parse(response) if (condition(response)) { if (after !== undefined) { - after() + await after() } return true } @@ -497,12 +498,17 @@ function addToProcessedToots(toot) { return tmpSettings.processed.length - 1 } -async function updateMutedBlocked() { - var res = await new Promise(async function(resolve) { +function updateMutedBlocked() { + return new Promise(async function(resolve) { try { - await chrome.runtime.sendMessage({updatemutedblocked: true}, function(response) { + await chrome.runtime.sendMessage({updatemutedblocked: true}, async function(response) { if (response) { - resolve(response) + if (!await getSettings()) { + // but reload if settings are invalid + location.reload() + } else { + resolve(true) + } } else { resolve(false) } @@ -514,12 +520,6 @@ async function updateMutedBlocked() { location.reload() } }) - if (res) { - if (!await getSettings()) { - // but reload if settings are invalid - location.reload() - } - } } function showModal(settings) { @@ -533,13 +533,17 @@ function showModal(settings) { $("body").append($(baseEl)) async function handleModalEvent(e) { if (e.originalEvent.isTrusted) { - if ($(e.target).is(".fediactmodal li, .fediactmodal li a")) { - if ($(e.target).is(".fediactmodal li")) { - e.target = $(e.target).find("a") + if ($(e.target).is(".fediactmodal li, .fediactmodal li *")) { + if (!$(e.target).is(".fediactmodal li a")) { + if ($(e.target).find("a").length) { + e.target = $(e.target).find("a") + } else { + e.target = $(e.target).closest("a") + } } var action = $(e.target).attr("fediactaction") var data = $(e.target).attr("fediactdata") - var done = executeAction(data, action, null) + var done = await executeAction(data, action, null) if (done) { $(e.target).addClass("activated") $(e.target).append("Done!") @@ -566,6 +570,8 @@ function showModal(settings) { $(baseEl).remove() $("body").off("click", handleModalEvent) } + } else if ($(e.target).is(".fediactmodalinner")) { + $.noop() } else { $(baseEl).remove() $("body").off("click", handleModalEvent) @@ -1532,6 +1538,7 @@ function getSettings() { } catch(e) { log(e) resolve(false) + return } if (settings) { // validate settings diff --git a/src/inject.min.js b/src/inject.min.js index c5c4e1b..05f9f44 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,}$/,R=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,M=/^(?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",k="/api/v1/blocks",u="/api/v1/domain_blocks",f="/api/v1/polls",r=500,c=200,h='
    ';var browser,chrome,F={};const w={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:[]},q={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 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-o)}),q.lasthomerequest=e),new Promise(async function(e){try{await chrome.runtime.sendMessage({requestdata:[t,i,a,n]},function(t){e(t||!1)})}catch(t){z(t),z("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 L(t){var e;F.fediact_redirects?F.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,F.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 W(t,e,i){var a,n,o,s,r="POST";switch(e){case"copy":return void navigator.clipboard.writeText(t);case"domainblock":a="https://"+F.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},s=function(){v()};break;case"domainunblock":a="https://"+F.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=function(){v()};break;case"mute":a="https://"+F.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=function(){v()};break;case"unmute":a="https://"+F.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=function(){v()};break;case"block":a="https://"+F.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=function(){v()};break;case"unblock":a="https://"+F.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=function(){v()};break;case"vote":a="https://"+F.fediact_homeinstance+f+"/"+t+"/votes",n=function(t){return t.voted},o=i;break;case"follow":a="https://"+F.fediact_homeinstance+l+"/"+t+"/follow",n=function(t){return t.following||t.requested};break;case"boost":a="https://"+F.fediact_homeinstance+d+"/"+t+"/reblog",n=function(t){return t.reblogged};break;case"favourite":a="https://"+F.fediact_homeinstance+d+"/"+t+"/favourite",n=function(t){return t.favourited};break;case"bookmark":a="https://"+F.fediact_homeinstance+d+"/"+t+"/bookmark",n=function(t){return t.bookmarked};break;case"unfollow":a="https://"+F.fediact_homeinstance+l+"/"+t+"/unfollow",n=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+F.fediact_homeinstance+d+"/"+t+"/unreblog",n=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+F.fediact_homeinstance+d+"/"+t+"/unfavourite",n=function(t){return!t.favourited};break;case"unbookmark":a="https://"+F.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,q.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://"+F.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,q.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 a")&&($(e.target).is(".fediactmodal li")&&(e.target=$(e.target).find("a")),i=$(e.target).attr("fediactaction"),W($(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))})}function X(){$(".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 S(){function N(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){X(),$(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(F.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!=q.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+q.exturi)}return o.some(t=>j(t))||j(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?N($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?N($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?N($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var s=[],r=!1,c=Z(o),d=$(e).find("button:has(i.fa-star)").first(),l=($(d).length||(d=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),$("").insertAfter($(d)),$(e).find("button:has(i.fa-retweet)").first()),u=($(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()),f=$(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(),p=$(e).find('button[class*="show-more"]').first(),h=$(e).find("div.poll button").first(),m=($(p).length&&($(p).click(),$(e).find("div.poll").length&&(r=!0),$(p).click()),$(e).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first());async function g(t,e,i){if(F.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.

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

    View the results on your home instance.

    "))):$("X").insertAfter($(d))}function _(n){var t=n[1].split("@"),e=t.pop()||t.pop();$(f).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&L(n[7]+"?fedireply")}),$(m).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],J(n[1])?t.push(["unblock",n[6],"Unblock user"]):t.push(["block",n[6],"Block user"]),B(n[1])?t.push(["unmute",n[6],"Unmute user"]):t.push(["mute",n[6],"Mute user"]),G(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))}),$([d,l,u,h]).each(function(){$(h).length&&$(h).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]?g(n[9],n[7],t):await v(n[2],t))||z("Action failed."),a=0},350):(clearTimeout(i),(e?g(n[9],n[7],t):await v(n[2],t))?L(n[7]):z("Action failed."),a=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(c){var k=q.processed[c];b(k),k[1]&&_(k)}else{if(a&&s.push(n),t){var w,y,x,T=t.match(R),[C,P]=[!1,!1],A=(!T.groups.handledomain||~location.hostname.indexOf(T.groups.handledomain)||(C=!0),[i]);a||A.push(n);for(w of A=A.filter((t,e)=>void 0!==t&&A.indexOf(t)==e))C?P||((y=await Y(location.protocol+"//"+location.hostname+"/"+t+"/"+w))&&(P=!0,s.push(y),M.test(y)?(x=y.match(M)).groups.handle&&x.groups.tootid&&x.groups.domain&&s.push(x.groups.domain+"/@"+x.groups.handle+"/"+x.groups.tootid):R.test(y)&&(x=y.match(R)).groups.handle&&x.groups.tootid&&x.groups.domain&&s.push(x.groups.domain+"/users/"+x.groups.handle+"/statuses/"+x.groups.tootid)),s.push(location.protocol+"//"+location.hostname+"/"+t+"/"+w)):(s.push(location.protocol+"//"+location.hostname+"/users/"+T.groups.handle+"/statuses/"+w),s.push(location.protocol+"//"+location.hostname+"/@"+T.groups.handle+"/"+w))}if(s.length){var O,S,D,U,E,I=!1;for(O of s=s.filter((t,e)=>s.indexOf(t)==e))I||([S,D]=await K(O),S&&(I=!0,U="https://"+F.fediact_homeinstance+"/@"+S[0]+"/"+S[1],E=[o,...S,U,!0,...D,!1,O,r]));I?(c=V(E),b(E),_(E)):(z("Failed to resolve: "+s),c=V([o,!1]),b([o,!1]))}else z("Could not identify a post URI for home resolving."),c=V([o,!1]),b([o,!1])}}else z("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){q.isProcessing.includes($(t.target).get(0))||(q.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){q.isProcessing.includes($(this).get(0))||(q.isProcessing.push($(this).get(0)),e($(this)))})}async function D(){async function e(a){X();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 F.fediact_autoaction?(t=await W(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):(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 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+"@"+q.exturi);break}e&&!q.processedFollow.includes(e)&&($("").insertBefore($(a)),(o=await A(e))?(q.processedFollow.push(e),$(l).length&&$(l).removeClass("disabled").removeAttr("disabled"),t=e.split("@"),i=t.pop()||t.pop(),s="https://"+F.fediact_homeinstance+"/@"+o[1],(await P([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=[],J(e)?t.push(["unblock",o[0],"Unblock user"]):t.push(["block",o[0],"Block user"]),B(e)?t.push(["unmute",o[0],"Unmute user"]):t.push(["mute",o[0],"Mute user"]),G(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(){L(s),$(n).length?$(n).attr("class",e):$(a).text(i)},1e3)):z("Action failed."),r=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){q.isProcessing.includes($(t.target).get(0))||(q.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){q.isProcessing.includes($(this).get(0))||(q.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 U(){if(null==F.fediact_homeinstance||!F.fediact_homeinstance)return z("Mastodon home instance is not set."),!1;if(!F.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(q.tokenheader={Authorization:"Bearer "+F.fediact_token},!a.test(F.fediact_homeinstance))return z("Instance setting is not a valid domain name."),!1;if("whitelist"==F.fediact_mode){if(q.whitelist=t(F.fediact_whitelist),q.whitelist.length<1)return z("Whitelist is empty or invalid."),!1}else q.blacklist=t(F.fediact_blacklist);return!0}async function E(){if(location.hostname==F.fediact_homeinstance&&(q.fedireply=x("fedireply"),!q.fedireply))return z("Current site is your home instance."),!1;if("whitelist"==F.fediact_mode){if($.inArray(location.hostname,q.whitelist)<0)return z("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,q.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),q.exturi=t.hostname):q.exturi=t,I()?!F.fediact_runifloggedin&&!q.fedireply&&await y()&&(z("Already logged in to this external instance."),1):(z("Could not start background process"),1)))}async function I(){chrome.runtime.onMessage.addListener(async function(t,e,i){if(t.urlchanged){q.processed=[],q.processedFollow=[],q.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){z(t)}return!1}function b(){return new Promise(async function(e){try{F=await(browser||chrome).storage.local.get(w)}catch(t){z(t),e(!1)}F&&U()?e(!0):e(!1)})}async function N(){await b()?await E()?(q.fedireply?O:(D(),S))():z("Will not process this site."):z("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,}$/,R=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,M=/^(?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",_="/api/v1/blocks",u="/api/v1/domain_blocks",f="/api/v1/polls",r=500,c=200,h='

      ';var browser,chrome,F={};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:[]},q={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 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)}),q.lasthomerequest=t);try{await chrome.runtime.sendMessage({requestdata:[a,n,o,s]},function(t){e(t||!1)})}catch(t){z(t),z("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 L(t){var e;F.fediact_redirects?F.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,F.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 W(t,e,i){var a,n,o,s,r="POST";switch(e){case"copy":return navigator.clipboard.writeText(t),!0;case"domainblock":a="https://"+F.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},s=async function(){await v()};break;case"domainunblock":a="https://"+F.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=async function(){await v()};break;case"mute":a="https://"+F.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=async function(){await v()};break;case"unmute":a="https://"+F.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=async function(){await v()};break;case"block":a="https://"+F.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=async function(){await v()};break;case"unblock":a="https://"+F.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=async function(){await v()};break;case"vote":a="https://"+F.fediact_homeinstance+f+"/"+t+"/votes",n=function(t){return t.voted},o=i;break;case"follow":a="https://"+F.fediact_homeinstance+l+"/"+t+"/follow",n=function(t){return t.following||t.requested};break;case"boost":a="https://"+F.fediact_homeinstance+d+"/"+t+"/reblog",n=function(t){return t.reblogged};break;case"favourite":a="https://"+F.fediact_homeinstance+d+"/"+t+"/favourite",n=function(t){return t.favourited};break;case"bookmark":a="https://"+F.fediact_homeinstance+d+"/"+t+"/bookmark",n=function(t){return t.bookmarked};break;case"unfollow":a="https://"+F.fediact_homeinstance+l+"/"+t+"/unfollow",n=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+F.fediact_homeinstance+d+"/"+t+"/unreblog",n=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+F.fediact_homeinstance+d+"/"+t+"/unfavourite",n=function(t){return!t.favourited};break;case"unbookmark":a="https://"+F.fediact_homeinstance+d+"/"+t+"/unbookmark",n=function(t){return!t.bookmarked};break;default:return void z("No valid action specified.")}if(a){var c=await m(r,a,q.tokenheader,o);if(c&&n(JSON.parse(c)))return void 0!==s&&await s(),!0}z(e+" action failed.")}async function P(t){var e="https://"+F.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,q.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 W($(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 X(){$(".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 S(){function N(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){X(),$(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(F.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!=q.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+q.exturi)}return o.some(t=>j(t))||j(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?N($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?N($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?N($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var s=[],r=!1,c=Z(o),d=$(e).find("button:has(i.fa-star)").first(),l=($(d).length||(d=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),$("").insertAfter($(d)),$(e).find("button:has(i.fa-retweet)").first()),u=($(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()),f=$(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(),p=$(e).find('button[class*="show-more"]').first(),h=$(e).find("div.poll button").first(),m=($(p).length&&($(p).click(),$(e).find("div.poll").length&&(r=!0),$(p).click()),$(e).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first());async function g(t,e,i){if(F.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.

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

      View the results on your home instance.

      "))):$("X").insertAfter($(d))}function w(n){var t=n[1].split("@"),e=t.pop()||t.pop();$(f).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&L(n[7]+"?fedireply")}),$(m).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],J(n[1])?t.push(["unblock",n[6],"Unblock user"]):t.push(["block",n[6],"Block user"]),B(n[1])?t.push(["unmute",n[6],"Unmute user"]):t.push(["mute",n[6],"Mute user"]),G(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))}),$([d,l,u,h]).each(function(){$(h).length&&$(h).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]?g(n[9],n[7],t):await v(n[2],t))||z("Action failed."),a=0},350):(clearTimeout(i),(e?g(n[9],n[7],t):await v(n[2],t))?L(n[7]):z("Action failed."),a=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(c){var _=q.processed[c];b(_),_[1]&&w(_)}else{if(a&&s.push(n),t){var k,y,x,T=t.match(R),[C,P]=[!1,!1],A=(!T.groups.handledomain||~location.hostname.indexOf(T.groups.handledomain)||(C=!0),[i]);a||A.push(n);for(k of A=A.filter((t,e)=>void 0!==t&&A.indexOf(t)==e))C?P||((y=await Y(location.protocol+"//"+location.hostname+"/"+t+"/"+k))&&(P=!0,s.push(y),M.test(y)?(x=y.match(M)).groups.handle&&x.groups.tootid&&x.groups.domain&&s.push(x.groups.domain+"/@"+x.groups.handle+"/"+x.groups.tootid):R.test(y)&&(x=y.match(R)).groups.handle&&x.groups.tootid&&x.groups.domain&&s.push(x.groups.domain+"/users/"+x.groups.handle+"/statuses/"+x.groups.tootid)),s.push(location.protocol+"//"+location.hostname+"/"+t+"/"+k)):(s.push(location.protocol+"//"+location.hostname+"/users/"+T.groups.handle+"/statuses/"+k),s.push(location.protocol+"//"+location.hostname+"/@"+T.groups.handle+"/"+k))}if(s.length){var O,S,D,U,E,I=!1;for(O of s=s.filter((t,e)=>s.indexOf(t)==e))I||([S,D]=await K(O),S&&(I=!0,U="https://"+F.fediact_homeinstance+"/@"+S[0]+"/"+S[1],E=[o,...S,U,!0,...D,!1,O,r]));I?(c=V(E),b(E),w(E)):(z("Failed to resolve: "+s),c=V([o,!1]),b([o,!1]))}else z("Could not identify a post URI for home resolving."),c=V([o,!1]),b([o,!1])}}else z("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){q.isProcessing.includes($(t.target).get(0))||(q.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){q.isProcessing.includes($(this).get(0))||(q.isProcessing.push($(this).get(0)),e($(this)))})}async function D(){async function e(a){X();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 F.fediact_autoaction?(t=await W(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):(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 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+"@"+q.exturi);break}e&&!q.processedFollow.includes(e)&&($("").insertBefore($(a)),(o=await A(e))?(q.processedFollow.push(e),$(l).length&&$(l).removeClass("disabled").removeAttr("disabled"),t=e.split("@"),i=t.pop()||t.pop(),s="https://"+F.fediact_homeinstance+"/@"+o[1],(await P([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=[],J(e)?t.push(["unblock",o[0],"Unblock user"]):t.push(["block",o[0],"Block user"]),B(e)?t.push(["unmute",o[0],"Unmute user"]):t.push(["mute",o[0],"Mute user"]),G(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(){L(s),$(n).length?$(n).attr("class",e):$(a).text(i)},1e3)):z("Action failed."),r=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){q.isProcessing.includes($(t.target).get(0))||(q.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){q.isProcessing.includes($(this).get(0))||(q.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 U(){if(null==F.fediact_homeinstance||!F.fediact_homeinstance)return z("Mastodon home instance is not set."),!1;if(!F.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(q.tokenheader={Authorization:"Bearer "+F.fediact_token},!a.test(F.fediact_homeinstance))return z("Instance setting is not a valid domain name."),!1;if("whitelist"==F.fediact_mode){if(q.whitelist=t(F.fediact_whitelist),q.whitelist.length<1)return z("Whitelist is empty or invalid."),!1}else q.blacklist=t(F.fediact_blacklist);return!0}async function E(){if(location.hostname==F.fediact_homeinstance&&(q.fedireply=x("fedireply"),!q.fedireply))return z("Current site is your home instance."),!1;if("whitelist"==F.fediact_mode){if($.inArray(location.hostname,q.whitelist)<0)return z("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,q.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),q.exturi=t.hostname):q.exturi=t,I()?!F.fediact_runifloggedin&&!q.fedireply&&await y()&&(z("Already logged in to this external instance."),1):(z("Could not start background process"),1)))}async function I(){chrome.runtime.onMessage.addListener(async function(t,e,i){if(t.urlchanged){q.processed=[],q.processedFollow=[],q.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){z(t)}return!1}function b(){return new Promise(async function(e){try{F=await(browser||chrome).storage.local.get(k)}catch(t){return z(t),void e(!1)}F&&U()?e(!0):e(!1)})}async function N(){await b()?await E()?(q.fedireply?O:(D(),S))():z("Will not process this site."):z("Could not load settings.")}N(); \ No newline at end of file