Errors
unknown
java
2 years ago
11 kB
6
No Index
package com.felixgarske.scraper.scraper;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Label;
import java.awt.event.ActionListener;
import java.io.File;
import java.time.Duration;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.event.ActionEvent;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class MainFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private Label lStatus;
private Label lBalance;
private Label lBalancetotal;
private String userDataDirectory = "C:\\Users\\Felix\\Documents\\ChromeProfiles";
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
MainFrame frame = new MainFrame();
frame.setVisible(true);
Image icon = ImageIO.read(new File("./ico.png"));
frame.setIconImage(icon);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public MainFrame() {
setTitle("SkinClub Free Case Farmer");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 524, 390);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
setResizable(false);
ImageIcon icon = new ImageIcon("/ico.png");
setIconImage(icon.getImage());
chromedriveroptions();
createWebDriver();
JButton btnNewButton_2 = new JButton("Chrome Profil Verzeichnis ändern");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chooseUserDataDirectory();
}
});
btnNewButton_2.setBounds(276, 33, 211, 23);
contentPane.add(btnNewButton_2);
JButton btnNewButton_1 = buttonStopFarming();
btnNewButton_1.setBounds(163, 269, 165, 74);
contentPane.add(btnNewButton_1);
Label label_Balance = new Label("Waffen Skin Guthaben :");
label_Balance.setBounds(10, 95, 123, 47);
contentPane.add(label_Balance);
lBalance = new Label("$0.00");
lBalance.setBounds(163, 95, 64, 47);
contentPane.add(lBalance);
Label label_status = new Label("Status :");
label_status.setBounds(10, 201, 123, 47);
contentPane.add(label_status);
lStatus = new Label("Idle..");
lStatus.setBounds(163, 201, 342, 47);
contentPane.add(lStatus);
buttonStartFarming();
JButton btnNewButton_3 = buttonSellAllWeapons();
btnNewButton_3.setBounds(340, 269, 165, 74);
contentPane.add(btnNewButton_3);
Label label_Balance_1 = new Label("Guthaben");
label_Balance_1.setBounds(10, 148, 123, 47);
contentPane.add(label_Balance_1);
lBalancetotal = new Label("$0.00");
lBalancetotal.setBounds(163, 148, 64, 47);
contentPane.add(lBalancetotal);
buttonRefreshBalance();
}
public ChromeOptions chromedriveroptions() {
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--remote-debugging-port=1224");
options.addArguments("--disable-blink-features=AutomationControlled");
options.addArguments("--user-data-dir=" + userDataDirectory);
options.addArguments("--headless");
return options;
}
public WebDriver createWebDriver() {
ChromeOptions options = chromedriveroptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--remote-debugging-port=1224");
options.addArguments("--disable-blink-features=AutomationControlled");
options.addArguments("--user-data-dir=" +userDataDirectory);
options.addArguments("--headless");
return new ChromeDriver(options);
}
private JButton buttonStopFarming() {
JButton btnNewButton_1 = new JButton("Stop Farming");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ChromeOptions options = chromedriveroptions();
WebDriver driver = new ChromeDriver(options);
lStatus.setText("Farming Beendet");
driver.quit();
}
});
return btnNewButton_1;
}
private JButton buttonSellAllWeapons() {
JButton btnNewButton_3 = new JButton("Alle Waffen Verkaufen");
btnNewButton_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ChromeOptions options = chromedriveroptions();
WebDriver driver = new ChromeDriver(options);
try {
driver.get("https://skin.club/de");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(2));
WebElement button1 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("user-weapon-balance")));
if (!driver.findElements(By.className("user-weapon-balance")).isEmpty()) {
button1.click();
WebElement button2 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("select-all-button")));
button2.click();
WebElement button3 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("sell-all-button")));
button3.click();
WebElement element1 = driver.findElement(By.className("user-money__balances"));
String balancecash = element1.getText();
lBalancetotal.setText(balancecash);
lStatus.setText("Alle Waffen Verkauft!");
List<WebElement> weaponBalanceElements = driver
.findElements(By.className("user-money__balances"));
if (!weaponBalanceElements.isEmpty()) {
WebElement element = weaponBalanceElements.get(0);
String balanceweapons = element.getText();
lBalance.setText(balanceweapons);
} else {
driver.quit();
}
} else {
driver.quit();
}
} catch (Exception e1) {
e1.printStackTrace();
} finally {
lBalance.setText("$0.00");
lStatus.setText("Keine Waffen zum Verkaufen");
driver.quit();
}
}
});
return btnNewButton_3;
}
private void buttonRefreshBalance() {
JButton btnNewButton_4 = new JButton("Guthaben Aktualisieren");
btnNewButton_4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
WebDriver driver = null;
try {
ChromeOptions options = chromedriveroptions();
driver = new ChromeDriver(options);
driver.get("https://skin.club/de");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
WebElement element = wait
.until(ExpectedConditions.visibilityOfElementLocated(By.className("user-money__balances")));
element.click();
WebElement element1 = driver.findElement(By.className("user-money__balances")); // user-balance
// user-money__balances
String balancecash = element1.getText();
lBalancetotal.setText(balancecash);
lStatus.setText("Aktuelles Guthaben wird angezeigt");
if (!driver.findElements(By.className("user-weapon-balance")).isEmpty()) {
WebElement element3 = driver.findElement(By.className("user-weapon-balance"));
String balanceweapons = element3.getText();
lBalance.setText(balanceweapons);
} else {
driver.quit();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (driver != null) {
driver.quit();
}
}
}
});
btnNewButton_4.setBounds(10, 11, 158, 67);
contentPane.add(btnNewButton_4);
}
private void chooseUserDataDirectory() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
userDataDirectory = fileChooser.getSelectedFile().getAbsolutePath();
}
}
private void buttonStartFarming() {
JButton btnNewButton = new JButton("Start Farming...");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Timer timer = new Timer();
TimerTask hourlyTask = new TimerTask() {
@Override
public void run() {
ChromeOptions options = chromedriveroptions();
WebDriver driver = new ChromeDriver(options);
try {
driver.get("https://skin.club/de/cases/open/lvl-3");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
WebElement button1 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("case-buttons")));
button1.click();
driver.get("https://skin.club/de/cases/open/lvl-10");
WebElement button2 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("case-buttons")));
button2.click();
driver.get("https://skin.club/de/cases/open/lvl-20");
WebElement button3 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("case-buttons")));
button3.click();
driver.get("https://skin.club/de/cases/open/lvl-30");
WebElement button4 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("case-buttons")));
button4.click();
driver.get("https://skin.club/de/cases/open/lvl-40");
WebElement button5 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("case-buttons")));
button5.click();
driver.get("https://skin.club/de/cases/open/lvl-50");
WebElement button6 = wait
.until(ExpectedConditions.elementToBeClickable(By.className("case-buttons")));
button6.click();
lStatus.setText("Alle Kisten Geöffnet");
WebElement element1 = driver.findElement(By.className("user-money__balances"));
String balancecash = element1.getText();
lBalancetotal.setText(balancecash);
if (!driver.findElements(By.className("user-weapon-balance")).isEmpty()) {
WebElement element = driver.findElement(By.className("user-weapon-balance"));
String balanceweapons = element.getText();
lBalance.setText(balanceweapons);
}
} finally {
driver.quit();
}
}
};
timer.schedule(hourlyTask, 0l, 1000 * 60 * 60 * 24 + 15000);
}
});
btnNewButton.setBounds(10, 269, 143, 74);
contentPane.add(btnNewButton);
}
}
Editor is loading...
Leave a Comment