משתמש:Idoiz/FnRdefaults.js
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
// Default values
const defaultFindValue = "[%]|[\u002D\u2010\u2011\u2012\u2014\u2015\u2212\u05BE]|הגיון|ראיון| |ככר|לעתים|ששה|ביתם|ללמעלה|היתה|מלה|אשה|בינלאו|שמים|שניה|000|מאד|יומיומ|\\|[משהוכלב]";
const defaultReplaceValue = "–";
const defaultIsRegexChecked = true;
// Function to set default values to the inputs when they become available
function setDefaultValues() {
const findInput = document.querySelector('input[name="search"][main-field="true"]');
const replaceInput = document.querySelector('input[name="replace"]');
const regexCheckbox = document.querySelector('input[name="re"]');
if (findInput && replaceInput && regexCheckbox) {
findInput.value = defaultFindValue;
replaceInput.value = defaultReplaceValue;
regexCheckbox.checked = defaultIsRegexChecked;
} else {
// If inputs are not yet available, wait and try again
setTimeout(setDefaultValues, 500); // Adjust timeout if needed
}
}
// Monitor DOM changes to detect when the inputs appear
const observer = new MutationObserver(setDefaultValues);
observer.observe(document.body, { childList: true, subtree: true });
// Event listeners to save the values when they change
document.addEventListener('input', (event) => {
const target = event.target;
if (target && (target.name === 'search' || target.name === 'replace' || target.name === 're')) {
saveToLocalStorage();
}
});
// Function to save the values to localStorage
function saveToLocalStorage() {
const findValue = document.querySelector('input[name="search"]').value;
const replaceValue = document.querySelector('input[name="replace"]').value;
const isRegexChecked = document.querySelector('input[name="re"]').checked;
localStorage.setItem('findValue', findValue);
localStorage.setItem('replaceValue', replaceValue);
localStorage.setItem('isRegexChecked', isRegexChecked);
}
// Function to load the values from localStorage
function loadFromLocalStorage() {
const findValue = localStorage.getItem('findValue');
const replaceValue = localStorage.getItem('replaceValue');
const isRegexChecked = localStorage.getItem('isRegexChecked') === 'true';
if (findValue !== null) {
document.querySelector('input[name="search"]').value = findValue;
}
if (replaceValue !== null) {
document.querySelector('input[name="replace"]').value = replaceValue;
}
document.querySelector('input[name="re"]').checked = isRegexChecked;
}
// Load the values when the page loads
window.addEventListener('load', loadFromLocalStorage);