Grundo's Cafe Remember Training Selection

Auto remembers and chooses the user's last selection on the training page on grundos.cafe.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Grundo's Cafe Remember Training Selection
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Auto remembers and chooses the user's last selection on the training page on grundos.cafe.
// @author       Thornruler
// @match    https://www.grundos.cafe/island/training/?type=courses
// @match    https://grundos.cafe/island/training/?type=courses
// @match    https://www.grundos.cafe/pirates/academy/?type=courses
// @match    https://grundos.cafe/pirates/academy/?type=courses
// @match    https://www.grundos.cafe/island/fight_training/?type=courses
// @match    https://grundos.cafe/island/fight_training/?type=courses
// @icon     https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
// @grant    none
// @license MIT
// ==/UserScript==

// Base keys to store/retrieve selections
const BASE_COURSE_TYPE_KEY = 'courseTypeSelection';
const BASE_PET_KEY = 'petSelection';

// Incorporate the current URL into the keys
const COURSE_TYPE_KEY = `${BASE_COURSE_TYPE_KEY}_${window.location.pathname}`;
const PET_KEY = `${BASE_PET_KEY}_${window.location.pathname}`;

const courseTypeSelect = document.querySelector('select[name="course_type"]');
const petSelect = document.querySelector('select[name="pet"]');

// Check if we have a stored selection
const storedCourseType = localStorage.getItem(COURSE_TYPE_KEY);
const storedPet = localStorage.getItem(PET_KEY);

if(storedCourseType) {
    courseTypeSelect.value = storedCourseType;
}

if(storedPet) {
    petSelect.value = storedPet;
}

// Listen for changes and store the selected option
courseTypeSelect.addEventListener('change', function() {
    localStorage.setItem(COURSE_TYPE_KEY, courseTypeSelect.value);
});

petSelect.addEventListener('change', function() {
    localStorage.setItem(PET_KEY, petSelect.value);
});