prepare for pubsub depreciation, switch to ebs services
This commit is contained in:
+1
-76
@@ -95,79 +95,4 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
import('https://cdn.jsdelivr.net/npm/@sentry/browser@8/+esm').then(sentry=>{
|
||||
sentry.init({
|
||||
dsn:'https://f5fe0dec9f2f42dc80153b67e7e00dd0@app.glitchtip.com/8359',
|
||||
environment:location.hostname,
|
||||
release:"1.1.0",
|
||||
integrations: [
|
||||
sentry.feedbackIntegration({colorScheme:"light"})
|
||||
]
|
||||
})
|
||||
}).catch(e=>{
|
||||
console.warn('automatic error reporting failed to load',e)
|
||||
})
|
||||
|
||||
try{
|
||||
if(window.location.search.includes('remotejs')){
|
||||
const channel=new URLSearchParams(window.location.search).get('remotejs')
|
||||
const script=document.createElement('script')
|
||||
script.src='https://remotejs.com/agent/agent.js'
|
||||
script.setAttribute("data-consolejs-channel",channel)
|
||||
document.head.appendChild(script)
|
||||
}
|
||||
}catch(e){
|
||||
console.warn('remotejs load failed',e)
|
||||
}
|
||||
|
||||
window.onload=async function(){
|
||||
const client_id='ib2n7v7mur7ab2mcxv7rjju2ctsyoi'
|
||||
const scope='moderator:read:followers channel:read:subscriptions bits:read channel:read:charity chat:read chat:edit'
|
||||
const status_div=document.querySelector('div#status')
|
||||
status_div.innerHTML='Logging in to twitch...'
|
||||
const TBA=await import('https://tba.sugoidogo.com/tba.mjs')
|
||||
const tokens=await TBA.get_tokens(client_id,scope)
|
||||
document.querySelector('#timer-link').href+='?refresh_token='+tokens.refresh_token
|
||||
status_div.innerHTML='Loading settings...'
|
||||
const FormDataDeep=await import('https://sugoidogo.github.io/js-util/FormDataDeep.mjs')
|
||||
const config=await fetch('https://ts.sugoidogo.com/config.json',{headers:tokens.auth_headers})
|
||||
.then(async response=>{
|
||||
if(response.ok){
|
||||
try {
|
||||
return await response.json()
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
console.warn(response.code,await response.text())
|
||||
return {}
|
||||
}
|
||||
).then(config=>{
|
||||
for(const checkbox of document.querySelectorAll('input[type=checkbox]')){
|
||||
checkbox.checked=false
|
||||
}
|
||||
for(const key in config){
|
||||
const input=document.querySelector('[name='+key+']')
|
||||
if(!input){
|
||||
continue
|
||||
}
|
||||
if(input.type=='checkbox'){
|
||||
input.checked=true
|
||||
}else{
|
||||
input.value=config[key]
|
||||
}
|
||||
}
|
||||
})
|
||||
status_div.innerHTML='Ready!'
|
||||
document.querySelector('form#config').onsubmit=function(event){
|
||||
event.preventDefault()
|
||||
const config=Object.fromEntries(new FormData(event.target))
|
||||
fetch('https://ts.sugoidogo.com/config.json',{
|
||||
headers:tokens.auth_headers,
|
||||
method:'POST',
|
||||
body:JSON.stringify(config)
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script type="module" src="js/config.js"></script>
|
||||
@@ -0,0 +1,66 @@
|
||||
const status_div = document.querySelector('div#status')
|
||||
onerror = function (error) {
|
||||
status_div.innerHTML = error.message
|
||||
//throw new Error(null,{cause:error})
|
||||
}
|
||||
onunhandledrejection = (event) => onerror(event.reason)
|
||||
|
||||
import AuthProvider from 'https://ebs.sugoidogo.com/SugoiAuthProvider.mjs'
|
||||
import WebStorage from 'https://ebs.sugoidogo.com/WebStorage.mjs'
|
||||
|
||||
const client_id = 'ib2n7v7mur7ab2mcxv7rjju2ctsyoi'
|
||||
const scope = 'moderator:read:followers channel:read:subscriptions bits:read channel:read:charity chat:read chat:edit moderation:read channel:manage:moderators user:read:chat'
|
||||
|
||||
/** @type {import('../node_modules/twitch-cloud-ebs/static/SugoiAuthProvider.mjs').default} */
|
||||
const authProvider = new AuthProvider(client_id)
|
||||
const tokens=await authProvider.addUser(...scope.split(' '))
|
||||
|
||||
/** @type {import('../node_modules/twitch-cloud-ebs/static/WebStorage.mjs').default} */
|
||||
const webStorage = new WebStorage(authProvider)
|
||||
|
||||
document.querySelector('#timer-link').href += '?refresh_token=' + tokens.refresh_token
|
||||
status_div.innerHTML = 'Loading settings...'
|
||||
const FormDataDeep = await import('https://sugoidogo.github.io/js-util/FormDataDeep.mjs')
|
||||
const config = await webStorage.fetch('config.json')
|
||||
.then(async response => {
|
||||
if (response.ok) {
|
||||
try {
|
||||
return await response.json()
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
console.warn(response.code, await response.text())
|
||||
return {}
|
||||
}
|
||||
).then(config => {
|
||||
for (const checkbox of document.querySelectorAll('input[type=checkbox]')) {
|
||||
checkbox.checked = false
|
||||
}
|
||||
for (const key in config) {
|
||||
const input = document.querySelector('[name=' + key + ']')
|
||||
if (!input) {
|
||||
continue
|
||||
}
|
||||
if (input.type == 'checkbox') {
|
||||
input.checked = true
|
||||
} else {
|
||||
input.value = config[key]
|
||||
}
|
||||
}
|
||||
})
|
||||
status_div.innerHTML = 'Ready!'
|
||||
document.querySelector('form#config').onsubmit =async function (event) {
|
||||
event.preventDefault()
|
||||
status_div.innerHTML = 'Saving settings...'
|
||||
const config = Object.fromEntries(new FormData(event.target))
|
||||
await webStorage.fetch('config.json', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(config)
|
||||
}).then(response=>{
|
||||
if(!response.ok){
|
||||
throw new Error(response.statusText,{cause:response})
|
||||
}
|
||||
})
|
||||
status_div.innerHTML = 'Settings saved'
|
||||
}
|
||||
Reference in New Issue
Block a user