Created
February 19, 2023 04:55
-
-
Save theowenyoung/a0f1194896ea77828eb65fee50ed3a91 to your computer and use it in GitHub Desktop.
Auto update stayfork userscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function uploadToStay() { | |
const userscriptContent = await Deno.readTextFile( | |
"dist/userscript/immersive-translate.user.js", | |
); | |
const STAYFORK_API_KEY = Deno.env.get("STAYFORK_API_KEY"); | |
if (!STAYFORK_API_KEY) { | |
throw new Error("STAYFORK_API_KEY is not set"); | |
} | |
const response = await fetch( | |
`https://api.shenyin.name/stay-fork/modify/${STAYFORK_API_KEY}`, | |
{ | |
"credentials": "omit", | |
"headers": { | |
"User-Agent": | |
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0", | |
"Accept": "application/json, text/plain, */*", | |
"Accept-Language": | |
"zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2", | |
"Content-Type": | |
"multipart/form-data; boundary=---------------------------226697552030855259952894318799", | |
"Sec-Fetch-Dest": "empty", | |
"Sec-Fetch-Mode": "cors", | |
"Sec-Fetch-Site": "cross-site", | |
"Pragma": "no-cache", | |
"Cache-Control": "no-cache", | |
}, | |
"referrer": "https://stayfork.app/", | |
"body": | |
`-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="script"; filename="immersive-translate.user.js"\r\nContent-Type: application/x-javascript\r\n\r\n${userscriptContent}\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="website"\r\n\r\nhttps://immersive-translate.owenyoung.com/\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="icon"\r\n\r\n\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="uuid"\r\n\r\n604133DEA84022066BE76DC281124CF0\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="platforms"\r\n\r\niphone,ipad,mac\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="tags"\r\n\r\n翻译,网页翻译,双语网页翻译\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="mail"\r\n\r\nowen@owenyoung.com\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="stayOnly"\r\n\r\n0\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="version"\r\n\r\n0.2.17\r\n-----------------------------226697552030855259952894318799\r\nContent-Disposition: form-data; name="name"\r\n\r\nImmersive Translate\r\n-----------------------------226697552030855259952894318799--\r\n`, | |
"method": "PUT", | |
"mode": "cors", | |
}, | |
); | |
const status = response.status; | |
if (status !== 200) { | |
throw new Error(`Failed to upload to stayfork: ${status}`); | |
} else { | |
console.info(`Uploaded to stayfork: ${status}`); | |
} | |
} | |
uploadToStay().catch((e) => { | |
console.error(`Failed to upload to stayfork: ${e}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment