// ==UserScript==
// @name SBI YONO - Allow Custom Date Range and PDF
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Allows Custom Date Range and PDF; blocks other options
// @match https://yonoretail.sbi.bank.in/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function () {
'use strict';
const ALLOWED_OPTIONS = [
'Custom Date Range',
'PDF'
];
const ERROR_MESSAGE =
'The service is temporarily closed. Please try again later.';
function getOption(event) {
if (!(event.target instanceof Element)) {
return null;
}
return event.target.closest(
'mat-option, [role="option"], .mat-mdc-option'
);
}
function getOptionText(option) {
return option?.textContent
.replace(/\s+/g, ' ')
.trim() || '';
}
function isAllowed(option) {
return ALLOWED_OPTIONS.includes(getOptionText(option));
}
function blockEvent(event, showMessage = false) {
const option = getOption(event);
if (!option || isAllowed(option)) {
return;
}
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
if (showMessage) {
alert(ERROR_MESSAGE);
}
}
// Block unwanted mouse selections
document.addEventListener('pointerdown', event => {
blockEvent(event, false);
}, true);
document.addEventListener('click', event => {
blockEvent(event, true);
}, true);
// Block unwanted keyboard selections
document.addEventListener('keydown', event => {
if (event.key === 'Enter' || event.key === ' ') {
blockEvent(event, true);
}
}, true);
})();2 views