tweak timeouts, show unresolved on timeout

pull/23/head
lartsch 2022-12-18 17:40:33 -05:00
rodzic 0820562ffe
commit 318b08a189
4 zmienionych plików z 9 dodań i 6 usunięć

Wyświetl plik

@ -27,7 +27,7 @@ async function resolveToot(url) {
const controller = new AbortController()
const timeoutId = setTimeout(() => {
controller.abort()
}, 1000)
}, 5000)
var res = await fetch(url, {method: 'HEAD', signal: controller.signal})
clearTimeout(timeoutId)
if (res.redirected) {

Wyświetl plik

@ -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=/"access_token":".*?",/gm,d={fediact_homeinstance:null};function u(t){n&&console.log(a+" "+t)}async function h(i){return new Promise(async function(e){try{const a=new AbortController;var t=setTimeout(()=>{a.abort()},1e3),n=await fetch(i,{method:"HEAD",signal:a.signal});clearTimeout(t),n.redirected?e(n.url):e(!1)}catch(t){u(t),e(!1)}})}async function f(){return new Promise(async function(e){var t="https://"+i.fediact_homeinstance;try{var n=await(await fetch(t)).text()}catch(t){return u(t),void e(!1)}if(n){t=n.match(r);if(t){var n=t[0].search(/"access_token":"/),a=t[0].search(/",/);if(-1<n&&-1<a){t=t[0].substring(n+=16,a);if(16<t.length)return i.fediact_token=t,void e(!0)}}}i.fediact_token=null,u("Token could not be found."),e(!1)})}async function l(){return new Promise(async function(t){[i.fediact_mutes,i.fediact_blocks,i.fediact_domainblocks]=[[],[],[]];var[e,n,a]=await Promise.all([fetch("https://"+i.fediact_homeinstance+c,{headers:{Authorization:"Bearer "+i.fediact_token}}).then(t=>t.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 m(){return new Promise(async function(n){try{i=await(browser||chrome).storage.local.get(d)}catch(t){return u(t),void n(!1)}if(i.fediact_homeinstance){await f(),await l();try{await(browser||chrome).storage.local.set(i),n(!0)}catch{u(e)}}else u("Home instance not set"),n(!1)})}async function g(){chrome.tabs.query({},async function(t){for(var e=0;e<t.length;++e)try{chrome.tabs.sendMessage(t[e].id,{updatedfedisettings:!0})}catch(t){continue}})}chrome.runtime.onInstalled.addListener(m),chrome.alarms.create("refresh",{periodInMinutes:t}),chrome.alarms.onAlarm.addListener(m),chrome.runtime.onMessage.addListener((t,a,e)=>t.url?(h(t.url).then(e),!0):t.updatedsettings?(m().then(g),!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){u(t)}})));
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=/"access_token":".*?",/gm,d={fediact_homeinstance:null};function u(t){n&&console.log(a+" "+t)}async function h(i){return new Promise(async function(e){try{const a=new AbortController;var t=setTimeout(()=>{a.abort()},5e3),n=await fetch(i,{method:"HEAD",signal:a.signal});clearTimeout(t),n.redirected?e(n.url):e(!1)}catch(t){u(t),e(!1)}})}async function f(){return new Promise(async function(e){var t="https://"+i.fediact_homeinstance;try{var n=await(await fetch(t)).text()}catch(t){return u(t),void e(!1)}if(n){t=n.match(r);if(t){var n=t[0].search(/"access_token":"/),a=t[0].search(/",/);if(-1<n&&-1<a){t=t[0].substring(n+=16,a);if(16<t.length)return i.fediact_token=t,void e(!0)}}}i.fediact_token=null,u("Token could not be found."),e(!1)})}async function l(){return new Promise(async function(t){[i.fediact_mutes,i.fediact_blocks,i.fediact_domainblocks]=[[],[],[]];var[e,n,a]=await Promise.all([fetch("https://"+i.fediact_homeinstance+c,{headers:{Authorization:"Bearer "+i.fediact_token}}).then(t=>t.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 m(){return new Promise(async function(n){try{i=await(browser||chrome).storage.local.get(d)}catch(t){return u(t),void n(!1)}if(i.fediact_homeinstance){await f(),await l();try{await(browser||chrome).storage.local.set(i),n(!0)}catch{u(e)}}else u("Home instance not set"),n(!1)})}async function g(){chrome.tabs.query({},async function(t){for(var e=0;e<t.length;++e)try{chrome.tabs.sendMessage(t[e].id,{updatedfedisettings:!0})}catch(t){continue}})}chrome.runtime.onInstalled.addListener(m),chrome.alarms.create("refresh",{periodInMinutes:t}),chrome.alarms.onAlarm.addListener(m),chrome.runtime.onMessage.addListener((t,a,e)=>t.url?(h(t.url).then(e),!0):t.updatedsettings?(m().then(g),!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){u(t)}})));

Wyświetl plik

@ -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 = /^(?<domain>https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})?\/?@(?<handle>\w+)(?:@(?<handledomain>(?:[\w-]+\.)+?\w+))?(?:\/(?<tootid>\d+))?\/?$/
const handleExtractUriRegex = /^(?<domain>https?:\/\/(?:\.?[a-z0-9-]+)+(?:\.[a-z]+){1})(?:\/users\/)(?<handle>\w+)(?:(?:\/statuses\/)(?<tootid>\d+))?\/?$/
const enableConsoleLog = false
const enableConsoleLog = true
const logPrepend = "[FediAct]"
const instanceApi = "/api/v1/instance"
const statusApi = "/api/v1/statuses"
@ -157,7 +157,7 @@ async function makeRequest(method, url, extraheaders, jsonbody) {
// open it with the method and url specified
xhr.open(method, url)
// set timeout
xhr.timeout = 1000
xhr.timeout = 5000
// set extra headers if any were given
if (extraheaders) {
for (var key in extraheaders) {
@ -174,6 +174,9 @@ async function makeRequest(method, url, extraheaders, jsonbody) {
resolve(false)
}
}
xhr.ontimeout = function() {
resolve(false)
}
// on any error, resolve false
xhr.onerror = function() {
log("Request to " + url + " failed.")

4
src/inject.min.js vendored

File diff suppressed because one or more lines are too long