User:Idoiz/Hebrew-Fixer.js: Difference between revisions – Wikipedia

From Wikipedia, the free encyclopedia

Content deleted Content added


 

Line 12: Line 12:

function addSuggestionBox(fixed) {

function addSuggestionBox(fixed) {

const container =

const container =

document.querySelector(‘.mw-search-formwrapper‘) ||

document.querySelector(‘.mw-search–‘) ||

document.querySelector(‘#mw-content-text’);

document.querySelector(‘#mw-content-text’);

Line 18: Line 18:

const box = document.createElement(‘div’);

const box = document.createElement(‘div’);

box.style.background = ‘#fff8d0‘;

box.style.background = ‘#’;

box.style.border=”1px solid #ccc“;

box.style.border=”1px solid #”;

box.style.padding = ‘10px‘;

box.style.padding = ”;

box.style.margin = ‘12px 0′;

box.style.margin = ‘ 0’;

box.style.fontSize=”15px”;

box.style.fontSize=”15px”;

box.style.borderRadius=”4px“;

box.style.borderRadius=””;

box.style.boxShadow = ‘0 1px 2px rgba(0,0,0,0.08)’;

box.style.lineHeight=”1.5″;

const strong = document.createElement(‘b’);

strong.textContent=”Did you mean: “;

const link = document.createElement(‘a’);

const link = document.createElement(‘a’);

link.href = `/w/index.php?title=Special:Search&search=${encodeURIComponent(fixed)}`;

link.href = `/w/index.php?title=Special:Search&search=${encodeURIComponent(fixed)}`;

link.textContent = `”${fixed}”`;

link.textContent = fixed;

link.style.fontWeight=”bold”;

link.style.color=”#36c”;

link.style.textDecoration = ‘underline’;

box.textContent=”Did you mean: “;

box.;

box.appendChild(link);

box.appendChild(link);

box.appendChild(document.createTextNode(‘ ?’));

container.prepend(box);

container.prepend(box);

Line 37: Line 44:

(function () {

(function () {

// Only run on Special:Search

// Only on Special:Search

if (mw.config.get(‘wgCanonicalSpecialPageName’) !== ‘Search’) return;

if (mw.config.get(‘wgCanonicalSpecialPageName’) !== ‘Search’) return;

Line 43: Line 50:

const term = params.get(‘search’) || ”;

const term = params.get(‘search’) || ”;

// If no Hebrew stop

//

if (!/[א-ת]/.test(term)) return;

if (!/[א-ת]/.test(term)) return;


Latest revision as of 21:24, 30 November 2025

// Hebrew → English physical keyboard mapping
const hebToEngMap = {
    'ש':'a','נ':'b','ב':'c','ג':'d','ק':'e','כ':'f','ע':'g','י':'h','ח':'i',
    'ל':'j','ך':'k','ף':'l','ז':'z','ס':'x','ה':'w','ר':'r','ת':'t','ד':'s',
    'ו':'u','ט':'y','א':'t','מ':'n','צ':'m','ם':'o','ן':'i','פ':'p'
};

function convertHebrew(str) {
    return str.split('').map(ch => hebToEngMap[ch] || ch).join('');
}

function addSuggestionBox(fixed) {
    const container =
        document.querySelector('.mw-search-results-info') ||
        document.querySelector('#mw-content-text');

    if (!container) return;

    const box = document.createElement('div');
    box.style.background = '#f8f9fa';
    box.style.border = '1px solid #c8ccd1';
    box.style.padding = '12px 16px';
    box.style.margin = '16px 0';
    box.style.fontSize = '15px';
    box.style.borderRadius = '6px';
    box.style.boxShadow = '0 1px 2px rgba(0,0,0,0.08)';
    box.style.lineHeight = '1.5';

    const strong = document.createElement('b');
    strong.textContent = 'Did you mean: ';

    const link = document.createElement('a');
    link.href = `/w/index.php?title=Special:Search&search=${encodeURIComponent(fixed)}&fulltext=1&ns0=1`;
    link.textContent = fixed;
    link.style.fontWeight = 'bold';
    link.style.color = '#36c';
    link.style.textDecoration = 'underline';

    box.appendChild(strong);
    box.appendChild(link);

    container.prepend(box);
}

(function () {
    // Only on Special:Search
    if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;

    const params = new URLSearchParams(window.location.search);
    const term = params.get('search') || '';

    // Only act on Hebrew terms
    if (!/[א-ת]/.test(term)) return;

    const fixed = convertHebrew(term);
    if (!fixed || fixed === term) return;

    addSuggestionBox(fixed);
})();

Leave a Comment

Your email address will not be published. Required fields are marked *

Exit mobile version