Grundo's Cafe Remember Training Selection

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
});