This commit is contained in:
@@ -3,11 +3,11 @@
|
|||||||
* @param {Object} config - Configuration object for the SDK
|
* @param {Object} config - Configuration object for the SDK
|
||||||
* @param {Object} config.data - Quiz data containing question, options, and answer
|
* @param {Object} config.data - Quiz data containing question, options, and answer
|
||||||
*/
|
*/
|
||||||
function SenaSDK(gid) {
|
function SenaSDK(gid = 'G2510S1T30') {
|
||||||
// Initialize data
|
// Initialize data
|
||||||
this.data = null;
|
this.data = null;
|
||||||
this.correctAnswer = null;
|
this.correctAnswer = null;
|
||||||
this.gameCode = gid || window.SENA_GAME_CODE || 'G2510S1T30';
|
this.gameCode = gid;
|
||||||
// Initialize properties
|
// Initialize properties
|
||||||
this.timeLimit = 0;
|
this.timeLimit = 0;
|
||||||
this.shuffle = true;
|
this.shuffle = true;
|
||||||
@@ -35,10 +35,14 @@ SenaSDK.prototype.shuffleArray = function(array) {
|
|||||||
[array[i], array[j]] = [array[j], array[i]];
|
[array[i], array[j]] = [array[j], array[i]];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SenaSDK.prototype.load = function(callback,template) {
|
SenaSDK.prototype.load = function(callback,template = 'G2510S1T30') {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
// get parameter LID from URL
|
||||||
self.gameCode = self.gameCode || window.SENA_GAME_CODE || template;
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const LID = urlParams.get('LID');
|
||||||
|
if (LID) {
|
||||||
|
self.gameCode = LID;
|
||||||
|
};
|
||||||
fetch(`https://senaai.tech/sample/${self.gameCode}.json`)
|
fetch(`https://senaai.tech/sample/${self.gameCode}.json`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
(function () {
|
// (function () {
|
||||||
// Default game code
|
// // Default game code
|
||||||
var DEFAULT_GAME_CODE = 'G2510S1T30';
|
// var DEFAULT_GAME_CODE = 'G2510S1T30';
|
||||||
|
|
||||||
var gameCode = DEFAULT_GAME_CODE;
|
// var gameCode = DEFAULT_GAME_CODE;
|
||||||
|
|
||||||
// 1️⃣ Trường hợp: ?gid=G2510S1T30
|
// // 1️⃣ Trường hợp: ?gid=G2510S1T30
|
||||||
var params = new URLSearchParams(window.location.search);
|
// var params = new URLSearchParams(window.location.search);
|
||||||
if (params.has('gid')) {
|
// if (params.has('gid')) {
|
||||||
gameCode = params.get('gid');
|
// gameCode = params.get('gid');
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 2️⃣ Trường hợp: ?G2510S1T30 (không key)
|
// // 2️⃣ Trường hợp: ?G2510S1T30 (không key)
|
||||||
else if (window.location.search.length > 1) {
|
// else if (window.location.search.length > 1) {
|
||||||
var raw = window.location.search.substring(1);
|
// var raw = window.location.search.substring(1);
|
||||||
if (/^G\d+/.test(raw)) {
|
// if (/^G\d+/.test(raw)) {
|
||||||
gameCode = raw;
|
// gameCode = raw;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Expose globally
|
// // Expose globally
|
||||||
window.SENA_GAME_CODE = gameCode;
|
// window.SENA_GAME_CODE = gameCode;
|
||||||
|
|
||||||
console.log('[SENA] Game code detected:', gameCode);
|
// console.log('[SENA] Game code detected:', gameCode);
|
||||||
})();
|
// })();
|
||||||
|
|||||||
Reference in New Issue
Block a user