add content-type check, add cross browser prefixes

pull/53/head
lartsch 2022-12-29 05:11:29 -05:00
rodzic 80cbbdf631
commit 8926e8ad80
8 zmienionych plików z 92 dodań i 26 usunięć

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "FediAct",
"version": "0.9.8.5",
"version": "0.9.8.6",
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediAct for more.",
"manifest_version": 2,
"content_scripts": [

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "FediAct",
"version": "0.9.8.5",
"version": "0.9.8.6",
"description": "Simplifies interactions on other Mastodon instances than your own. Visit https://github.com/lartsch/FediAct for more.",
"manifest_version": 3,
"content_scripts": [

Wyświetl plik

@ -73,9 +73,14 @@ async function generalRequest(data) {
})
}
clearTimeout(timeoutId)
if (res.status >= 200 && res.status < 300) {
var restext = await res.text()
resolve(restext)
if (res.status >= 200 && res.status < 300 ) {
const contentType = res.headers.get("content-type")
if (contentType && contentType.indexOf("application/json") !== -1) {
var restext = await res.text()
resolve(restext)
} else {
resolve(false)
}
} else {
resolve(false)
}

Wyświetl plik

@ -1 +1 @@
var browser,chrome,c;const a=!1,n="[FediAct]",t=1,i="/api/v1/mutes",o="/api/v1/blocks",s="/api/v1/domain_blocks",r=15e3,d=/"access_token":".*?",/gm,u={fediact_homeinstance:null,fediact_token:null};function h(t){a&&console.log(n+" "+t)}async function f(i){return new Promise(async function(e){try{const n=new AbortController;var t=setTimeout(()=>{h("Timed out"),n.abort()},r),a=await fetch(i,{method:"HEAD",signal:n.signal});clearTimeout(t),a.redirected?e(a.url):e(!1)}catch(t){h(t),e(!1)}})}async function l(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(-1<a&&-1<n){t=t[0].substring(a+=16,n);if(16<t.length)return c.fediact_token=t,void e(!0)}}}c.fediact_token=null,h("Token could not be found."),e(!1)})}function g(){return new Promise(async function(t){try{[c.fediact_mutes,c.fediact_blocks,c.fediact_domainblocks]=[[],[],[]];var[e,a,n]=await Promise.all([fetch("https://"+c.fediact_homeinstance+i,{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()),fetch("https://"+c.fediact_homeinstance+s,{headers:{Authorization:"Bearer "+c.fediact_token}}).then(t=>t.json())]);e.length&&c.fediact_mutes.push(...e.map(t=>t.acct)),a.length&&c.fediact_blocks.push(...a.map(t=>t.acct)),n.length&&(c.fediact_domainblocks=n),t(!0)}catch{t(!1)}})}async function y(n,i){return new Promise(async function(t){var a=!1;try{if((c=await(browser||chrome).storage.local.get(u)).fediact_homeinstance){if(n||i){!n&&c.fediact_token||await m(),i&&await g();try{await(browser||chrome).storage.local.set(c),a=!0}catch{h(e)}}}else h("Home instance not set")}catch(t){h(t)}t(a)})}async function _(){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(function(){y(!0,!0)}),chrome.alarms.create("refresh",{periodInMinutes:t}),chrome.alarms.onAlarm.addListener(function(){y(!0,!0)}),chrome.runtime.onMessage.addListener((t,n,e)=>t.externaltoot?(f(t.externaltoot).then(e),!0):t.requestdata?(l(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)}})));
var browser,chrome,c;const a=!1,n="[FediAct]",t=1,i="/api/v1/mutes",o="/api/v1/blocks",s="/api/v1/domain_blocks",r=15e3,d=/"access_token":".*?",/gm,u={fediact_homeinstance:null,fediact_token:null};function h(t){a&&console.log(n+" "+t)}async function f(i){return new Promise(async function(e){try{const n=new AbortController;var t=setTimeout(()=>{h("Timed out"),n.abort()},r),a=await fetch(i,{method:"HEAD",signal:n.signal});clearTimeout(t),a.redirected?e(a.url):e(!1)}catch(t){h(t),e(!1)}})}async function l(c){return new Promise(async function(e){try{const i=new AbortController;var t,a,n=setTimeout(()=>{h("Timed out"),i.abort()},r);t=c[3]?(c[2]["Content-Type"]="application/json",await fetch(c[1],{method:c[0],signal:i.signal,headers:c[2],body:JSON.stringify(c[3])})):c[2]?await fetch(c[1],{method:c[0],signal:i.signal,headers:c[2]}):await fetch(c[1],{method:c[0],signal:i.signal}),clearTimeout(n),200<=t.status&&t.status<300&&(a=t.headers.get("content-type"))&&-1!==a.indexOf("application/json")?e(await t.text()):e(!1)}catch(t){h(t),e(!1)}})}async function m(){return new Promise(async function(e){var t="https://"+c.fediact_homeinstance;try{var a=await(await fetch(t)).text()}catch(t){return h(t),void e(!1)}if(a){t=a.match(d);if(t){var a=t[0].search(/"access_token":"/),n=t[0].search(/",/);if(-1<a&&-1<n){t=t[0].substring(a+=16,n);if(16<t.length)return c.fediact_token=t,void e(!0)}}}c.fediact_token=null,h("Token could not be found."),e(!1)})}function g(){return new Promise(async function(t){try{[c.fediact_mutes,c.fediact_blocks,c.fediact_domainblocks]=[[],[],[]];var[e,a,n]=await Promise.all([fetch("https://"+c.fediact_homeinstance+i,{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()),fetch("https://"+c.fediact_homeinstance+s,{headers:{Authorization:"Bearer "+c.fediact_token}}).then(t=>t.json())]);e.length&&c.fediact_mutes.push(...e.map(t=>t.acct)),a.length&&c.fediact_blocks.push(...a.map(t=>t.acct)),n.length&&(c.fediact_domainblocks=n),t(!0)}catch{t(!1)}})}async function y(n,i){return new Promise(async function(t){var a=!1;try{if((c=await(browser||chrome).storage.local.get(u)).fediact_homeinstance){if(n||i){!n&&c.fediact_token||await m(),i&&await g();try{await(browser||chrome).storage.local.set(c),a=!0}catch{h(e)}}}else h("Home instance not set")}catch(t){h(t)}t(a)})}async function p(){chrome.tabs.query({},async function(t){for(var e=0;e<t.length;++e)try{chrome.tabs.sendMessage(t[e].id,{updatedfedisettings:!0})}catch(t){continue}})}chrome.runtime.onInstalled.addListener(function(){y(!0,!0)}),chrome.alarms.create("refresh",{periodInMinutes:t}),chrome.alarms.onAlarm.addListener(function(){y(!0,!0)}),chrome.runtime.onMessage.addListener((t,n,e)=>t.externaltoot?(f(t.externaltoot).then(e),!0):t.requestdata?(l(t.requestdata).then(e),!0):t.updatedsettings?(y(!0,!0).then(p),!0):t.updatemutedblocked?(y(!1,!0).then(e),!0):void(t.running&&chrome.tabs.onUpdated.addListener(async function(t,e,a){if(t===n.tab.id&&e.url)try{await chrome.tabs.sendMessage(t,{urlchanged:e.url})}catch(t){h(t)}})));

Wyświetl plik

@ -9,6 +9,7 @@
--hover: rgba(100,100,130,0.2);
--confirmation: rgb(38, 133, 0);
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #24262d;
@ -29,9 +30,12 @@
background-color: rgba(0,0,0,0.4);
margin: 0;
padding: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
font-size: 1rem;
animation: fadeIn .2s;
-webkit-animation: fadeIn .2s;
animation: fadeIn .2s;
}
.fediactmodalinner {
@ -42,7 +46,8 @@
margin: auto;
padding: .4em;
border-radius: 8px;
animation: scaleInSmall .2s;
-webkit-animation: scaleInSmall .2s;
animation: scaleInSmall .2s;
}
.fediactmodalitem {
position: relative;
@ -52,22 +57,33 @@
cursor: pointer;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: background-color .4s;
-o-transition: background-color .4s;
transition: background-color .4s;
}
.fediactmodalitem:hover, .fediactmodalitem:focus-within {
background-color: var(--hover);
}
.fediactmodallink {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
cursor: pointer;
text-decoration: none;
color: var(--fg);
margin: -.7em;
padding: .7em;
border-radius: inherit;
box-shadow: inset 0 0 0 var(--confirmation);
-webkit-box-shadow: inset 0 0 0 var(--confirmation);
box-shadow: inset 0 0 0 var(--confirmation);
-webkit-transition: padding .2s, color .2s, -webkit-box-shadow .2s cubic-bezier(.2,.2,0,1);
transition: padding .2s, color .2s, -webkit-box-shadow .2s cubic-bezier(.2,.2,0,1);
-o-transition: padding .2s, color .2s, box-shadow .2s cubic-bezier(.2,.2,0,1);
transition: padding .2s, color .2s, box-shadow .2s cubic-bezier(.2,.2,0,1);
transition: padding .2s, color .2s, box-shadow .2s cubic-bezier(.2,.2,0,1), -webkit-box-shadow .2s cubic-bezier(.2,.2,0,1);
}
.fediactmodallink span:not(:first-of-type) {
position: absolute;
@ -77,10 +93,12 @@
border-radius: 4px;
background-color: white;
color: var(--confirmation);
animation: scaleInFadeSmall .2s;
-webkit-animation: scaleInFadeSmall .2s;
animation: scaleInFadeSmall .2s;
}
.fediactmodallink.activated {
box-shadow: inset 300px 0 0 var(--confirmation);
-webkit-box-shadow: inset 300px 0 0 var(--confirmation);
box-shadow: inset 300px 0 0 var(--confirmation);
color: white;
font-weight: 600;
}
@ -89,7 +107,8 @@
.fediactprocessing {
display: inline-block;
margin: auto 10px;
animation: spin 2s infinite linear;
-webkit-animation: spin 2s infinite linear;
animation: spin 2s infinite linear;
width: 1em;
height: 1em;
border-radius: 1em;
@ -97,16 +116,20 @@
border-left-color: transparent;
border-top-color: transparent;
position: relative;
box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
opacity: .8;
}
.fediactprocessing::after {
content: "";
border: inherit;
border-radius: inherit;
animation: inherit;
animation-duration: 1.5s;
animation-timing-function: ease;
-webkit-animation: inherit;
animation: inherit;
-webkit-animation-duration: 1.5s;
animation-duration: 1.5s;
-webkit-animation-timing-function: ease;
animation-timing-function: ease;
position: absolute;
inset: -2px;
}
@ -174,30 +197,68 @@
/* Keyframes */
@-webkit-keyframes fadeIn {
from {
-webkit-filter: opacity(0);
filter: opacity(0);
}
}
@keyframes fadeIn {
from {
filter: opacity(0);
-webkit-filter: opacity(0);
filter: opacity(0);
}
}
@-webkit-keyframes fadeOut {
to {
-webkit-filter: opacity(0);
filter: opacity(0);
}
}
@keyframes fadeOut {
to {
filter: opacity(0);
-webkit-filter: opacity(0);
filter: opacity(0);
}
}
@-webkit-keyframes scaleInSmall {
from {
-webkit-transform: scale(.98);
transform: scale(.98);
}
}
@keyframes scaleInSmall {
from {
transform: scale(.98);
-webkit-transform: scale(.98);
transform: scale(.98);
}
}
@-webkit-keyframes scaleInFadeSmall {
from {
-webkit-transform: scale(.98);
transform: scale(.98);
-webkit-filter: opacity(0);
filter: opacity(0);
}
}
@keyframes scaleInFadeSmall {
from {
transform: scale(.98);
filter: opacity(0);
-webkit-transform: scale(.98);
transform: scale(.98);
-webkit-filter: opacity(0);
filter: opacity(0);
}
}
@-webkit-keyframes spin {
to {
-webkit-transform: rotate(1turn);
transform: rotate(1turn);
}
}
@keyframes spin {
to {
transform: rotate(1turn);
-webkit-transform: rotate(1turn);
transform: rotate(1turn);
}
}

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -1475,7 +1475,7 @@ async function checkSite() {
}
// at this point, we know that it's mastodon and the background processor should start running
if (!backgroundProcessor()) {
log("Could not start background process")
log("Could not start background processor.")
return false
}
// if option is enabled, check if logged in on that instance and stop

2
src/inject.min.js vendored

File diff suppressed because one or more lines are too long