-
Notifications
You must be signed in to change notification settings - Fork 0
/
icy-veins-leveling-slider-reminder.user.js
69 lines (56 loc) · 2.37 KB
/
icy-veins-leveling-slider-reminder.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
// ==UserScript==
// @name Icy Veins Leveling Slider Reminder
// @description Remembers the last selected level on the Icy Veins Leveling Guide sliders
// @namespace https://github.com/DJScias
// @version 2.0.0
// @author DJScias
// @match https://www.icy-veins.com/wow/*-leveling-guide
// @grant none
// @require http://code.jquery.com/jquery-3.5.1.min.js
// @require https://cdn.jsdelivr.net/npm/js-cookie@3.0.1/dist/js.cookie.min.js
// @license GPLv3
// @homepageURL https://github.com/DJScias/Icy-Veins-Leveling-Slider-Reminder
// @supportURL https://github.com/DJScias/Icy-Veins-Leveling-Slider-Reminder/issues
// @run-at document-end
// ==/UserScript==
/* globals jQuery, $, waitForKeyElements, Cookies */
(function() {
'use strict';
// Check all the sliders and apply saved values
$('.leveling_slider_container input').each(function () {
let id = $(this).parent().attr('id');
let name = id.split("_")[0];
let level = Cookies.get(id);
if (Cookies.get(id) !== undefined) {
$(this).val(level).trigger('change');
// Update the website UI to reflect the level change
$(this).next().find("span").text(level);
let processName = name + '_process_levels';
let processFnc = window[processName];
processFnc(level);
}
$(this).parent().append('<a href="#" id="'+id+'_reset" class="slider_reset">Reset</a>');
});
$(document).on('input', '.leveling_slider_container > input', function() {
let id = $(this).parent().attr('id');
let level = $(this).val();
// Save for a week, that should be fine
Cookies.set(id, level, { expires: 7, path: '' });
});
// Reset button function
$(document).on('click', '.slider_reset', function(e) {
e.preventDefault();
let id = $(this).parent().attr('id');
let name = id.split("_")[0];
let level = 60;
let curid = $(this).parent().attr('id');
$("#" + id + " > input").val(level).trigger('change');
// Update the website UI to reflect the level change
$(this).prev().find("span").text(level);
let processName = name + '_process_levels';
let processFnc = window[processName];
processFnc(level);
// Remove the cookie, we don't need it anymore
Cookies.remove(id, { path: '' });
});
})();