-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfanatical.js
More file actions
128 lines (113 loc) · 5.15 KB
/
fanatical.js
File metadata and controls
128 lines (113 loc) · 5.15 KB
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
// ==UserScript==
// @name Cambiar Orden por defecto de los bundles de Fanatical
// @name:en Change default sorting on bundles page
// @namespace http://tampermonkey.net/
// @version 0.2
// @description Fanatical lo pone por defecto como "Más vendidos". No, no, quiero ver lo más reciente, que si no no me entero de qué hay nuevo
// @description:en By default Fanatical sorts by Popular. I'd like to see what's new so this does it. No more missing bundles.
// @author LinxESP
// @match *://www.fanatical.com/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_registerMenuCommand
// @license MIT
// @downloadURL https://update.greasyfork.org/scripts/528436/Cambiar%20Orden%20por%20defecto%20de%20los%20bundles%20de%20Fanatical.user.js
// @updateURL https://update.greasyfork.org/scripts/528436/Cambiar%20Orden%20por%20defecto%20de%20los%20bundles%20de%20Fanatical.meta.js
// ==/UserScript==
(function() {
'use strict';
// Valores predeterminados
const defaultConfig = {
sortValue: "latest_deals",
delayTime: 100
};
// Obtener la configuración guardada o usar valores predeterminados
function getConfig() {
return {
sortValue: GM_getValue('sortValue', defaultConfig.sortValue),
delayTime: GM_getValue('delayTime', defaultConfig.delayTime)
};
}
// Guardar configuración
function setConfig(config) {
GM_setValue('sortValue', config.sortValue);
GM_setValue('delayTime', config.delayTime);
}
// Configuración actual
const config = getConfig();
// Registrar comandos de menú para cambiar la configuración
GM_registerMenuCommand('⚙️ Configurar valor de ordenamiento', function() {
const options = [
{value: "", label: "Top Sellers"},
{value: "price_asc", label: "Price: Low to High"},
{value: "price_desc", label: "Price: High to Low"},
{value: "name", label: "Alphabetical"},
{value: "discount", label: "Top Discount"},
{value: "latest_deals", label: "Latest Deals"},
{value: "ending_soon", label: "Ending Soon"},
{value: "most_wanted", label: "Most Wanted"},
{value: "release_date_desc", label: "Release: Newest"}
];
let optionsText = "Selecciona el orden por defecto:\n";
options.forEach((opt, index) => {
optionsText += `${index}. ${opt.label}\n`;
});
const selection = prompt(optionsText, config.sortValue);
if (selection !== null) {
// Comprobar si es un número (índice) o un valor directo
if (!isNaN(selection) && selection >= 0 && selection < options.length) {
config.sortValue = options[parseInt(selection)].value;
} else {
// Verificar si el valor ingresado es válido
const validOption = options.find(opt => opt.value === selection);
if (validOption) {
config.sortValue = selection;
} else {
alert('Valor no válido. Por favor selecciona una opción válida.');
return;
}
}
setConfig(config);
alert(`Valor de ordenamiento cambiado a: ${config.sortValue}`);
}
});
GM_registerMenuCommand('⏱️ Configurar tiempo de retraso (ms)', function() {
const newDelay = prompt('Ingresa el tiempo de retraso en milisegundos:', config.delayTime);
if (newDelay !== null) {
const delay = parseInt(newDelay);
if (!isNaN(delay) && delay >= 0) {
config.delayTime = delay;
setConfig(config);
alert(`Tiempo de retraso cambiado a: ${delay}ms`);
} else {
alert('Por favor ingresa un número válido mayor o igual a 0.');
}
}
});
// Función para cambiar el valor del menú desplegable
function changeDropdownValue() {
const selectElement = document.querySelector('.dropdown-container.sort-by select');
if (selectElement) {
// Usar el valor de configuración
selectElement.value = config.sortValue;
// Disparar evento de cambio para asegurar que el sitio detecte el cambio
selectElement.dispatchEvent(new Event('change', { bubbles: true }));
console.log(`La opción de ordenamiento ha sido cambiada a: ${config.sortValue}`);
return true;
}
return false;
}
// Esperar a que el DOM esté completamente cargado
window.addEventListener('load', function() {
// Intento inicial
if (!changeDropdownValue()) {
console.log('No se encontró el elemento del menú desplegable, reintentando...');
// Intentar después del retraso configurado
setTimeout(function() {
if (!changeDropdownValue()) {
console.log('No se pudo encontrar el elemento después del retraso configurado');
}
}, config.delayTime);
}
});
})();