Last active
February 19, 2026 12:28
-
-
Save simurq/ae3c9b6ac09dc9f8813e68ff6bacc32f to your computer and use it in GitHub Desktop.
Modified lookup.js for Calibre 9.0+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* vim:fileencoding=utf-8 | |
| * | |
| * Combined Lookup Script for Calibre E-Reader | |
| * Supported Dictionaries: | |
| - Al-Maany (Arabic to/from multiple languages) | |
| - Cambridge | |
| - DeepL Translator | |
| - Dictionary.com | |
| - Etymological Dictionary of English | |
| - Kartaslov.ru (Russian Thesaurus) | |
| - Longman | |
| - Merriam-Webster | |
| - Multitran (Russian to/from multiple languages) | |
| - Nişanyan Sözlük (Turkish Thesaurus) | |
| - OneLook Dictionary | |
| - Oxford Hindi-English (McGregor, R. S.) | |
| - Oxford Persian-English (Steingass, F. J.) | |
| - TurEng (Turkish to/from multiple languages) | |
| - Urban Dictionary | |
| - Wikiwand (Wikipedia re-styled) | |
| * Author: Victor Quebec | |
| * Date: Feb 19, 2026 | |
| * Version: 1.3 | |
| * Supported Calibre version: 9.0 and above | |
| */ | |
| /* --- DEFAULT DICTIONARY TEMPLATE --- | |
| You can use this as a template to add new dictionaries | |
| by replacing the asterisk content with relevant dictionary name and style. | |
| // --- *** CLEANUP --- | |
| function fix_***_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-***-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-***-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| *** relpace this placemark with pure CSS rules *** | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_***_markup() failed with error:", e); | |
| } | |
| } | |
| --- DEFAULT INITIALIZATION TEMPLATE --- | |
| else if (host.indexOf('my_dictionary.com') !== -1) { // <-- URL of the dictionary website | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_***_markup); // <-- function title from the above dictionary template | |
| } else { | |
| fix_***_markup(); // <-- function title from the above dictionary template | |
| } | |
| } | |
| */ | |
| (function() { | |
| "use strict"; | |
| // Inject global CSS variables | |
| function inject_root_vars() { | |
| if (document.getElementById('calibre-root-vars')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-root-vars'; | |
| /* For the details of global CSS variables used in this script, please check: | |
| https://lumetrium.com/definer/wiki/css/#css-variables-theming-system */ | |
| style.textContent = ` | |
| :root { | |
| --accent-rgb: 255,248,225; | |
| --anchor-rgb: 166,215,255; | |
| --border-radius-left-bottom: 4px; | |
| --border-radius-left-top: 4px; | |
| --border-radius-right-bottom: 4px; | |
| --border-radius-right-top: 4px; | |
| --border-radius: 4px; | |
| --contrast-rgb: 255,255,255; | |
| --error-rgb: 244,67,54; | |
| --font-family: "Roboto", sans-serif; | |
| --font-size: 16px; | |
| --font-weight: normal; | |
| --ground-rgb: 52,58,64; | |
| --info-rgb: 84,110,122; | |
| --primary-rgb: 163,102,0; | |
| --ptext-rgb: 255,160,0; | |
| --secondary-rgb: 69,90,100; | |
| --success-rgb: 76,175,80; | |
| --text-rgb: 255,255,255; | |
| --v-accent-base: #fff8e1; | |
| --v-anchor-base: #a6d7ff; | |
| --v-border-base: rgba(255,255,255,0.12); | |
| --v-border-darken1: rgba(255,255,255,0.25); | |
| --v-border-darken2: rgba(255,255,255,0.4); | |
| --v-contrast-base: #ffffff; | |
| --v-error-base: #f44336; | |
| --v-ground-base: #343a40; | |
| --v-info-base: #546e7a; | |
| --v-ptext-base: #ffa000; | |
| --v-secondary-base: #455a64; | |
| --v-success-base: #4caf50; | |
| --v-text-base: #ffffff; | |
| --v-warning-base: #ff5722; | |
| --warning-rgb: 255,87,34; | |
| } | |
| `; | |
| (document.head || document.documentElement).appendChild(style); | |
| } | |
| if (document.head || document.documentElement) { | |
| inject_root_vars(); | |
| } else { | |
| document.addEventListener('DOMContentLoaded', inject_root_vars); | |
| } | |
| // --- GOOGLE SPECIFIC VARIABLES --- | |
| var google_num_tries = 0; | |
| var google_style_id = 'a' + Math.random().toString(36).slice(2); | |
| // --- GOOGLE CLEANUP --- | |
| function fix_google_markup() { | |
| try { | |
| var cc = document.getElementById('center_col'); | |
| if (!cc) { | |
| if (++google_num_tries > 10) return; | |
| return setTimeout(fix_google_markup, 100); | |
| } | |
| // Figure out if they actually got a dictionary card | |
| var is_dictionary_result = !!document.querySelector('.lr_container, .lr_dct_ent'); | |
| if (is_dictionary_result) { | |
| // Only add styles once to prevent duplication | |
| if (!document.getElementById(google_style_id)) { | |
| var style = document.createElement('style'); | |
| style.id = google_style_id; | |
| style.textContent = ` | |
| * { | |
| column-gap: 0!important; | |
| -webkit-column-gap: 0!important; | |
| } | |
| #center_col { | |
| position: absolute !important; | |
| top: 1px !important; | |
| left: 0 !important; | |
| z-index: 100; | |
| } | |
| #cnt { | |
| position: relative; | |
| min-height: 100vh; | |
| } | |
| /* Clear the space where search form was */ | |
| #searchform, #appbar, #before-appbar { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } | |
| var maxW = 'calc(100vw - 25px)'; | |
| cc.style.maxWidth = maxW; | |
| cc.style.marginLeft = '0'; | |
| ['rcnt', 'cnt', 'search'].forEach(function(id) { | |
| var e = document.getElementById(id); | |
| if (e) { | |
| if (id === 'search') e.style.maxWidth = maxW; | |
| else if (id === 'cnt') e.style.paddingTop = '0'; | |
| else e.style.marginLeft = '0'; | |
| } | |
| }); | |
| cc.style.paddingLeft = '0'; | |
| cc.style.paddingRight = '6px'; | |
| // Constrain define text | |
| document.querySelectorAll('[data-topic]') | |
| .forEach(e => e.style.maxWidth = maxW); | |
| // Ensure footer stays at bottom | |
| var cnt = document.getElementById('cnt'); | |
| if (cnt) cnt.style.minHeight = '100vh'; | |
| } | |
| // Hide bunch of useful UI elements | |
| ['sfcnt', 'top_nav', 'easter-egg', 'topstuff', 'searchform', 'appbar', 'before-appbar'] | |
| .forEach(function(id) { | |
| var e = document.getElementById(id); | |
| if (e && e.style) e.style.display = 'none'; | |
| }); | |
| // Remove promo sidebar | |
| var promo = document.getElementById('promos'); | |
| if (promo) promo.remove(); | |
| document.querySelectorAll('[data-ved]') | |
| .forEach(e => e.style.maxWidth = '100%'); | |
| document.querySelectorAll('cite') | |
| .forEach(c => { | |
| var wrap = c.closest('div'); | |
| if (wrap) wrap.style.position = 'static'; | |
| }); | |
| } catch (e) { | |
| console.error("fix_google_markup() failed with error:", e); | |
| } | |
| } | |
| // --- ALMAANY.COM CLEANUP --- | |
| function fix_almaany_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-almaany-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-almaany-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| /* Declutter the webpage */ | |
| header, footer, #search-block, #search-home, #sticky-header, #word-idx, .ad, .breadcrumb, .sidebar-column { | |
| display: none !important; | |
| } | |
| .mainbar-column { | |
| float: none !important; | |
| width: 100% !important; | |
| } | |
| /* body, .mainbar-column, | |
| .pagination, .panel, .panel-body, | |
| .panel-heading, .panel-lightblue, td | |
| { | |
| background-color: #343a40 !important; | |
| color: #f8f8f2 !important; | |
| } | |
| / * Buttons * / | |
| .dropdown button, .next { | |
| background-color: var(--v-ground-base) !important; | |
| border-color: #337ab7 !important; | |
| color: #f8f8f2 !important; | |
| } */ | |
| /* Remove Google ads block */ | |
| iframe[id^="google"] { | |
| display: none !important; | |
| } | |
| /* Increase font size conditionally: applied to columns with Arabic text only */ | |
| .arabic-column { | |
| font-size: 1.5em !important; | |
| line-height: 1.5 !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| // Detect Arabic columns and apply styling conditionally | |
| // function styleArabicColumns() { | |
| // var arabicRegex = /[\u0600-\u06FF]/; // Arabic Unicode range: U+0600 to U+06FF | |
| // // Find all columns in main translation block, tables 'Words and Phrases' and 'Contextual Example' | |
| // var columns = document.querySelectorAll('.col-md-6.text-left.bd-plain, .col-md-6.text-right.bd-plain, .text-right, td[id^="m"]'); | |
| // columns.forEach(function(column) { | |
| // var text = column.textContent || column.innerText; | |
| // // If column contains Arabic characters, mark it for larger font | |
| // if (arabicRegex.test(text)) { | |
| // column.classList.add('arabic-column'); | |
| // } | |
| // }); | |
| // } | |
| // // Run detection after DOM is fully loaded | |
| // if (document.readyState === 'loading') { | |
| // document.addEventListener('DOMContentLoaded', styleArabicColumns); | |
| // } else { | |
| // styleArabicColumns(); | |
| // } | |
| // // Also run detection after a short delay to catch dynamically loaded content | |
| // setTimeout(styleArabicColumns, 500); | |
| } catch (e) { | |
| console.error("fix_almaany_markup() failed with error:", e); | |
| } | |
| } | |
| // --- CAMBRIDGE.ORG CLEANUP --- | |
| function fix_cambridge_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-cambridge-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-cambridge-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| body #stickyslot_placeholder, div[class^="csr-"], h1.ti, #footer, | |
| #header, #onetrust-consent-sdk, #pbSurveyContainer, #rightcol-above-sticky, | |
| #stickyslot_container, .am-default, .am-default_moreslots, | |
| .dwl.hax, .ex-opinion, .hfr-s.lt2s.lmt-10, .pb-inline-sense, | |
| .pr.x.lbb.lb-cm, .topslot-container { | |
| display: none !important; | |
| } | |
| body, .page, .def-body, .sense-body, .dphrase-block, .daccord, .bw, .drunon, #translations { | |
| background: var(--v-ground-base) !important; | |
| color: var(--v-text-base) !important; | |
| } | |
| .h1, .h2, .h3, .dpos-h_hw, .tc-bd, .dsense_h { | |
| color: var(--v-ptext-base) !important; | |
| } | |
| a, .ibd, .iw, .i, .tc-bb { | |
| color: var(--v-anchor-base) !important; | |
| } | |
| .cb i, .cb i:before, .cb i:after { | |
| background: var(--v-anchor-base) !important; | |
| } | |
| .habg:hover, .bo { | |
| background: var(--v-secondary-base) !important; | |
| color: var(--v-text-base) !important; | |
| } | |
| .dwla, .bb { | |
| background: var(--v-primary-base) !important; | |
| color: var(--v-contrast-base) !important; | |
| } | |
| .bh, .bhb { | |
| background: var(--v-ground-darken1) !important; | |
| color: var(--v-text-base) !important; | |
| } | |
| .i-amphtml-notbuilt { | |
| color: var(--v-text-base) !important; | |
| } | |
| .lb, #translations { | |
| border: 1px solid var(--v-primary-base) !important; | |
| } | |
| .cc { | |
| padding-top: 0 !important; | |
| } | |
| #page-content { | |
| margin-top: 0 !important; | |
| } | |
| .dsense-noh, .dsense { | |
| border-color: rgba(var(--text-rgb), 0.12) !important; | |
| } | |
| .def-body > *, .def-head > * { | |
| font-size: var(--font-size) !important; | |
| } | |
| .dthesButton { | |
| color: black; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_cambridge_markup() failed with error:", e); | |
| } | |
| } | |
| // --- DEEPL CLEANUP --- | |
| function fix_deepl_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-deepl-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-deepl-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| footer, | |
| header, | |
| #cookieBanner, | |
| .pointer-events-auto, | |
| .sticky, | |
| .\\[\\.is-home_\\&\\]\\:hidden { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_deepl_markup() failed with error:", e); | |
| } | |
| } | |
| // --- DICTIONARY.COM CLEANUP --- | |
| function fix_dictionary_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-dict-com-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-dict-com-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| /* Declutter the webpage */ | |
| aside, nav, [class*="sidebar"], [class*="nav"], header, hr, footer, | |
| video, .acw, .box-additional, .box-content-top, .cmasAdRoot, | |
| .copyright-txt, .grecaptcha-badge, .grecaptcha-logo, .wrapper-site-hdr, | |
| [data-type="browse-module"], [data-type="common-quiz-module"], | |
| [data-type="dictionary-carambola-ad"], [data-type="dictionary-page-navigation-module"], | |
| [data-type="view-definitions-or-synonyms-for"], [data-type="words-nearby-module"], [data-type="xotd-module"] { | |
| display: none !important; | |
| } | |
| /* Links' colour */ | |
| a { | |
| color: #0059d1 !important; | |
| } | |
| /* Webpage colour */ | |
| [data-type="page"] { | |
| background-color: #343a40 !important; | |
| color: #f8f8f2 !important; | |
| } | |
| /* Decrease the margin of main container */ | |
| .wrapper-site-main { | |
| margin-top: 1em !important; | |
| } | |
| /* 'Discover More' text colour */ | |
| #example-sentences, | |
| #idioms-and-phrases, | |
| #other-words-from, | |
| #related-words, | |
| #synonym-study, | |
| #word-history-and-origins { | |
| color: #343a40 !important; | |
| } | |
| /* Ensure the lookup word section remains visible */ | |
| .dictionary-entry, [class*="primary-definition"], .part-of-speech { | |
| display: block !important; | |
| margin: 0 auto !important; | |
| width: 100% !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_dictionary_markup() failed with error:", e); | |
| } | |
| } | |
| // --- ETYMONLINE.COM CLEANUP --- | |
| function fix_etymonline_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-etymonline-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-etymonline-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| /* Declutter the webpage */ | |
| header, footer, .adsbygoogle, .backdrop-blur-md, .bottom-0, | |
| .mt-0, .my-4, .mt-4.space-y-2, .space-y-8, .sticky { | |
| display: none !important; | |
| } | |
| /* Main block positioning */ | |
| .container.flex-1.py-4 { | |
| padding: 1.5em !important; | |
| margin: 0 !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_etymonline_markup() failed with error:", e); | |
| } | |
| } | |
| // --- KARTASLOV.RU CLEANUP --- | |
| function fix_kartaslov_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-kartaslov-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-kartaslov-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| img, #bottom-bar, #searchForm, .col-lg-2, .footer, .navbar, .v4-breadcrumbs-bar, | |
| [class*="yandex"], [id*="lampobot"], [id*="lx"], [id*="yandex"] { | |
| display: none !important; | |
| } | |
| .container { | |
| padding: 5 0 !important; | |
| margin: 0 0 !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_kartaslov_markup() failed with error:", e); | |
| } | |
| } | |
| // --- LONGMAN CLEANUP --- | |
| function fix_longman_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-longman-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-longman-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| /* Declutter the webpage */ | |
| .am-dictionary, | |
| .column-left, | |
| .footer, | |
| .header, | |
| .parallax-container, | |
| .right_col, | |
| [aria-label="Cookie banner"] { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_longman_markup() failed with error:", e); | |
| } | |
| } | |
| // --- MERRIAM-WEBSTER CLEANUP --- | |
| function fix_mw_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-mw-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-mw-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| body div#cmpwrapper.cmpwrapper:empty, #anchor-seporator, #definition-right-rail, #gdpr-consent-tool-wrapper, | |
| #main-banner-ad-container, #mw-sidebar-nav-container, #related-articles, #social-links, #subscribe-unabridged, | |
| #unabridged-promo, .additional-content-area, .adthrive-ad, .disclaimer, .global-footer, .header-placeholder, | |
| .read-more-content-hint-container:after, .read-more-content-hint-toggler, .right-rail, .top-header { | |
| display: none !important; | |
| } | |
| h1, p, #citations label, #citations select, .badge, .body-500-normal, .card p, .content-section-sub-header, | |
| .entry-header, .error_cont, .et_snote, .ex-sent, .example_sentences, .form-select, .function-label, | |
| .function-label-header, .headword-row .vrs, .left-content, .left-content span.mw.no-badge, | |
| .letter, .mw_t_sp, .num, .prons-entry-list-item .l, .prt-a .mw, .redesign-container, .sub-num, | |
| .thread-anchor-content, .vg a.play-pron-v2, .vg-ins, .vg-sseq-entry-item-label, .word-history, | |
| .word-syllables-entry, .word-syllables-prons-header-content .play-pron-v2:hover, | |
| .word-syllables-prons-header-content, .words_fail_us_cont li { | |
| color: var(--v-text-base) !important; | |
| } | |
| .hword { | |
| font-size: 32px !important; | |
| } | |
| .redesign-container, .entry-attr, .ex-sent, .redesign-container a, | |
| .redesign-container .left-content p { | |
| font-size: var(--font-size) !important; | |
| } | |
| .widget { | |
| padding-bottom: 15px; | |
| padding-top: 10px; | |
| } | |
| .vg .vg-sseq-entry-item .sb .sb-entry { | |
| padding-bottom: 4px !important; | |
| } | |
| .outer-container { | |
| top: 0 !important; | |
| } | |
| .long-headword .syl, .card-box { | |
| background-color: transparent !important; | |
| } | |
| html, #left-content, .bg-white { | |
| background: var(--v-ground-base) !important; | |
| --bs-body-bg: var(--v-ground-base) !important; | |
| --bs-body-color: var(--v-text-base) !important; | |
| } | |
| .content-section-header, .badge, .card-body, .form-select, | |
| .redesign-container .il.il-badge, .error_cont .words_fail_us_cont { | |
| background-color: var(--v-secondary-base) !important; | |
| } | |
| .btn { | |
| background: var(--v-primary-base) !important; | |
| color: var(--v-contrast-base) !important; | |
| border: none; | |
| } | |
| body .entry-header .word-syllables-prons-header-content .play-pron-v2:active { | |
| background: rgba(var(--secondary-rgb), 0.6) !important; | |
| } | |
| path[fill="#303336"] { | |
| fill: var(--v-text-base) !important; | |
| } | |
| a, .important-blue-link, .sense .thes-relevance-meter .meter div:first-child, | |
| .mw-grid-table-list ul li a span { | |
| color: var(--v-anchor-base) !important; | |
| } | |
| .example_sentences, .ex-sent, .mw_t_sp, .word-syllables-entry, | |
| .mw.no-badge, .et_snote, .prons-entry-list-item .l, #citations select, | |
| .body-500-normal, .prt-a .mw { | |
| opacity: 0.9; | |
| } | |
| .example_sentences .auth { | |
| color: rgba(var(--text-rgb), 0.7) !important; | |
| } | |
| .ure, h2 { | |
| -webkit-text-fill-color: var(--v-text-base) !important; | |
| text-fill-color: var(--v-text-base) !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_mw_markup() failed with error:", e); | |
| } | |
| } | |
| // --- MULTITRAN.COM CLEANUP --- | |
| function fix_multitran_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-multitran-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-multitran-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| #__ap_gfc_consent_box_btn__, #start > table:first-child, #translation, | |
| .adfinity-body, .adp_interactive_ad, .banner_top, .empty5, .mclass160_120 .menu, | |
| .mclass160_120 .menu1, .menu, .menu1, .middle_mobile, .offset1, lclass160, | |
| rclass300 { | |
| display: none !important; | |
| } | |
| a { | |
| color: var(--v-anchor-base) !important; | |
| } | |
| html, body, .left_col_mobile { | |
| background: var(--v-ground-base) !important; | |
| color: var(--v-text-base) !important; | |
| } | |
| .orig11, .grayline { | |
| background: rgba(var(--text-rgb), 0.08) !important; | |
| color: var(--v-text-base) !important; | |
| } | |
| td { | |
| color: var(--v-text-base) !important; | |
| } | |
| span[style="color:gray"] { | |
| color: rgba(var(--text-rgb), 0.7) !important; | |
| } | |
| .mclass160_120, .mclass160_300 { | |
| padding: 0 1em; | |
| } | |
| td.phras_cnt { | |
| padding-right: 0.2em !important; | |
| } | |
| .container { | |
| margin: 0 0.5em; | |
| } | |
| .mclass160_10 { | |
| padding-left: 0; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_multitran_markup() failed with error:", e); | |
| } | |
| } | |
| // --- NİŞANYANSÖZLÜK CLEANUP --- | |
| function fix_ns_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-ns-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-ns-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| footer, nav { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_ns_markup() failed with error:", e); | |
| } | |
| } | |
| // --- ONELOOK CLEANUP --- | |
| function fix_onelook_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-onelook-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-onelook-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| body > table > tbody > tr > td, center:nth-of-type(1), center:nth-of-type(2), | |
| center:nth-of-type(3), center:nth-of-type(4), #olform > center, #dmapi_cls, | |
| #section-dicts, #snippets_mid, .cyj--wrapper, .medo-hw, .ol_inbrief, .ol_searchassist { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_onelook_markup() failed with error:", e); | |
| } | |
| } | |
| // --- OXFORD DICTIONARIES CLEANUP --- | |
| function fix_oxford_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-oxford-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-oxford-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| #query_display, | |
| #responsive_results_banner_table { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_oxford_markup() failed with error:", e); | |
| } | |
| } | |
| // --- TURENG.COM CLEANUP --- | |
| function fix_tureng_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-tureng-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-tureng-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| footer, .affix-top, .nts-ad, .termresults-ad-tr, .tureng-navbar, .tureng-searchform-container-container, | |
| .tureng-searchresults-col-left.col-md-8.col-lg-8 > div > .nts-ad-h280.nts-ad { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_tureng_markup() failed with error:", e); | |
| } | |
| } | |
| // --- URBAN DICTIONARY CLEANUP --- | |
| function fix_ud_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-ud-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-ud-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| aside, header, main#main-content [class*="leaderboard"], main#main-content [class*="mobile_leaderboard"], | |
| #rc-anchor-alert, .ad-panel, .ad-slot, .grecaptcha-badge, .py-2, .rc-anchor, .rc-anchor-invisible, | |
| .rc-anchor-invisible-hover, .static | |
| { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_ud_markup() failed with error:", e); | |
| } | |
| } | |
| // --- WIKIWAND CLEANUP --- | |
| function fix_wikiwand_markup() { | |
| try { | |
| // Check if styles are already injected to avoid duplication | |
| if (document.getElementById('calibre-wikiwand-styles')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-wikiwand-styles'; | |
| // Injected CSS string | |
| style.textContent = ` | |
| #navbar, [class*="extensions_wrapper"], [class*="footer_wrapper"], [class*="navbar_wrapper"], | |
| [class*="sidebar_wrapper"], [class*="wrapper_incontent"], [class*="wrapper_wrapper"] { | |
| display: none !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } catch (e) { | |
| console.error("fix_wikiwand_markup() failed with error:", e); | |
| } | |
| } | |
| // --- INITIALIZATION --- | |
| var host = location.hostname; | |
| if (host.indexOf('google.com') !== -1) { | |
| window.addEventListener('DOMContentLoaded', fix_google_markup); | |
| // Re-run on resize to handle Google's dynamic layout changes | |
| window.addEventListener('resize', function() { | |
| google_num_tries = 0; | |
| fix_google_markup(); | |
| }); | |
| } else if (host.indexOf('urbandictionary.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_ud_markup); | |
| } else { | |
| fix_ud_markup(); | |
| } | |
| } else if (host.indexOf('almaany.com') !== -1) { | |
| // Inject styles immediately if DOM is ready, otherwise wait | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_almaany_markup); | |
| } else { | |
| fix_almaany_markup(); | |
| } | |
| } else if (host.indexOf('dictionary.cambridge.org') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_cambridge_markup); | |
| } else { | |
| fix_cambridge_markup(); | |
| } | |
| } else if (host.indexOf('deepl.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_deepl_markup); | |
| } else { | |
| fix_deepl_markup(); | |
| } | |
| } else if (host.indexOf('dictionary.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_dictionary_markup); | |
| } else { | |
| fix_dictionary_markup(); | |
| } | |
| } else if (host.indexOf('etymonline.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_etymonline_markup); | |
| } else { | |
| fix_etymonline_markup(); | |
| } | |
| } else if (host.indexOf('kartaslov.ru') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_kartaslov_markup); | |
| } else { | |
| fix_kartaslov_markup(); | |
| } | |
| } else if (host.indexOf('ldoceonline.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_longman_markup); | |
| } else { | |
| fix_longman_markup(); | |
| } | |
| } else if (host.indexOf('merriam-webster.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_mw_markup); | |
| } else { | |
| fix_mw_markup(); | |
| } | |
| } else if (host.indexOf('multitran.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_multitran_markup); | |
| } else { | |
| fix_multitran_markup(); | |
| } | |
| } else if (host.indexOf('nisanyansozluk.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_ns_markup); | |
| } else { | |
| fix_ns_markup(); | |
| } | |
| } else if (host.indexOf('onelook.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_onelook_markup); | |
| } else { | |
| fix_onelook_markup(); | |
| } | |
| } else if (host.indexOf('uchicago.edu') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_oxford_markup); | |
| } else { | |
| fix_oxford_markup(); | |
| } | |
| } else if (host.indexOf('tureng.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_tureng_markup); | |
| } else { | |
| fix_tureng_markup(); | |
| } | |
| } else if (host.indexOf('wikiwand.com') !== -1) { | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', fix_wikiwand_markup); | |
| } else { | |
| fix_wikiwand_markup(); | |
| } | |
| } | |
| // --- GLOBAL ARABIC TEXT STYLING (wraps only Arabic characters) --- | |
| function inject_arabic_style() { | |
| if (document.getElementById('calibre-global-arabic-style')) return; | |
| var style = document.createElement('style'); | |
| style.id = 'calibre-global-arabic-style'; | |
| style.textContent = ` | |
| .arabic-text { | |
| font-size: 1.5em !important; | |
| line-height: 1.5 !important; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| } | |
| function applyGlobalArabicStyling() { | |
| try { | |
| inject_arabic_style(); | |
| // Regular expression for Arabic characters (Unicode range U+0600 to U+06FF) | |
| var arabicRegex = /[\u0600-\u06FF]/; | |
| // TreeWalker to find all text nodes not already inside an .arabic-text span | |
| var walker = document.createTreeWalker( | |
| document.body, | |
| NodeFilter.SHOW_TEXT, | |
| { | |
| acceptNode: function(node) { | |
| // Skip nodes that are already inside an arabic-text span | |
| if (node.parentElement && node.parentElement.closest('.arabic-text')) { | |
| return NodeFilter.FILTER_REJECT; | |
| } | |
| // Skip empty or whitespace-only nodes | |
| if (!node.nodeValue.trim()) { | |
| return NodeFilter.FILTER_REJECT; | |
| } | |
| // Only process nodes that actually contain Arabic characters | |
| return arabicRegex.test(node.nodeValue) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT; | |
| } | |
| } | |
| ); | |
| var textNodes = []; | |
| while (walker.nextNode()) { | |
| textNodes.push(walker.currentNode); | |
| } | |
| // Process each qualifying text node | |
| textNodes.forEach(function(textNode) { | |
| var text = textNode.nodeValue; | |
| var parent = textNode.parentNode; | |
| if (!parent) return; | |
| // Use a regex that matches one or more Arabic characters | |
| var arabicRunRegex = /[\u0600-\u06FF]+/g; | |
| var lastIndex = 0; | |
| var match; | |
| var fragment = document.createDocumentFragment(); | |
| // Iterate over all Arabic runs in the text | |
| while ((match = arabicRunRegex.exec(text)) !== null) { | |
| // Add preceding non-Arabic text as a plain text node | |
| if (match.index > lastIndex) { | |
| fragment.appendChild(document.createTextNode(text.substring(lastIndex, match.index))); | |
| } | |
| // Wrap the Arabic run in a span with class 'arabic-text' | |
| var span = document.createElement('span'); | |
| span.className = 'arabic-text'; | |
| span.textContent = match[0]; | |
| fragment.appendChild(span); | |
| lastIndex = match.index + match[0].length; | |
| } | |
| // Add any remaining non-Arabic text after the last Arabic run | |
| if (lastIndex < text.length) { | |
| fragment.appendChild(document.createTextNode(text.substring(lastIndex))); | |
| } | |
| // Replace the original text node with the new fragment | |
| parent.replaceChild(fragment, textNode); | |
| }); | |
| } catch (e) { | |
| console.error('applyGlobalArabicStyling() failed:', e); | |
| } | |
| } | |
| // Global Arabic text styling (runs on every page) | |
| if (document.readyState === 'loading') { | |
| window.addEventListener('DOMContentLoaded', applyGlobalArabicStyling); | |
| } else { | |
| applyGlobalArabicStyling(); | |
| } | |
| // Also run after a short delay for dynamically loaded content | |
| setTimeout(applyGlobalArabicStyling, 500); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment