Skip to content

Commit

Permalink
Sync custom user theme across subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalnjs committed Dec 28, 2024
1 parent abebaf2 commit c4f4772
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion admin/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
const segment = urlParams.get('segment');
if (!question && !syllabus && !segment) window.location.href = '/admin';
const inputElement = document.querySelector('input[type="file"]');
const domain = ((window.location.hostname.search('check') != -1) || (window.location.hostname.search('127') != -1)) ? 'https://api.check.vssfalcons.com' : 'http://localhost:5000';
const domain = ((window.location.hostname.search('check') != -1) || (window.location.hostname.search('127') != -1)) ? 'https://api.check.vssfalcons.com' : `http://${document.domain}:5000`;
FilePond.registerPlugin(FilePondPluginFileValidateType);
const pond = FilePond.create(inputElement, {
server: domain + ((question) ? '/upload' : (segment) ? '/speedModeUpload' : '/syllabus'),
Expand Down
2 changes: 1 addition & 1 deletion src/checker/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ui from "/src/modules/ui.js";

const domain = ((window.location.hostname.search('check') != -1) || (window.location.hostname.search('127') != -1)) ? 'https://api.check.vssfalcons.com' : 'http://localhost:5000';
const domain = ((window.location.hostname.search('check') != -1) || (window.location.hostname.search('127') != -1)) ? 'https://api.check.vssfalcons.com' : `http://${document.domain}:5000`;
if (window.location.pathname.split('?')[0].endsWith('/admin')) window.location.pathname = '/admin/';

var courses = [];
Expand Down
2 changes: 1 addition & 1 deletion src/checker/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getPeriod } from "/src/periods/periods";
import { convertLatexToAsciiMath, convertLatexToMarkup, renderMathInElement } from "mathlive";
``;

const domain = ((window.location.hostname.search('check') != -1) || (window.location.hostname.search('127') != -1)) ? 'https://api.check.vssfalcons.com' : 'http://localhost:5000';
const domain = ((window.location.hostname.search('check') != -1) || (window.location.hostname.search('127') != -1)) ? 'https://api.check.vssfalcons.com' : `http://${document.domain}:5000`;
const segments = document.getElementById("segment-input");
const segmentInput = document.getElementById("segment-input");
const questions = document.getElementById("question-input");
Expand Down
9 changes: 2 additions & 7 deletions src/modules/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class Storage {
const cookieData = getCookie(this.id);
if (cookieData) {
localStorage.setItem(this.id, cookieData);
console.log(`Synchronized localStorage with cookie data: ${cookieData}`);
} else {
console.log(`No cookie data found for id: ${this.id}`);
}
}
}
Expand All @@ -55,9 +52,7 @@ function setCookie(name, value, days) {
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
const domain = ".vssfalcons.com";
document.cookie = name + "=" + (value || "") + expires + "; path=/; domain=" + domain;
console.log(`Set cookie: ${name}=${value}; domain=${domain}`);
document.cookie = `${name}=${(value || "")}${expires}; path=/; domain=.${document.domain}`;
}

function getCookie(name) {
Expand All @@ -71,4 +66,4 @@ function getCookie(name) {
return null;
}

export default new Storage("virtual-checker-2");
export default new Storage("virtual-falcons");

0 comments on commit c4f4772

Please sign in to comment.