FediAct/src/inject.min.js

1 wiersz
24 KiB
JavaScript
Czysty Zwykły widok Historia

2023-01-22 01:03:36 +00:00
const i=["div.account__header button.logo-button","div.public-account-header a.logo-button","div.account-card a.logo-button","div.directory-card a.icon-button","div.directory__card a.icon-button","div.detailed-status a.logo-button","button.remote-button","div.account__header button.button--follow"],p=["div.account__header__tabs__name small","div.public-account-header__tabs__name small","div.detailed-status span.display-name__account","div.display-name > span","a.user-screen-name","div.profile-info-panel small"],a=/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/,M=/^(?<domain>https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?<handle>\w+)(?:@(?<handledomain>(?:[\w-]+\.)+?\w+))?(?:\/(?<tootid>\d+))?\/?$/,F=/^(?<domain>https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?<handle>\w+)(?:(?:\/statuses\/)(?<tootid>\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=600,c=200,h='<div class="fediactmodal"><div class="fediactmodalinner"><ul class="fediactmodallist"></ul></div></div>',t=10;var browser,chrome,q={};const y={fediact_homeinstance:null,fediact_alert:!1,fediact_mode:"blacklist",fediact_whitelist:null,fediact_blacklist:null,fediact_target:"_self",fediact_autoaction:!0,fediact_token:null,fediact_redirects:!0,fediact_enabledelay:!0,fediact_hidemuted:!1,fediact_runifloggedin:!1,fediact_mutes:[],fediact_blocks:[],fediact_domainblocks:[]},z={fedireply:void 0,lasthomerequest:void 0,whitelist:void 0,blacklist:void 0,exturi:void 0,tokenheader:void 0,processed:[],processedFollow:[],isProcessing:[]};function L(t){e&&console.log(n+" "+t)}function x(){return new Promise(function(e){var t;$(document).find("script#initial-state").length?(t=$(document).find("script#initial-state").first(),JSON.parse($(t).text()).meta.access_token&&e(!0)):$(document).DOMNodeAppear(function(t){t=$(t.target);JSON.parse($(t).text()).meta.access_token&&e(!0)},"script#initial-state"),e(!1)})}!function(a){a.fn.DOMNodeAppear=function(e,i){if(!i)return!1;a(document).on("animationstart webkitAnimationStart oanimationstart MSAnimationStart",function(t){"fa_nodeInserted"==t.originalEvent.animationName&&a(t.target).is(i)&&"function"==typeof e&&e(t)})},jQuery.fn.onAppear=jQuery.fn.DOMNodeAppear}(jQuery);var T=function(t){for(var e,i=window.location.search.substring(1).split("&"),a=0;a<i.length;a++)if((e=i[a].split("="))[0]===t)return void 0===e[1]||decodeURIComponent(e[1]);return!1};const C=(i,a)=>{let n=[];return async function(...t){for(;n.length>=a;)await Promise.race(n).catch(()=>{});const e=i.apply(this,t);return n.push(e),await e.catch(()=>{}),n=n.filter(t=>t!==e),e}};function A(t,a,n,o){return new Promise(async function(e){var i;~a.indexOf(q.fediact_homeinstance)&&q.fediact_enabledelay&&((i=Date.now()-z.lasthomerequest)<r&&await new Promise(t=>{setTimeout(function(){t()},r-i)}),z.lasthomerequest=Date.now());try{await chrome.runtime.sendMessage({requestdata:[t,a,n,o]},function(t){e(t||!1)})}catch(t){L(t),L("Reloading page, extension likely got updated or reloaded."),location.reload()}})}const m=C(A,t);function P(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function O(t,e,i){return t.replace(new RegExp(P(e),"g"),i)}function W(t){var e;q.fediact_redirects?("_self"==q.fediact_target&&(window.onpageshow=function(t){t.persisted&&window.location.reload()}),q.fediact_alert&&!confirm("Redirecting to "+t)||(e=window.open(t,q.fediact_target),L("Redirected to "+t),e?e.focus():L("Could not open new window. Please allow popups for this website."))):L("Redirects disabled.")}async function J(t,e,i){var a,n,o,s,r="POST";switch(e){case"copy":return navigator.clipboard.writeText(t),!0;case"domainblock":a="https://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},s=async function(){await v()};break;case"domainunblock":a="https://"+q.fediact_homeinstance+u+"?domain="+t,n=function(t){if(t)return!0},r="DELETE",s=async function(){await v()};break;case"mute":a="https://"+q.fediact_homeinstance+l+"/"+t+"/mute",n=functi