0% found this document useful (0 votes)
7 views

User Script

The script adds a button to view student lists to each row on the student group page. When clicked, it loads the student list into a modal overlay on the page. It fetches the student data from an API and builds a table to display the names, IDs, dates and classes.

Uploaded by

no name
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

User Script

The script adds a button to view student lists to each row on the student group page. When clicked, it loads the student list into a modal overlay on the page. It fetches the student data from an API and builds a table to display the names, IDs, dates and classes.

Uploaded by

no name
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

// ==UserScript==

// @name Xem Dssv Qldt Ptit


// @namespace http://tampermonkey.net/
// @version 1.0.0
// @description Try to take over the world!
// @author NhatHoang
// @match https://qldt.ptit.edu.vn/
// ==/UserScript==

function nhatHoang(data) {
const rowHeader = document.querySelector('#printArea table thead tr')
const arrHeader = document.querySelectorAll('#printArea table thead tr th')
if (arrHeader.length <= 13) {
const th = document.createElement('th')
rowHeader.appendChild(th)
}

const arrElement = document.querySelectorAll('#printArea table tbody tr')

arrElement.forEach(function (element, index) {


const td = document.createElement('td')
td.className = 'align-middle'
const button = document.createElement('button')
button.className = 'btn btn-outline-primary btnprintxem'
button.textContent = 'DSSV'
button.addEventListener('click', () => {
handleClick(data.data.ds_nhom_to[index].id_to_hoc)
})
td.appendChild(button)
element.appendChild(td);
});
}

const handleClick = async (id) => {


const body = document.querySelector('body')
body.style.overflowY = 'hidden'

const page = document.querySelector('.page.ng-star-inserted')


const container = document.createElement('div')
container.id = 'dssv'
container.className = 'd-flex justify-content-center position-fixed w-100 h-100 top-0 start-0 overflow-auto'
container.style.background = 'rgba(0, 0, 0, .9)'
container.style.zIndex = '10000'

container.addEventListener('click', () => handleClose())

createTable(id, container)

page.append(container)
}

const createTable = async (id, container) => {


const loading = document.createElement('div')
loading.className = 'ng-tns-c41-11 la-2x la-ball-clip-rotate-multiple ng-star-inserted'
loading.style.color = 'rgb(255, 255, 255)'
const first = document.createElement('div')
first.className = 'ng-tns-c41-11 ng-star-inserted'
const last = document.createElement('div')
last.className = 'ng-tns-c41-11 ng-star-inserted'

loading.appendChild(first)
loading.appendChild(last)
container.appendChild(loading)
container.classList.add('align-items-center')

const data = await getDssv(id)

if (data === null || data.code !== 200) {


const notify = document.createElement('div')
notify.className = 'bg-primary p-3 text-white fs-5'
notify.textContent = "Có lỗi xảy ra!"
notify.addEventListener('click', (e) => e.stopPropagation())
container.appendChild(notify)
loading.remove()
return
}

const listSv = data.data.ds_sinh_vien

if (listSv.length === 0) {
const notify = document.createElement('div')
notify.className = 'bg-primary p-3 text-white fs-5'
notify.textContent = "Danh sách sinh viên trống!"
notify.addEventListener('click', (e) => e.stopPropagation())
container.appendChild(notify)
loading.remove()
return
}

container.classList.remove('align-items-center')
loading.remove()

const table = document.createElement('table');


table.className = 'bg-light'

const thead = document.createElement('thead');


thead.className = 'position-sticky top-0'

const headerRow = document.createElement('tr');


headerRow.className = 'bg-primary text-center align-middle'

const headerTitle = [
'STT',
'Mã sinh viên',
'Họ và tên',
'Ngày sinh',
'Lớp'
]
for (let i = 0; i < headerTitle.length; i++) {
const th = document.createElement('th');
th.textContent = headerTitle[i]
th.className = 'px-3 py-2 border border-top-0 text-center align-middle'
headerRow.appendChild(th);
}

thead.appendChild(headerRow);
table.appendChild(thead);

const tbody = document.createElement('tbody');

for (let i = 0; i < listSv.length; i++) {

const row = document.createElement('tr');


row.className = 'text-center align-middle ng-star-inserted'
const tdStt = document.createElement('td');
tdStt.className = 'px-3 py-1 border text-center align-middle ng-star-inserted'
tdStt.textContent = i + 1
row.appendChild(tdStt);

const tdMsv = document.createElement('td');


tdMsv.className = 'px-3 py-1 border text-center align-middle ng-star-inserted'
tdMsv.textContent = listSv[i].ma_sinh_vien
row.appendChild(tdMsv);

const tdName = document.createElement('td')


tdName.className = 'px-3 py-1 border text-left align-middle custenmon ng-star-inserted'
tdName.textContent = listSv[i].ho_lot + ' ' + listSv[i].ten
row.appendChild(tdName);

const tdDate = document.createElement('td');


tdDate.className = 'px-3 py-1 border text-center align-middle ng-star-inserted'
tdDate.textContent = listSv[i].ngay_sinh
row.appendChild(tdDate);

const tdClass = document.createElement('td');


tdClass.className = 'px-3 py-1 border text-left align-middle ng-star-inserted'
tdClass.textContent = listSv[i].ten_lop
row.appendChild(tdClass);

tbody.appendChild(row);
}

table.appendChild(tbody);
table.addEventListener('click', (e) => e.stopPropagation())
container.appendChild(table)
}

const handleClose = () => {


const body = document.querySelector('body')
body.style.removeProperty('overflow-y')

const dssv = document.querySelector('#dssv')


dssv.remove()
}

const getDssv = async (id) => {


try {
const res = await fetch('https://qldt.ptit.edu.vn/api/sch/w-locdssinhvientheotohoc', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${JSON.parse(sessionStorage.getItem("CURRENT_USER")).access_token}`
},
body: JSON.stringify({
filter: {
id_to_hoc: id,
id_sinh_hoat: "NhatHoang"
},
additional: {
paging: {
limit: 500,
page: 1
},
ordering: [{
name: null,
order_type: 0
}]
}
})
})
const data = await res.json()
return data
} catch (error) {
return null
}
}

(function () {
'use strict';
const url = "/api/sch/w-locdstkbhockytheodoituong";
const originalXhrSend = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function () {
const xhr = this;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.__zone_symbol__xhrURL === url) {
const data = JSON.parse(xhr.response)
setTimeout(() => nhatHoang(data), 0)
}
};
originalXhrSend.apply(this, arguments);
};
})();

You might also like