-
Notifications
You must be signed in to change notification settings - Fork 0
/
skyblog-script.js
140 lines (112 loc) · 5.07 KB
/
skyblog-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const puppeteer = require('puppeteer');
require('dotenv').config();
async function run() {
const browser = await puppeteer.launch({
// Path to the Google Chrome browser executable (may vary by operating system)
executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
// Headless mode disabled to display the browser window
headless: false,
// Additional arguments passed to the browser
args: ['--remote-debugging-port=0'],
});
const page = await browser.newPage();
await page.setViewport({
width: 1920,
height: 1080,
});
// Navigate to Skyrock mobile login page
await page.goto('https://www.skyrock.com/mobile/?connect=1');
// Perform an evaluation on the page
await page.evaluate(async () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
// Select and log the elements with class 'css-5a47r'
const elements = document.querySelectorAll('.css-5a47r');
elements.forEach((element) => console.log(element));
if (elements.length >= 2) {
// Simulate a click event on the second element
const secondElement = elements[1];
const clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
secondElement.dispatchEvent(clickEvent);
}
});
// Wait for the login input fields to appear
await page.waitForSelector('#login');
await page.waitForSelector('#password');
// Enter the login credentials from environment variables
// Make sure to update the 'xxx' values in the .env file with your actual username and password
if (process.env.USERNAME === 'xxx' || process.env.PASSWORD === 'xxx' || !process.env.USERNAME || !process.env.PASSWORD) {
console.log('Missing or incorrect username and/or password. Please check your .env file.');
} else {
await page.type('#login', process.env.USERNAME);
await page.type('#password', process.env.PASSWORD);
}
// Click on the targets elements with class 'bouton_wide' and id 'barrenoire_post_link'
await page.waitForSelector('.bouton_wide');
await page.click('.bouton_wide');
await page.waitForSelector('#barrenoire_post_link');
await page.click('#barrenoire_post_link');
// Process the current page
async function processPage() {
// Select elements with class 'etat-article'
const elementsEtatArticle = document.querySelectorAll('.etat-article');
console.log('Selected elements:', elementsEtatArticle);
const elementsEtatArticleLength = elementsEtatArticle.length;
console.log('Number of elements:', elementsEtatArticleLength);
// Iterate over the elements and perform actions
for (let i = 0; i < elementsEtatArticleLength; i++) {
const elementEtatArticle = elementsEtatArticle[i];
const etatButton = elementEtatArticle.querySelector('.etat2');
// etat0 = 'hors ligne' / etat1 = 'public' / etat2 = 'secret'
// This changes the state of the element to 'secret' (etat2)
// Add a click event listener and simulate a click on the etatButton
elementEtatArticle.addEventListener('click', () => {
etatButton.click();
console.log('Button clicked!');
});
const clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
elementEtatArticle.dispatchEvent(clickEvent);
}
// Process pagination
const paginationPage = document.querySelector('.pagination.pagination_admin li.current + li > a');
if (paginationPage) {
const clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
paginationPage.dispatchEvent(clickEvent);
} else {
// Process the final page
// Get the element with id 'barrenoire_account_link' and class 'account_pseudo'
const myDiv = document.querySelector('#barrenoire_account_link .account_pseudo');
console.log(myDiv);
const myDivContent = myDiv.textContent.trim();
myBlogUrl = `https://${myDivContent}.skyrock.com/secret`;
console.log(myBlogUrl);
// Open a new window/tab with the myBlogUrl
const newPage = await window.open(myBlogUrl, '_blank');
return newPage;
}
}
// Process next page recursively
async function processNextPage() {
await new Promise((resolve) => setTimeout(resolve, 1000));
await page.evaluate(processPage);
await page.waitForNavigation();
await processNextPage();
}
// Start the processing of pages
await processNextPage();
// Close the browser
await browser.close();
}
// Run the main function and catch any errors
run().catch((error) => console.error(error));