-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGamesense Loader Download-1.0.user.js
80 lines (69 loc) · 3.04 KB
/
Gamesense Loader Download-1.0.user.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
// ==UserScript==
// @name Gamesense Loader Download
// @description Script that adds download buttons for the latest CS2 & CS:GO loader
// @version 1.0
// @author Exodouding
// @match https://gamesense.pub/forums/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=gamesense.pub
// ==/UserScript==
(function() {
'use strict';
function addDownloadButtons() {
var autoDownloadLink = document.createElement("li");
autoDownloadLink.id = "navpayment";
autoDownloadLink.innerHTML = '<a href="" id="cs2DownloadButton">Download CS2 Loader</a>';
var csgoDownloadLink = document.createElement("li");
csgoDownloadLink.id = "navpayment-csgo";
csgoDownloadLink.innerHTML = '<a href="" id="csgoDownloadButton">Download CS:GO Loader</a>';
var premiumElement = document.getElementById("navpremium");
if (premiumElement) {
premiumElement.parentNode.insertBefore(autoDownloadLink, premiumElement.nextSibling);
premiumElement.parentNode.insertBefore(csgoDownloadLink, autoDownloadLink.nextSibling);
}
var downloadButton = document.getElementById("cs2DownloadButton");
if (downloadButton) {
downloadButton.addEventListener('click', function(event) {
event.preventDefault();
fetchUserIdAndRedirect("cs2");
});
}
var csgoButton = document.getElementById("csgoDownloadButton");
if (csgoButton) {
csgoButton.addEventListener('click', function(event) {
event.preventDefault();
fetchUserIdAndRedirect("csgo");
});
}
}
function fetchUserIdAndRedirect(version) {
var profileLink = document.querySelector('#navprofile a');
if (profileLink) {
var urlParams = new URLSearchParams(profileLink.href.split('?')[1]);
var userId = urlParams.get('id');
if (userId) {
redirectToPremiumPage(userId, version);
}
}
}
function redirectToPremiumPage(userId, version) {
var premiumPageUrl = `https://gamesense.pub/forums/profile.php?section=premium&id=${userId}`;
sessionStorage.setItem('triggerDownload', version);
sessionStorage.setItem('userId', userId);
window.location.href = premiumPageUrl;
}
function triggerDownloadOnPremiumPage() {
var shouldTriggerDownload = sessionStorage.getItem('triggerDownload');
if (shouldTriggerDownload) {
sessionStorage.removeItem('triggerDownload');
var downloadButtonName = shouldTriggerDownload === "cs2" ? "download_client" : "download_client_csgo";
var existingDownloadButton = document.querySelector(`input[name="${downloadButtonName}"].button`);
if (existingDownloadButton) {
existingDownloadButton.click();
}
}
}
addDownloadButtons();
if (window.location.href.includes('section=premium')) {
triggerDownloadOnPremiumPage();
}
})();