diff --git a/firefox/manifest.json b/firefox/manifest.json index 06d27ca..3bfeaa6 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -1,6 +1,6 @@ { "name": "FediAct", - "version": "0.9.8.3", + "version": "0.9.8.4", "description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediAct for more.", "manifest_version": 2, "content_scripts": [ diff --git a/manifest.json b/manifest.json index b983f1d..0094df5 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "FediAct", - "version": "0.9.8.3", + "version": "0.9.8.4", "description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediAct for more.", "manifest_version": 3, "content_scripts": [ diff --git a/src/background.js b/src/background.js index a4274cf..14cc5ee 100644 --- a/src/background.js +++ b/src/background.js @@ -6,9 +6,7 @@ const mutesApi = "/api/v1/mutes" const blocksApi = "/api/v1/blocks" const domainBlocksApi = "/api/v1/domain_blocks" const timeout = 15000 - const tokenRegex = /"access_token":".*?",/gm - // required settings keys with defauls const settingsDefaults = { fediact_homeinstance: null @@ -22,7 +20,7 @@ function log(text) { } // get redirect url (it will be the url on the toot authors home instance) -async function resolveToot(url) { +async function resolveExternalTootHome(url) { return new Promise(async function(resolve) { try { const controller = new AbortController() @@ -44,6 +42,49 @@ async function resolveToot(url) { }) } +// get redirect url (it will be the url on the toot authors home instance) +async function generalRequest(data) { + return new Promise(async function(resolve) { + try { + const controller = new AbortController() + const timeoutId = setTimeout(() => { + log("Timed out") + controller.abort() + }, timeout) + if (data[3]) { + data[2]["Content-Type"] = "application/json" + var res = await fetch(data[1], { + method: data[0], + signal: controller.signal, + headers: data[2], + body: JSON.stringify(data[3]) + }) + } else if (data[2]) { + var res = await fetch(data[1], { + method: data[0], + signal: controller.signal, + headers: data[2] + }) + } else { + var res = await fetch(data[1], { + method: data[0], + signal: controller.signal + }) + } + clearTimeout(timeoutId) + if (res.status >= 200 && res.status < 300) { + var restext = await res.text() + resolve(restext) + } else { + resolve(false) + } + } catch(e) { + log(e) + resolve(false) + } + }) +} + // fetch API token here (will use logged in session automatically) async function fetchBearerToken() { return new Promise(async function(resolve) { @@ -155,8 +196,13 @@ chrome.alarms.onAlarm.addListener(fetchData) // different listeners for inter-script communication chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { // the content script gave us an url to perform a 302 redirect with - if(request.url) { - resolveToot(request.url).then(sendResponse) + if(request.externaltoot) { + resolveExternalTootHome(request.externaltoot).then(sendResponse) + return true + } + // the content script gave us an url to perform a 302 redirect with + if(request.requestdata) { + generalRequest(request.requestdata).then(sendResponse) return true } // immediately fetch api token after settings are updated @@ -164,6 +210,10 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { fetchData().then(reloadListeningScripts) return true } + if (request.updatemutedblocked) { + fetchMutesAndBlocks().then((browser || chrome).storage.local.set(settings)).then(sendResponse) + return true + } // when the content script starts to process on a site, listen for tab changes (url) if (request.running) { chrome.tabs.onUpdated.addListener(async function(tabId, changeInfo, tab) { diff --git a/src/background.min.js b/src/background.min.js index 2fbde57..227e1d5 100644 --- a/src/background.min.js +++ b/src/background.min.js @@ -1 +1 @@ -var browser,chrome,i;const n=!0,a="[FediAct]",t=1,c="/api/v1/mutes",s="/api/v1/blocks",o="/api/v1/domain_blocks",r=15e3,d=/"access_token":".*?",/gm,u={fediact_homeinstance:null};function h(t){n&&console.log(a+" "+t)}async function f(i){return new Promise(async function(e){try{const a=new AbortController;var t=setTimeout(()=>{h("Timed out"),a.abort()},r),n=await fetch(i,{method:"HEAD",signal:a.signal});clearTimeout(t),n.redirected?e(n.url):e(!1)}catch(t){h(t),e(!1)}})}async function l(){return new Promise(async function(e){var t="https://"+i.fediact_homeinstance;try{var n=await(await fetch(t)).text()}catch(t){return h(t),void e(!1)}if(n){t=n.match(d);if(t){var n=t[0].search(/"access_token":"/),a=t[0].search(/",/);if(-1t.json()),fetch("https://"+i.fediact_homeinstance+s,{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)),n.length&&i.fediact_blocks.push(...n.map(t=>t.acct)),a.length&&(i.fediact_domainblocks=a),t(!0)})}async function g(){return new Promise(async function(n){try{i=await(browser||chrome).storage.local.get(u)}catch(t){return h(t),void n(!1)}if(i.fediact_homeinstance){await l(),await m();try{await(browser||chrome).storage.local.set(i),n(!0)}catch{h(e)}}else h("Home instance not set"),n(!1)})}async function _(){chrome.tabs.query({},async function(t){for(var e=0;et.url?(f(t.url).then(e),!0):t.updatedsettings?(g().then(_),!0):void(t.running&&chrome.tabs.onUpdated.addListener(async function(t,e,n){if(t===a.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,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 diff --git a/src/content_styles.css b/src/content_styles.css index cb0988a..f5e2e49 100644 --- a/src/content_styles.css +++ b/src/content_styles.css @@ -76,8 +76,8 @@ } .fediactvoted > a { - font-weight: bold; - color: orange + font-weight: bold !important; + color: orange !important; } /* Inserted in the bottom right of any external instance where FediAct is running */ diff --git a/src/content_styles.min.css b/src/content_styles.min.css index 9b540c4..edc23e9 100644 --- a/src/content_styles.min.css +++ b/src/content_styles.min.css @@ -1 +1 @@ -.fediactmodal{position:fixed;z-index:99999;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgba(0,0,0,0.4);margin:0;padding:0}.fediactmodalinner{background-color:#494949;border:1px solid #888;width:50%;max-width:300px;left:50%;top:50%;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);position:absolute;margin:0;padding:0}.fediactmodallist{width:100%;margin:0;padding:0}.fediactmodalitem{cursor:pointer;width:100%;padding:5px 10px;-webkit-box-sizing:border-box;box-sizing:border-box}.fediactmodallink{font-size:16px;cursor:pointer;text-decoration:none;color:white}.fediactprocessing{color:white;padding-right:10px;padding-left:10px}.fediactunresolved{color:orange;padding-right:10px;padding-left:10px}.fediactvoted{font-style:italic}.fediactvoted>a{font-weight:bold;color:orange}.fediacticon{height:32px;width:32px;position:fixed;z-index:99998;bottom:15px;right:10px;background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAA1ISURBVGhD1VoJdFTlFf7em0z2hYQlkEBYDCYsglCO4IIrKi5YVKpAFSUQNwixPbVae6QKIlg2RSKtK3hAj4KgoHVBqSIuBaQeoUKIYliyEQIh6ySZea/f/d97yWQykwCHnmP/k5fAm3+5393/e0fLGDjCREfD5BR5XC4gKgFadCLQqQcQ1w1aXBfrXVQ8EBEDhEVBc0cAehjn85FheAGfF6a3AWiqBxpqAU81zLpKmDUVQHU5zBNFAP+P+pNqLjTNejoYWkgAhg8IjwaS0qAl94fWtR+0Tt0BIZ6EakKgTkDOIQIQ9hOKJYoe+eVHnKzjWaaAbKxTIMzKYpjHCmGWFQDHDvI9ActZQUZwAN5GaL2GQvvVLdC69APIUU0IlcPkfFMIkL9BKG0mMthxIslgVMjegsv+nGeZsrevEWb5zzC/2wjz5+2ULiUbMAIAcCOKXRtyA1wjJ1pTfU2tOdaRTM/W50ptDdLjJjAdBkEYO9cCZK7/aA2ACPXRWdDSLyGDbVadgh6eLZqD7mNL2SQIs2AbjK9WWTZkjxYA5LQ2ejr0wddQkraqKD35hQzSZIpq5W+FsSWv2UFYAGhEWuYVcI2ZZXkJou1wODrrTHTsosOFYju2vp/uWmEs7dH3+Qswd3+oDNsC0CkFrusfgRaTZG3ZjtqIcf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sSMxVum4N+9BQxaA4ezks1FuxqdiWtY+5N7ymW0DlgRk3HFXGcqOuvHOuq6IiWlRm7AwE3mv5OP8/vW4f1Y6du0IBkDsoUsfuEZPUx16VbW2LKutRihJCAi6SzFu6eGyf6UAyL8VAPuqKt5I7EUAMH4YeiSmjVqOnJHLsYQeyLEB0XEnlMg3G/yHAHj+1XwMO7cO987sHwKAWkHCWLHWL7oTWv/RKtlS7jKUbTSnq3YybCX19tkOcOsaaAVqeiFDR9bI5zBrVB4WL0vByyu6IyLCbpiEMB5RobxX9mM4vU8HAOwdSISWfjG0Yb+GxqAlUlA9ZCUR+1dgrh2YTrT53AInnM4a9Rxmjnweq9Z0xdKne6pQEuqCJNvG0gste3E/BqR5cF+OqBArHx1+W0XUIJKV5uQM1sEzofNLH5DEL5rfUFF9NYm2oin+eVEAGWLQjgrKfk11TBcqcFny65gzZTV8LgNFB9j/ZWxoL5OSeJDW24OjpeHInn4uSop5g+sQgCNOJzaILktDJLazSiPUw6/dQHrMkbGMxJFMzSOb8yP1FZt6NuzqjrOjUso0gelCRaH6io0btZh8Rymy7ilBJIkLxX2HBOHBoQOReHp+GnZ8w+Ix48V/AVFU3fKxDtrWAAAAAElFTkSuQmCC');background-size:32px 32px;cursor:pointer}.fediactsettings_onsite{position:fixed;z-index:99998;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgba(0,0,0,0.4);margin:0;padding:0;display:none}.fediactsettings_onsite .fediactsettings_onsite_inner{position:absolute;bottom:15px;right:15px;padding:10px 15px;background:white;border-radius:5px}.fediactsettings_onsite .fediactsettings_onsite_inner a{color:blue !important}@-moz-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@-webkit-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@-ms-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@-o-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@keyframes nodeInserted{from{opacity:1}to{opacity:1}}div.status,div.detailed-status,div.detailed-status__action-bar,div.account__header button.logo-button,div.account__header button.button--follow,div.public-account-header a.logo-button,div.account-card a.logo-button,div.directory-card a.icon-button,div.detailed-status a.logo-button,button.remote-button,script#initial-state{-webkit-animation-name:nodeInserted !important;-webkit-animation-duration:.001s !important;-ms-animation-name:nodeInserted !important;-ms-animation-duration:.001s !important;-moz-animation-name:nodeInserted !important;-moz-animation-duration:.001s !important;-o-animation-name:nodeInserted !important;-o-animation-duration:.001s !important;animation-name:nodeInserted !important;animation-duration:.001s !important} +.fediactmodal{position:fixed;z-index:99999;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgba(0,0,0,0.4);margin:0;padding:0}.fediactmodalinner{background-color:#494949;border:1px solid #888;width:50%;max-width:300px;left:50%;top:50%;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);position:absolute;margin:0;padding:0}.fediactmodallist{width:100%;margin:0;padding:0}.fediactmodalitem{cursor:pointer;width:100%;padding:5px 10px;-webkit-box-sizing:border-box;box-sizing:border-box}.fediactmodallink{font-size:16px;cursor:pointer;text-decoration:none;color:white}.fediactprocessing{color:white;padding-right:10px;padding-left:10px}.fediactunresolved{color:orange;padding-right:10px;padding-left:10px}.fediactvoted{font-style:italic}.fediactvoted>a{font-weight:bold !important;color:orange !important}.fediacticon{height:32px;width:32px;position:fixed;z-index:99998;bottom:15px;right:10px;background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAA1ISURBVGhD1VoJdFTlFf7em0z2hYQlkEBYDCYsglCO4IIrKi5YVKpAFSUQNwixPbVae6QKIlg2RSKtK3hAj4KgoHVBqSIuBaQeoUKIYliyEQIh6ySZea/f/d97yWQykwCHnmP/k5fAm3+5393/e0fLGDjCREfD5BR5XC4gKgFadCLQqQcQ1w1aXBfrXVQ8EBEDhEVBc0cAehjn85FheAGfF6a3AWiqBxpqAU81zLpKmDUVQHU5zBNFAP+P+pNqLj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uQmCC');background-size:32px 32px;cursor:pointer}.fediactsettings_onsite{position:fixed;z-index:99998;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:rgba(0,0,0,0.4);margin:0;padding:0;display:none}.fediactsettings_onsite .fediactsettings_onsite_inner{position:absolute;bottom:15px;right:15px;padding:10px 15px;background:white;border-radius:5px}.fediactsettings_onsite .fediactsettings_onsite_inner a{color:blue !important}@-moz-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@-webkit-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@-ms-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@-o-keyframes nodeInserted{from{opacity:1}to{opacity:1}}@keyframes nodeInserted{from{opacity:1}to{opacity:1}}div.status,div.detailed-status,div.detailed-status__action-bar,div.account__header button.logo-button,div.account__header button.button--follow,div.public-account-header a.logo-button,div.account-card a.logo-button,div.directory-card a.icon-button,div.detailed-status a.logo-button,button.remote-button,script#initial-state{-webkit-animation-name:nodeInserted !important;-webkit-animation-duration:.001s !important;-ms-animation-name:nodeInserted !important;-ms-animation-duration:.001s !important;-moz-animation-name:nodeInserted !important;-moz-animation-duration:.001s !important;-o-animation-name:nodeInserted !important;-o-animation-duration:.001s !important;animation-name:nodeInserted !important;animation-duration:.001s !important} diff --git a/src/inject.js b/src/inject.js index efafb88..c3e253a 100644 --- a/src/inject.js +++ b/src/inject.js @@ -7,7 +7,7 @@ const profileNamePaths = ["div.account__header__tabs__name small", "div.public-a const domainRegex = /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/ const handleExtractUrlRegex = /^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/ const handleExtractUriRegex = /^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?\w+)(?:(?:\/statuses\/)(?\d+))?\/?$/ -const enableConsoleLog = true +const enableConsoleLog = false const logPrepend = "[FediAct]" const instanceApi = "/api/v1/instance" const statusApi = "/api/v1/statuses" @@ -20,7 +20,6 @@ const pollsApi = "/api/v1/polls" const apiDelay = 500 const maxTootCache = 200 const modalHtml = '
    ' -const timeout = 15000 // settings keys with defauls var settings = {} @@ -145,47 +144,22 @@ async function makeRequest(method, url, extraheaders, jsonbody) { // TODO: move this to the top? or get new Date.now() here? tmpSettings.lasthomerequest = currenttime } - // return a new promise... - return new Promise(function (resolve) { - // create xhr - let xhr = new XMLHttpRequest() - // open it with the method and url specified - xhr.open(method, url) - // set timeout - xhr.timeout = timeout - // set extra headers if any were given - if (extraheaders) { - for (var key in extraheaders) { - xhr.setRequestHeader(key, extraheaders[key]) - } - } - // on load, check if status is OK... - xhr.onload = function () { - if (this.status >= 200 && this.status < 300) { - // is ok, resolve promise with response - resolve(xhr.responseText) - } else { - // nope, resolve false - resolve(false) - } - } - xhr.ontimeout = function() { - log("Timed out") - resolve(false) - } - // on any error, resolve false - xhr.onerror = function() { - log("Request to " + url + " failed.") - resolve(false) - } - // send the request - if (jsonbody) { - xhr.setRequestHeader("Content-Type","application/json") - xhr.send(JSON.stringify(jsonbody)) - } else { - xhr.send() + return new Promise(async function(resolve) { + try { + await chrome.runtime.sendMessage({requestdata: [method, url, extraheaders, jsonbody]}, function(response) { + if(response) { + resolve(response) + } else { + resolve(false) + } + }) + } catch (e) { + // if we encounter an error here, it is likely since the extension context got invalidated, so reload the page + log(e) + log("Reloading page, extension likely got updated or reloaded.") + location.reload() } - }) + }) } // Escape characters used for regex @@ -447,7 +421,7 @@ function resolveTootToExternalHome(tooturl) { if (tooturl) { return new Promise(async function(resolve) { try { - await chrome.runtime.sendMessage({url: tooturl}, function(response) { + await chrome.runtime.sendMessage({externaltoot: tooturl}, function(response) { if(response) { resolve(response) } else { @@ -524,23 +498,28 @@ function addToProcessedToots(toot) { } async function updateMutedBlocked() { - // 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 + var res = await new Promise(async function(resolve) { + try { + await chrome.runtime.sendMessage({updatemutedblocked: true}, function(response) { + if (response) { + resolve(response) + } else { + resolve(false) + } + }) + } catch (e) { + // if we encounter an error here, it is likely since the extension context got invalidated, so reload the page + log(e) + log("Reloading page, extension likely got updated or reloaded.") + location.reload() + } + }) + if (res) { + if (!await getSettings()) { + // but reload if settings are invalid + location.reload() + } } - updateSettings() } function showModal(settings) { @@ -594,14 +573,18 @@ function addFediElements() { $("body").append("
    ") $("body").append("") function fediSettingsHandler(e) { - if (e.originalEvent.isTrusted) { - if ($(e.target).is("div.fediacticon")) { - $("div.fediacticon").hide() - $("div.fediactsettings_onsite").show() - } else { - $("div.fediactsettings_onsite").hide() - $("div.fediacticon").show() + try { + if (e.originalEvent.isTrusted) { + if ($(e.target).is("div.fediacticon")) { + $("div.fediacticon").hide() + $("div.fediactsettings_onsite").show() + } else { + $("div.fediactsettings_onsite").hide() + $("div.fediacticon").show() + } } + } catch { + $.noop() } } $("body").on("click", fediSettingsHandler) @@ -799,6 +782,7 @@ async function processToots() { // do we have one of those? if (internalIdentifier) { var homeResolveStrings = [] + var hasHiddenPoll = false // check if id is already cached var cacheIndex = isInProcessedToots(internalIdentifier) // get all button elements of this toot @@ -813,7 +797,15 @@ async function processToots() { } var bookmarkButton = $(el).find("button:has(i.fa-bookmark)").first() var replyButton = $(el).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() + var spoilerButton = $(el).find('button[class*="show-more"]').first() var voteButton = $(el).find("div.poll button").first() + if ($(spoilerButton).length) { + $(spoilerButton).click() + if ($(el).find("div.poll").length) { + hasHiddenPoll = true + } + $(spoilerButton).click() + } var moreButton = $(el).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first() // handles process when a vote button is clicked async function pollAction(id, redirect, e) { @@ -901,6 +893,31 @@ async function processToots() { // first enable the bookmark button (is disabled on external instances) $(bookmarkButton).removeClass("disabled").removeAttr("disabled") $(moreButton).removeClass("disabled").removeAttr("disabled") + // special care for polls that are hidden behind a CW + if (tootdata[13]) { + // click initially to show content + $(spoilerButton).click() + $(spoilerButton).find("span").text("Show less") + // set voteButton + voteButton = $(el).find("div.poll button").first() + // set handling for all new clicks + $(spoilerButton).on("click", function(e) { + // prevent default etc. + e.preventDefault() + e.stopImmediatePropagation() + var spanText = $(spoilerButton).find("span") + if ($(spanText).text() == "Show less") { + $(spanText).text("Show more") + } else { + $(spanText).text("Show less") + } + // toggle the css manually to hide/show the content/poll + toggleInlineCss($(el).find("div.poll").first(),[["display","block","none"]], "fedihideshow") + toggleInlineCss($(el).find("div.status__content__text").first(),[["display","block","none"]], "fedihideshow") + }) + // click again so it is hidden by default, like usually + $(spoilerButton).click() + } $(voteButton).removeAttr("disabled") // set the toot buttons to active, depending on the state of the resolved toot and if the element already has the active class if (tootdata[4]) { @@ -1110,8 +1127,9 @@ async function processToots() { // set the redirect to home instance URL in @ format var redirectUrl = 'https://' + settings.fediact_homeinstance + "/@" + resolvedToot[0] + "/" + resolvedToot[1] // prepare the cache entry / toot data entry - var fullEntry = [internalIdentifier, ...resolvedToot, redirectUrl, true, ...poll, false, homeResolveString] - // 0: internal identifier; 1: toot home acct / false 2: toot home id 3: toot reblogged 4: toot favourited 5: toot bookmarked 6: home account id 7: redirect url 8: ??? crap! 9: poll id / false 10: poll voted 11: interacted 12: original URL that was resolved + var fullEntry = [internalIdentifier, ...resolvedToot, redirectUrl, true, ...poll, false, homeResolveString, hasHiddenPoll] + // 0: internal identifier; 1: toot home acct / false 2: toot home id 3: toot reblogged 4: toot favourited 5: toot bookmarked 6: home account id + // 7: redirect url 8: ??? crap! 9: poll id / false 10: poll voted 11: interacted 12: original URL that was resolved 13: has hidden poll? } } } @@ -1432,6 +1450,7 @@ async function checkSite() { 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) + // todo: add basic check for "mastodon" string in response if (response) { var uri = JSON.parse(response).uri if (uri) { @@ -1472,7 +1491,11 @@ async function backgroundProcessor() { tmpSettings.isProcessing = [] $(".fediacticon").remove() $(".fediactsettings_onsite").remove() - $("body").off("click", fediSettingsHandler) + try { + $("body").off("click", fediSettingsHandler) + } catch { + $.noop() + } // rerun getSettings to keep mutes/blocks up to date while not reloading the page if (!await getSettings()) { // but reload if settings are invalid @@ -1516,14 +1539,6 @@ function getSettings() { }) } -async function updateSettings() { - await (browser || chrome).storage.local.set(settings) - if (!await getSettings()) { - // but reload if settings are invalid - location.reload() - } -} - // run wrapper async function run() { // validate settings diff --git a/src/inject.min.js b/src/inject.min.js index a36b9cd..587f94a 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,}$/,E=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?\w+)(?:@(?(?:[\w-]+\.)+?\w+))?(?:\/(?\d+))?\/?$/,S=/^(?https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?\w+)(?:(?:\/statuses\/)(?\d+))?\/?$/,e=!0,n="[FediAct]",o="/api/v1/instance",d="/api/v1/statuses",s="/api/v2/search",l="/api/v1/accounts",r="/api/v1/mutes",c="/api/v1/blocks",u="/api/v1/domain_blocks",f="/api/v1/polls",h=500,_=200,k='
      ',w=15e3;var browser,chrome,I={};const y={fediact_homeinstance:null,fediact_alert:!1,fediact_mode:"blacklist",fediact_whitelist:null,fediact_blacklist:null,fediact_target:"_self",fediact_autoaction:!0,fediact_token:null,fediact_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1,fediact_runifloggedin:!1,fediact_mutes:[],fediact_blocks:[],fediact_domainblocks:[]},M={fedireply:void 0,lasthomerequest:void 0,whitelist:void 0,blacklist:void 0,exturi:void 0,tokenheader:void 0,processed:[],processedFollow:[],isProcessing:[]};function q(t){e&&console.log(n+" "+t)}function T(){return new Promise(function(e){var t;$(document).find("script#initial-state").length?(t=$(document).find("script#initial-state").first(),JSON.parse($(t).text()).meta.access_token&&e(!0)):$(document).DOMNodeAppear(function(t){t=$(t.target);JSON.parse($(t).text()).meta.access_token&&e(!0)},"script#initial-state"),e(!1)})}!function(a){a.fn.DOMNodeAppear=function(e,i){if(!i)return!1;a(document).on("animationstart webkitAnimationStart oanimationstart MSAnimationStart",function(t){"nodeInserted"==t.originalEvent.animationName&&a(t.target).is(i)&&"function"==typeof e&&e(t)})},jQuery.fn.onAppear=jQuery.fn.DOMNodeAppear}(jQuery);var x=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a{setTimeout(function(){t()},h-e)}),M.lasthomerequest=t),new Promise(function(t){let e=new XMLHttpRequest;if(e.open(a,n),e.timeout=w,o)for(var i in o)e.setRequestHeader(i,o[i]);e.onload=function(){200<=this.status&&this.status<300?t(e.responseText):t(!1)},e.ontimeout=function(){q("Timed out"),t(!1)},e.onerror=function(){q("Request to "+n+" failed."),t(!1)},s?(e.setRequestHeader("Content-Type","application/json"),e.send(JSON.stringify(s))):e.send()})}function C(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function A(t,e,i){return t.replace(new RegExp(C(e),"g"),i)}function z(t){var e;I.fediact_redirects?I.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,I.fediact_target),q("Redirected to "+t),e?e.focus():q("Could not open new window. Please allow popups for this website.")):q("Redirects disabled.")}async function B(t,e,i){var a,n,o,s,r="POST";switch(e){case"copy":return void navigator.clipboard.writeText(t);case"domainblock":a="https://"+I.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},s=function(){v()};break;case"domainunblock":a="https://"+I.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=function(){v()};break;case"mute":a="https://"+I.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=function(){v()};break;case"unmute":a="https://"+I.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=function(){v()};break;case"block":a="https://"+I.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=function(){v()};break;case"unblock":a="https://"+I.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=function(){v()};break;case"vote":a="https://"+I.fediact_homeinstance+f+"/"+t+"/votes",n=function(t){return t.voted},o=i;break;case"follow":a="https://"+I.fediact_homeinstance+l+"/"+t+"/follow",n=function(t){return t.following||t.requested};break;case"boost":a="https://"+I.fediact_homeinstance+d+"/"+t+"/reblog",n=function(t){return t.reblogged};break;case"favourite":a="https://"+I.fediact_homeinstance+d+"/"+t+"/favourite",n=function(t){return t.favourited};break;case"bookmark":a="https://"+I.fediact_homeinstance+d+"/"+t+"/bookmark",n=function(t){return t.bookmarked};break;case"unfollow":a="https://"+I.fediact_homeinstance+l+"/"+t+"/unfollow",n=function(t){return!t.following&&!t.requested};break;case"unboost":a="https://"+I.fediact_homeinstance+d+"/"+t+"/unreblog",n=function(t){return!t.reblogged};break;case"unfavourite":a="https://"+I.fediact_homeinstance+d+"/"+t+"/unfavourite",n=function(t){return!t.favourited};break;case"unbookmark":a="https://"+I.fediact_homeinstance+d+"/"+t+"/unbookmark",n=function(t){return!t.bookmarked};break;default:q("No valid action specified.")}if(a){var c=await m(r,a,M.tokenheader,o);if(c&&n(JSON.parse(c)))return void 0!==s&&s(),!0}q(e+" action failed.")}async function P(t){var e="https://"+I.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,M.tokenheader,null),a=Array(t.length).fill(!1);if(i)for(var i=JSON.parse(i),n=0;nt.json()),fetch("https://"+I.fediact_homeinstance+c,{headers:{Authorization:"Bearer "+I.fediact_token}}).then(t=>t.json()),fetch("https://"+I.fediact_homeinstance+u,{headers:{Authorization:"Bearer "+I.fediact_token}}).then(t=>t.json())]);t.length&&I.fediact_mutes.push(...t.map(t=>t.acct)),e.length&&I.fediact_blocks.push(...e.map(t=>t.acct)),i.length&&(I.fediact_domainblocks=i),tt()}function H(t){var a=$(k),e=$(a).find("ul");for(const n of t){var i="
    • "+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"),B($(e.target).attr("fediactdata"),i,null)?($(e.target).append(document.createTextNode(" - Done!")),await new Promise(t=>{setTimeout(function(){t()},1e3)})):($(e.target).append(document.createTextNode(" - Failed!")),await new Promise(t=>{setTimeout(function(){t()},1e3)}))),$(a).remove(),$("body").off("click",t))})}function Q(){$(".fediacticon").length||($("body").append("
      "),$("body").append(""),$("body").on("click",function(t){t.originalEvent.isTrusted&&($(t.target).is("div.fediacticon")?($("div.fediacticon").hide(),$("div.fediactsettings_onsite")):($("div.fediactsettings_onsite").hide(),$("div.fediacticon"))).show()}))}async function R(){$(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 N(){function D(t){var e;return!t.startsWith("http")||(e=new URL(t),location.hostname==e.hostname)?[!1,(t=t.split("/")).pop()||t.pop()]:[!0,t]}async function e(e){Q(),$(e).is("div.detailed-status")&&$(e).closest("div.focusable").length&&(e=$(e).closest("div.focusable"));var t=function(t){if($(t).find("span.display-name__account").length)return $(t).find("span.display-name__account").first().text().trim()}($(e));if(!function(t,e){if(I.fediact_hidemuted){var i,a,n=[],o=($(t).siblings(".status__prepend").length&&(i=$(t).siblings(".status__prepend").first(),$(i).find("a").attr("href"))&&n.push($(i).find("a").attr("href").split("?")[0]),$(t).find("span.h-card").each(function(){n.push($(this).find("a").attr("href").split("?")[0])}),[]);for(a of n){var s,r=a.split("/"),r=(r=r.pop()||r.pop()).slice(1);a.startsWith("http")&&(s=new URL(a)).hostname!=M.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+M.exturi)}return o.some(t=>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?D($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?D($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?D($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var s=[],r=K(o),c=$(e).find("button:has(i.fa-star)").first(),d=($(c).length||(c=$(e).find("a.icon-button:has(i.fa-star), a.detailed-status__link:has(i.fa-star)")),$("Resolving...").insertAfter($(c)),$(e).find("button:has(i.fa-retweet)").first()),l=($(d).length||(d=$(e).find("a.icon-button:has(i.fa-retweet), a.detailed-status__link:has(i.fa-retweet)")),$(e).find("button:has(i.fa-bookmark)").first()),u=$(e).find("button:has(i.fa-reply), button:has(i.fa-reply-all), a.icon-button:has(i.fa-reply), a.icon-button:has(i.fa-reply-all)").first(),f=$(e).find("div.poll button").first(),p=$(e).find("button:has(i.fa-ellipsis-h,i.fa-ellipsis-fw,i.fa-ellipsis-v)").first();async function h(t,e,i){if(I.fediact_autoaction){for(var a={choices:[]},n=$(i.currentTarget).closest("div.poll"),o=$(n).find("li"),s=0;sView the results on your home instance.

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

      View the results on your home instance.

      "))):$("Unresolved").insertAfter($(c))}function v(n){var t=n[1].split("@"),e=t.pop()||t.pop();$(u).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&z(n[7]+"?fedireply")}),$(p).on("click",function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(t=[],F(n[1])?t.push(["unblock",n[6],"Unblock user"]):t.push(["block",n[6],"Block user"]),L(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))}),$([c,d,l,f]).each(function(){$(f).length&&$(f).get(0).isEqualNode($(this).get(0))&&(e=!0);var e,i,a=0;$(this).on("click",async function(t){t.preventDefault(),t.stopImmediatePropagation(),t.originalEvent.isTrusted&&(1==++a?i=setTimeout(async function(){(e&&!n[10]?h(n[9],n[7],t):await m(n[2],t))||q("Action failed."),a=0},350):(clearTimeout(i),(e?h(n[9],n[7],t):await m(n[2],t))?z(n[7]):q("Action failed."),a=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})})}if(r){var b=M.processed[r];g(b),b[1]&&v(b)}else{if(a&&s.push(n),t){var _,k,w,y=t.match(E),[T,x]=[!1,!1],C=(!y.groups.handledomain||~location.hostname.indexOf(y.groups.handledomain)||(T=!0),[i]);a||C.push(n);for(_ of C=C.filter((t,e)=>void 0!==t&&C.indexOf(t)==e))T?x||((k=await X(location.protocol+"//"+location.hostname+"/"+t+"/"+_))&&(x=!0,s.push(k),S.test(k)?(w=k.match(S)).groups.handle&&w.groups.tootid&&w.groups.domain&&s.push(w.groups.domain+"/@"+w.groups.handle+"/"+w.groups.tootid):E.test(k)&&(w=k.match(E)).groups.handle&&w.groups.tootid&&w.groups.domain&&s.push(w.groups.domain+"/users/"+w.groups.handle+"/statuses/"+w.groups.tootid)),s.push(location.protocol+"//"+location.hostname+"/"+t+"/"+_)):(s.push(location.protocol+"//"+location.hostname+"/users/"+y.groups.handle+"/statuses/"+_),s.push(location.protocol+"//"+location.hostname+"/@"+y.groups.handle+"/"+_))}if(s.length){var A,P,O,R,N,U=!1;for(A of s=s.filter((t,e)=>s.indexOf(t)==e))U||([P,O]=await V(A),P&&(U=!0,R="https://"+I.fediact_homeinstance+"/@"+P[0]+"/"+P[1],N=[o,...P,R,!0,...O,!1,A]));U?(r=G(N),g(N),v(N)):(q("Failed to resolve: "+s),r=G([o,!1]),g([o,!1]))}else q("Could not identify a post URI for home resolving."),r=G([o,!1]),g([o,!1])}}else q("Could not get toot data.")}}$(document).DOMNodeAppear(async function(t){M.isProcessing.includes($(t.target).get(0))||(M.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){M.isProcessing.includes($(this).get(0))||(M.isProcessing.push($(this).get(0)),e($(this)))})}async function U(){async function e(a){Q();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 I.fediact_autoaction?(t=await B(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):(q("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+"@"+M.exturi);break}e&&!M.processedFollow.includes(e)&&($("Resolving...  ").insertBefore($(a)),(o=await O(e))?(M.processedFollow.push(e),$(l).length&&$(l).removeClass("disabled").removeAttr("disabled"),t=e.split("@"),i=t.pop()||t.pop(),s="https://"+I.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=[],F(e)?t.push(["unblock",o[0],"Unblock user"]):t.push(["block",o[0],"Block user"]),L(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(){z(s),$(n).length?$(n).attr("class",e):$(a).text(i)},1e3)):q("Action failed."),r=0))}).on("dblclick",function(t){t.preventDefault(),t.stopImmediatePropagation()})):q("Could not resolve user home ID."),$(a).siblings(".fediactprocessing").remove())}var t=i.join(",");$(document).DOMNodeAppear(async function(t){M.isProcessing.includes($(t.target).get(0))||(M.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){M.isProcessing.includes($(this).get(0))||(M.isProcessing.push($(this).get(0)),e($(this)))})}function t(t){var e,i=[];for(e of t.split(/\r?\n/))(e=e.trim()).length&&(a.test(e)?i.push(e):q("Removed invalid domain "+e+" from blacklist/whitelist."));return[...new Set(i)]}function D(){if(null==I.fediact_homeinstance||!I.fediact_homeinstance)return q("Mastodon home instance is not set."),!1;if(!I.fediact_token)return q("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(M.tokenheader={Authorization:"Bearer "+I.fediact_token},!a.test(I.fediact_homeinstance))return q("Instance setting is not a valid domain name."),!1;if("whitelist"==I.fediact_mode){if(M.whitelist=t(I.fediact_whitelist),M.whitelist.length<1)return q("Whitelist is empty or invalid."),!1}else M.blacklist=t(I.fediact_blacklist);return!0}async function Y(){if(location.hostname==I.fediact_homeinstance&&(M.fedireply=x("fedireply"),!M.fedireply))return q("Current site is your home instance."),!1;if("whitelist"==I.fediact_mode){if($.inArray(location.hostname,M.whitelist)<0)return q("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,M.blacklist))return q("Current site is in blacklist."),!1;var t=await m("GET",location.protocol+"//"+location.hostname+o,null,null);return!!t&&!(!(t=JSON.parse(t).uri)||(t.startsWith("http")?(t=new URL(t),M.exturi=t.hostname):M.exturi=t,Z()?!I.fediact_runifloggedin&&!M.fedireply&&await T()&&(q("Already logged in to this external instance."),1):(q("Could not start background process"),1)))}async function Z(){chrome.runtime.onMessage.addListener(async function(t,e,i){t.urlchanged&&(M.processed=[],M.processedFollow=[],M.isProcessing=[],$(".fediacticon").remove(),$(".fediactsettings_onsite").remove(),$("body").off("click",fediSettingsHandler),await b()||location.reload()),t.updatedfedisettings&&location.reload()});try{return await chrome.runtime.sendMessage({running:!0}),!0}catch(t){q(t)}return!1}function b(){return new Promise(async function(e){try{I=await(browser||chrome).storage.local.get(y)}catch(t){q(t),e(!1)}I&&D()?e(!0):e(!1)})}async function tt(){await(browser||chrome).storage.local.set(I),await b()||location.reload()}async function et(){await b()?await Y()?(M.fedireply?R:(U(),N))():q("Will not process this site."):q("Could not load settings.")}et(); \ No newline at end of file +const i=["div.account__header button.logo-button","div.public-account-header a.logo-button","div.account-card a.logo-button","div.directory-card a.icon-button","div.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,}$/,I=/^(?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,q={};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:[]},F={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)}),F.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;q.fediact_redirects?q.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,q.fediact_target),z("Redirected to "+t),e?e.focus():z("Could not open new window. Please allow popups for this website.")):z("Redirects disabled.")}async function 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://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},s=function(){v()};break;case"domainunblock":a="https://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=function(){v()};break;case"mute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/mute",n=function(t){return t.muting},s=function(){v()};break;case"unmute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unmute",n=function(t){return!t.muting},s=function(){v()};break;case"block":a="https://"+q.fediact_homeinstance+l+"/"+t+"/block",n=function(t){return t.blocking},s=function(){v()};break;case"unblock":a="https://"+q.fediact_homeinstance+l+"/"+t+"/unblock",n=function(t){return!t.blocking},s=function(){v()};break;case"vote":a="https://"+q.fediact_homeinstance+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:z("No valid action specified.")}if(a){var c=await m(r,a,F.tokenheader,o);if(c&&n(JSON.parse(c)))return void 0!==s&&s(),!0}z(e+" action failed.")}async function P(t){var e="https://"+q.fediact_homeinstance+l+"/relationships?";for(const o of t)e+="id[]="+o.toString()+"&";var i=await m("GET",e,F.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).append(document.createTextNode(" - Done!")),await new Promise(t=>{setTimeout(function(){t()},1e3)})):($(e.target).append(document.createTextNode(" - Failed!")),await new Promise(t=>{setTimeout(function(){t()},1e3)}))),$(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 N(){function E(t){var e;return!t.startsWith("http")||(e=new URL(t),location.hostname==e.hostname)?[!1,(t=t.split("/")).pop()||t.pop()]:[!0,t]}async function e(e){K(),$(e).is("div.detailed-status")&&$(e).closest("div.focusable").length&&(e=$(e).closest("div.focusable"));var t=function(t){if($(t).find("span.display-name__account").length)return $(t).find("span.display-name__account").first().text().trim()}($(e));if(!function(t,e){if(q.fediact_hidemuted){var i,a,n=[],o=($(t).siblings(".status__prepend").length&&(i=$(t).siblings(".status__prepend").first(),$(i).find("a").attr("href"))&&n.push($(i).find("a").attr("href").split("?")[0]),$(t).find("span.h-card").each(function(){n.push($(this).find("a").attr("href").split("?")[0])}),[]);for(a of n){var s,r=a.split("/"),r=(r=r.pop()||r.pop()).slice(1);a.startsWith("http")&&(s=new URL(a)).hostname!=F.exturi&&s.hostname!=location.hostname?o.push(r+"@"+s.hostname):o.push(r+"@"+F.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?E($(a).find("a.status__relative-time").first().attr("href").split("?")[0]):$(a).find("a.detailed-status__datetime").length?E($(a).find("a.detailed-status__datetime").first().attr("href").split("?")[0]):$(a).find("a.modal-button").length?E($(a).find("a.modal-button").first().attr("href").split("?")[0]):[!1,void 0]),o=i||n;if(o){var s=[],r=!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)")),$("Resolving...").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(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.

        "),c)&&(F.processed[c][10]=!0,F.processed[c][11]=!0),t}}async function v(t,e){if(!q.fediact_autoaction)return z("Auto-action disabled."),!0;a=e,i=!1,$(a.currentTarget).children("i.fa-retweet").length?i=$(a.currentTarget).children("i.fa-retweet").hasClass("fediactive")?"unboost":"boost":$(a.currentTarget).children("i.fa-star").length?i=$(a.currentTarget).hasClass("fediactive")?"unfavourite":"favourite":$(a.currentTarget).children("i.fa-bookmark").length?i=$(a.currentTarget).hasClass("fediactive")?"unbookmark":"bookmark":$(a.currentTarget).attr("href")&&(~$(a.currentTarget).attr("href").indexOf("type=reblog")?i=$(a.currentTarget).hasClass("fediactive")?"unboost":"boost":~$(a.currentTarget).attr("href").indexOf("type=favourite")&&(i=$(a.currentTarget).hasClass("fediactive")?"unfavourite":"favourite"));var i,a=i;if(a){if(await W(t,a,null))return c&&(F.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&&(F.processed[c][3]=!F.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&&(F.processed[c][4]=!F.processed[c][4])):(Q($(e.currentTarget),[["color","!remove","rgb(255, 80, 80)"]],"fediactive"),c&&(F.processed[c][5]=!F.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.

        "))):$("Unresolved").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=F.processed[c];b(k),k[1]&&_(k)}else{if(a&&s.push(n),t){var w,y,x,T=t.match(I),[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):I.test(y)&&(x=y.match(I)).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,N,R,S,U,D=!1;for(O of s=s.filter((t,e)=>s.indexOf(t)==e))D||([N,R]=await X(O),N&&(D=!0,S="https://"+q.fediact_homeinstance+"/@"+N[0]+"/"+N[1],U=[o,...N,S,!0,...R,!1,O,r]));D?(c=V(U),b(U),_(U)):(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){F.isProcessing.includes($(t.target).get(0))||(F.isProcessing.push($(t.target).get(0)),e($(t.target)))},"div.status, div.detailed-status"),$(document).find("div.status, div.detailed-status").each(function(){F.isProcessing.includes($(this).get(0))||(F.isProcessing.push($(this).get(0)),e($(this)))})}async function R(){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 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+"@"+F.exturi);break}e&&!F.processedFollow.includes(e)&&($("Resolving...  ").insertBefore($(a)),(o=await A(e))?(F.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 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){F.isProcessing.includes($(t.target).get(0))||(F.isProcessing.push($(t.target).get(0)),e($(t.target)))},t),$(document).find(t).each(function(){F.isProcessing.includes($(this).get(0))||(F.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 S(){if(null==q.fediact_homeinstance||!q.fediact_homeinstance)return z("Mastodon home instance is not set."),!1;if(!q.fediact_token)return z("No API token available. Are you logged in to your home instance? If yes, wait for 1-2 minutes and reload page."),!1;if(F.tokenheader={Authorization:"Bearer "+q.fediact_token},!a.test(q.fediact_homeinstance))return z("Instance setting is not a valid domain name."),!1;if("whitelist"==q.fediact_mode){if(F.whitelist=t(q.fediact_whitelist),F.whitelist.length<1)return z("Whitelist is empty or invalid."),!1}else F.blacklist=t(q.fediact_blacklist);return!0}async function U(){if(location.hostname==q.fediact_homeinstance&&(F.fedireply=x("fedireply"),!F.fedireply))return z("Current site is your home instance."),!1;if("whitelist"==q.fediact_mode){if($.inArray(location.hostname,F.whitelist)<0)return z("Current site is not in whitelist."),!1}else if(-1<$.inArray(location.hostname,F.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),F.exturi=t.hostname):F.exturi=t,D()?!q.fediact_runifloggedin&&!F.fedireply&&await y()&&(z("Already logged in to this external instance."),1):(z("Could not start background process"),1)))}async function D(){chrome.runtime.onMessage.addListener(async function(t,e,i){if(t.urlchanged){F.processed=[],F.processedFollow=[],F.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{q=await(browser||chrome).storage.local.get(w)}catch(t){z(t),e(!1)}q&&S()?e(!0):e(!1)})}async function E(){await b()?await U()?(F.fedireply?O:(R(),N))():z("Will not process this site."):z("Could not load settings.")}E(); \ No newline at end of file