Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
theg1239 committed Oct 13, 2024
0 parents commit bc6878d
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
90 changes: 90 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

chrome.alarms.create('activityAlarm', {
periodInMinutes: 10
});

chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === 'activityAlarm') {
keepVTOPSessionAlive();
}
});

function keepVTOPSessionAlive() {
chrome.tabs.query({ url: 'https://vtop.vit.ac.in/vtop/content' }, (tabs) => {
if (tabs.length > 0) {
let tabId = tabs[0].id;
chrome.scripting.executeScript({
target: { tabId: tabId },
func: extractTokensAndSendRequest
}, (results) => {
if (chrome.runtime.lastError) {
console.error('Failed to execute script:', chrome.runtime.lastError.message);
} else {
console.log('Request sent successfully:', results);
}
});
} else {
chrome.tabs.create({ url: 'https://vtop.vit.ac.in/vtop/content', active: false }, (tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: extractTokensAndSendRequest
}, (results) => {
if (chrome.runtime.lastError) {
console.error('Failed to execute script:', chrome.runtime.lastError.message);
} else {
console.log('Request sent successfully:', results);
chrome.tabs.remove(tab.id);
}
});
});
}
});
}

function extractTokensAndSendRequest() {
const csrfInput = document.querySelector('input[name="_csrf"]');
const authIDInput = document.querySelector('input[name="authorizedID"]');

if (!csrfInput || !authIDInput) {
console.error('CSRF token or authorizedID not found on the page.');
return;
}

const csrfToken = csrfInput.value;
const authorizedID = authIDInput.value;

const payload = new URLSearchParams();
payload.append('_csrf', csrfToken);
payload.append('authorizedID', authorizedID);
payload.append('x', new Date().toUTCString());

fetch('https://vtop.vit.ac.in/vtop/home', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
'Origin': 'https://vtop.vit.ac.in',
'Pragma': 'no-cache',
'Referer': 'https://vtop.vit.ac.in/vtop/content',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': navigator.userAgent,
'X-Requested-With': 'XMLHttpRequest'
},
body: payload.toString(),
credentials: 'include'
})
.then(response => {
if (response.ok) {
console.log('Activity request sent successfully.');
} else {
console.error('Failed to send activity request:', response.statusText);
}
})
.catch(error => {
console.error('Error sending activity request:', error);
});
}
19 changes: 19 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"manifest_version": 3,
"name": "VTOP Activity",
"version": "1.0",
"description": "Sends periodic requests to VTOP to simulate user activity in the background.",
"permissions": [
"alarms",
"cookies",
"scripting",
"tabs"
],
"host_permissions": [
"https://vtop.vit.ac.in/*"
],
"background": {
"service_worker": "background.js"
}
}

0 comments on commit bc6878d

Please sign in to comment.