Запись в клуб LifeStyle
clicker.js
class Clicker {
constructor () {
this.btnSendTitle = 'Подать всё что хочу'
this.token = this.getToken()
this.workouts = []
this.addSendBtn()
this.addDesireBtn()
}
getToken () {
let head = document.querySelector('meta[name="csrf-token"]')
return head.getAttribute('content')
}
addSendBtn () {
this.bthSend = document.createElement('a')
this.bthSend.innerText = this.btnSendTitle
this.bthSend.setAttribute('style', 'color:yellow; padding:5px; margin:15px')
this.bthSend.setAttribute('class', 'theme_btn')
let head = document.querySelector('div[class="container-fluid"]')
head.insertBefore(this.bthSend, head.children[3])
let self = this
this.bthSend.onclick = function () {
self.sendAll()
}
}
addDesireBtn () {
let forms = document.querySelectorAll('div[data-workout-id][data-workout-name]')
let self = this
for (let i = 0; i < forms.length; i++) {
let btn = document.createElement('a')
btn.innerText = 'Хочу сюда'
btn.setAttribute('style', 'color:black')
if (forms[i].classList.contains('disabled')) {
forms[i].classList.remove('disabled')
}
let footer = forms[i].querySelector('div[class="workout-item-top-block"]')
footer.insertBefore(btn, footer.children[0])
btn.onclick = function (event) {
event.stopPropagation()
let workoutId = event.path[2].getAttribute('data-workout-id')
if (self.workouts.indexOf(workoutId) < 0) {
self.workouts.push(workoutId)
self.bthSend.innerText = `${self.btnSendTitle} (${self.workouts.length})`
}
}
}
}
sendAll () {
for (let i = 0; i < this.workouts.length; i++) {
const req = new XMLHttpRequest();
const baseUrl = 'https://670770.club/timetable/enrollment/store';
const urlParams = `_token=${this.token}&workout_id=${this.workouts[i]}`;
req.open('POST', baseUrl, true);
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
req.send(urlParams);
}
alert("Сделал всё что смог")
}
}
let clicker = new Clicker()
manifest.json
{
"manifest_version": 2,
"name": "Life Style clicker",
"version": "1.0",
"description": "Life Style запись на тренировку",
"content_scripts": [
{
"matches": [
"https://670770.club/timetable/*"
],
"js": [
"clicker.js"
]
}
],
"permissions": [
"https://670770.club/*",
"<all_urls>",
"cookies",
"tabs"
]
}