convert to chrome
This commit is contained in:
parent
f5c23dc867
commit
68a20e8126
3 changed files with 70 additions and 30 deletions
37
content.js
37
content.js
|
|
@ -1,5 +1,7 @@
|
|||
"use strict";
|
||||
|
||||
const extensionApi = globalThis.browser ?? globalThis.chrome;
|
||||
|
||||
function getApplicationId() {
|
||||
const match = window.location.hash.match(/^#\/job-procedures\/record\/([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})/)
|
||||
if (match != null) {
|
||||
|
|
@ -10,16 +12,37 @@ function getApplicationId() {
|
|||
|
||||
async function getXSRFToken() {
|
||||
// we need to go through the background script to get the XSRF-TOKEN cookie
|
||||
return browser.runtime.sendMessage(
|
||||
{ type: "COOKIE", url: "https://personal.uni-graz.at", key: "XSRF-TOKEN" }
|
||||
).then((cookie) => {
|
||||
return cookie.value;
|
||||
return new Promise((resolve, reject) => {
|
||||
extensionApi.runtime.sendMessage(
|
||||
{ type: "COOKIE", url: "https://personal.uni-graz.at", key: "XSRF-TOKEN" },
|
||||
(cookie) => {
|
||||
const runtimeError = extensionApi.runtime.lastError;
|
||||
|
||||
if (runtimeError) {
|
||||
reject(new Error(runtimeError.message))
|
||||
return
|
||||
}
|
||||
|
||||
if (cookie?.error != null) {
|
||||
reject(new Error(cookie.error))
|
||||
return
|
||||
}
|
||||
|
||||
if (cookie?.value == null) {
|
||||
reject(new Error("Failed to retrieve XSRF token cookie"))
|
||||
return
|
||||
}
|
||||
|
||||
resolve(cookie.value)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function getApplicant(applicant, token) {
|
||||
return content.fetch(`https://personal.uni-graz.at/api/erec/job-applications/${applicant.id}`,
|
||||
return fetch(`https://personal.uni-graz.at/api/erec/job-applications/${applicant.id}`,
|
||||
{
|
||||
credentials: "same-origin",
|
||||
headers: { "X-XSRF-TOKEN": token }
|
||||
})
|
||||
.then((response) => {
|
||||
|
|
@ -32,7 +55,7 @@ async function getApplicant(applicant, token) {
|
|||
const files = jsonData.application_files ?? []
|
||||
|
||||
await Promise.all(files.map(async (afile) => {
|
||||
const response = await content.fetch(
|
||||
const response = await fetch(
|
||||
`https://personal.uni-graz.at/api/erec/download-file/${afile.file_id}`,
|
||||
{
|
||||
credentials: "same-origin",
|
||||
|
|
@ -54,7 +77,7 @@ async function getApplicant(applicant, token) {
|
|||
async function getApplicants() {
|
||||
const aid = getApplicationId()
|
||||
const token = await getXSRFToken()
|
||||
return content.fetch(`https://personal.uni-graz.at/api/erec/job-applications/procedure/${aid}`,
|
||||
return fetch(`https://personal.uni-graz.at/api/erec/job-applications/procedure/${aid}`,
|
||||
{
|
||||
credentials: "same-origin",
|
||||
headers: { "X-XSRF-TOKEN": token }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue