<commit_before>// ==UserScript==
// @name         Grand Canyon Reminder
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Auto Refresh page if no room is changed in the page. When new room appears, there will be Desktop notification as well as info banner for reminding.
// @author       <NAME>
// @match        https://secure.grandcanyonlodges.com/booking/lodging-search*
// @grant GM_addStyle
// @grant GM_notification
// ==/UserScript==

(async () => {
	const targetButtonSelector = 'button.mb-8';
	await waitFor(targetButtonSelector);
	const selectButtons = Array.from(document.querySelectorAll(targetButtonSelector));
	const disabledButtons = selectButtons.filter(b => b.getAttribute('disabled') === 'disabled');
	// console.log(selectButtons.length, disabledButtons.length);
	if (selectButtons.length === disabledButtons.length) {
		console.log(`Not available, sleep and refresh --- ${new Date().toISOString()}`);
		setTimeout(() => location.reload(), 5 * 1000);
	} else {
		console.log(`stop refreshing and send notification --- ${new Date().toISOString()}`);
		const params = new Proxy(new URLSearchParams(window.location.search), {
			get: (searchParams, prop) => searchParams.get(prop),
		});
		const notificationDetails = {
			text: 'New Room available',
			title: `Date: ${params.dateFrom}`,
			timeout: 10000,
		};
		notificationDetails.onclick = () => {
			parent.focus();
			window.focus(); //just in case, older browsers
			this.close();
		}
		GM_notification(notificationDetails);
	}
})();

/**
 * wait for element to appear in dom.
 * @returns a Promise which resolves when the element shows up.
 */
function waitFor(selector) {
	return new Promise(function (res, rej) {<commit_msg>extract the refresh/notification time<commit_after>// ==UserScript==
// @name         Grand Canyon Reminder
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Auto Refresh page if no room is changed in the page. When new room appears, there will be Desktop notification as well as info banner for reminding.
// @author       <NAME>
// @match        https://secure.grandcanyonlodges.com/booking/lodging-search*
// @grant GM_addStyle
// @grant GM_notification
// ==/UserScript==

(async () => {
	const targetButtonSelector = 'button.mb-8';
	await waitFor(targetButtonSelector);
	const selectButtons = Array.from(document.querySelectorAll(targetButtonSelector));
	const disabledButtons = selectButtons.filter(b => b.getAttribute('disabled') === 'disabled');
	// console.log(selectButtons.length, disabledButtons.length);
	if (selectButtons.length === disabledButtons.length) {
		const refreshInterval = 5; // 页面刷新间隔
		console.log(`Not available, sleep and refresh --- ${new Date().toISOString()}`);
		setTimeout(() => location.reload(), refreshInterval * 1000);
	} else {
		console.log(`stop refreshing and send notification --- ${new Date().toISOString()}`);
		const params = new Proxy(new URLSearchParams(window.location.search), {
			get: (searchParams, prop) => searchParams.get(prop),
		});
		const notificationTimeout = 10; // notification显示时间
		const notificationDetails = {
			text: 'New Room available',
			title: `Date: ${params.dateFrom}`,
			timeout: notificationTimeout * 1000,
		};
		notificationDetails.onclick = () => {
			parent.focus();
			window.focus(); //just in case, older browsers
			this.close();
		}
		GM_notification(notificationDetails);
	}
})();

/**
 * wait for element to appear in dom.
 * @returns a Promise which resolves when the element shows up.
 */
function waitFor(selector) {
	return new Promise(function (res, rej) {
{'fraction_non_alphanumeric': 0.14451827242524917, 'fraction_numerical': 0.007475083056478406, 'mean_word_length': 4.081575246132208, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1995159', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1051, 'n_words': 290}