This plugin finds Scripture references in your WordPress content, stores open Bible texts in your own database, and shows the matching verses in fast hover and keyboard-focus cards. Start by installing one or more open Bible translations below, choose the translation that should open first, then decide where the scanner should look on your public pages and optional admin screens.
Version Local verse lookupOpen Bible texts
Installed Texts
Install any combination of local Bible texts. Installed translations are automatically available in frontend tooltip tabs; the default translation only controls which one opens first.
This checks whether each installed text has at least one row for every canonical Bible book after source-code interpretation.
Open Text Policy
This plugin is designed for Bible texts that are public domain, openly licensed, or otherwise legally permitted for local storage and display. It does not provide import tools for restricted commercial translations unless a future integration explicitly supports proper licensing.
The built-in importer currently supports selected open/public-domain eBible VPL packages, including WEB, KJV, ASV, YLT, BSB, and OEB-US.
get_results("SELECT translation, COUNT(*) AS verses, MAX(source) AS source FROM " . self::table() . " GROUP BY translation ORDER BY translation ASC");
}
private function text_integrity_summary() {
global $wpdb;
$expected = array_map(function($book) { return $book['abbr']; }, $this->book_registry());
$translations = $wpdb->get_col("SELECT DISTINCT translation FROM " . self::table() . " ORDER BY translation ASC");
$summary = [];
foreach ((array)$translations as $translation) {
$found = $wpdb->get_col($wpdb->prepare(
"SELECT DISTINCT book FROM " . self::table() . " WHERE translation = %s ORDER BY book ASC",
$translation
));
$found = array_values(array_unique(array_map('strtoupper', array_map('strval', $found ?: []))));
$missing = array_values(array_diff($expected, $found));
$summary[] = [
'translation' => strtoupper((string)$translation),
'expected' => count($expected),
'found' => count(array_intersect($expected, $found)),
'missing' => $missing,
'ok' => !$missing,
];
}
return $summary;
}
private function available_translations() {
return [
'WEB' => [
'name' => 'World English Bible',
'url' => 'https://ebible.org/Scriptures/eng-web_vpl.zip',
'file' => 'eng-web_vpl.txt',
'source' => 'eBible WEB VPL',
'license' => 'World English Bible public domain',
],
'KJV' => [
'name' => 'King James Version',
'url' => 'https://ebible.org/Scriptures/eng-kjv_vpl.zip',
'file' => 'eng-kjv_vpl.txt',
'source' => 'eBible KJV VPL',
'license' => 'King James Version public domain in the United States',
],
'ASV' => [
'name' => 'American Standard Version',
'url' => 'https://ebible.org/Scriptures/eng-asv_vpl.zip',
'file' => 'eng-asv_vpl.txt',
'source' => 'eBible ASV VPL',
'license' => 'American Standard Version 1901 public domain',
],
'YLT' => [
'name' => "Young's Literal Translation",
'url' => 'https://ebible.org/Scriptures/engylt_vpl.zip',
'file' => 'engylt_vpl.txt',
'source' => 'eBible YLT VPL',
'license' => "Young's Literal Translation public domain",
],
'BSB' => [
'name' => 'Berean Standard Bible',
'url' => 'https://ebible.org/Scriptures/engbsb_vpl.zip',
'file' => 'engbsb_vpl.txt',
'source' => 'eBible BSB VPL',
'license' => 'Berean Standard Bible public domain',
],
'OEB-US' => [
'name' => 'Open English Bible (US)',
'url' => 'https://ebible.org/Scriptures/engoebus_vpl.zip',
'file' => 'engoebus_vpl.txt',
'source' => 'eBible OEB-US VPL',
'license' => 'Open English Bible public domain',
],
];
}
public function handle_save_settings() {
$this->require_admin();
$translation = strtoupper(sanitize_text_field($_POST['translation'] ?? $this->settings()['translation'] ?? 'WEB'));
$known = array_keys($this->available_translations());
$installed = array_map(function($row) { return $row['code']; }, $this->installed_translations());
if (!in_array($translation, array_unique(array_merge($known, $installed)), true)) $translation = 'WEB';
$theme = sanitize_key($_POST['theme'] ?? 'auto');
if (!in_array($theme, ['auto', 'dark', 'light'], true)) $theme = 'auto';
$settings = [
'enabled' => !empty($_POST['enabled']) ? '1' : '0',
'admin_enabled' => !empty($_POST['admin_enabled']) ? '1' : '0',
'translation' => $translation,
'scope' => sanitize_textarea_field($_POST['scope'] ?? self::defaults()['scope']),
'admin_scope' => sanitize_textarea_field($_POST['admin_scope'] ?? self::defaults()['admin_scope']),
'theme' => $theme,
'underline' => !empty($_POST['underline']) ? '1' : '0',
'show_translation' => !empty($_POST['show_translation']) ? '1' : '0',
'show_tooltips' => !empty($_POST['show_tooltips']) ? '1' : '0',
'case_insensitive' => !empty($_POST['case_insensitive']) ? '1' : '0',
'tag_chapters' => !empty($_POST['tag_chapters']) ? '1' : '0',
'scan_comments' => !empty($_POST['scan_comments']) ? '1' : '0',
'skip_tags' => $this->normalize_skip_tags($_POST['skip_tags'] ?? []),
'max_range' => (string)max(1, min(50, absint($_POST['max_range'] ?? 12))),
];
update_option(self::OPTION_KEY, $settings, false);
$this->redirect('Settings saved.');
}
public function handle_clear() {
$this->require_admin();
global $wpdb;
$wpdb->query("TRUNCATE TABLE " . self::table());
self::log_event('texts_cleared', [], 'Bible verse table cleared.');
$this->redirect('Verse table cleared.');
}
public function handle_import_web() {
$this->require_admin();
$available = $this->available_translations();
$bulk_action = sanitize_key($_POST['bulk_action'] ?? 'install_selected');
$selected = array_map(function($code) {
return strtoupper(preg_replace('/[^A-Z0-9_-]/i', '', sanitize_text_field($code)));
}, (array)($_POST['translations'] ?? []));
if (!$selected && !empty($_POST['translation'])) {
$selected[] = strtoupper(preg_replace('/[^A-Z0-9_-]/i', '', sanitize_text_field($_POST['translation'])));
}
$selected = array_values(array_filter(array_unique($selected), function($code) use ($available) {
return isset($available[$code]);
}));
if ($bulk_action === 'install_all') $selected = array_keys($available);
if ($bulk_action === 'clear_all') {
global $wpdb;
$wpdb->query("TRUNCATE TABLE " . self::table());
self::log_event('texts_removed_all', [], 'All installed Bible texts removed.');
$this->redirect('All installed Bible texts removed.');
}
if (!$selected) $this->redirect('No Bible translations selected.');
if ($bulk_action === 'remove_selected') {
$removed = $this->remove_translations($selected);
$remaining = $this->installed_translations();
$this->set_active_translation($this->default_translation($this->settings()['translation'], $remaining));
$this->redirect('Removed ' . number_format_i18n($removed) . ' verse rows from selected translation(s).');
}
if ($bulk_action === 'set_default') {
$this->set_active_translation($selected[0]);
$this->redirect($selected[0] . ' is now the default tooltip translation.');
}
$messages = [];
foreach ($selected as $translation) $messages[] = $this->import_vpl_translation($translation, false);
$this->set_active_translation($selected[0]);
$this->redirect(implode(' ', $messages));
}
private function remove_translations($translations) {
global $wpdb;
$count = 0;
foreach ((array)$translations as $translation) {
$count += (int)$wpdb->delete(self::table(), ['translation' => strtoupper((string)$translation)], ['%s']);
}
self::log_event('texts_removed', ['translations' => array_values((array)$translations), 'rows' => $count], 'Removed Bible text translations.');
return $count;
}
private function require_admin() {
if (!current_user_can('manage_options')) wp_die('Insufficient permissions.');
check_admin_referer(self::NONCE);
}
private function redirect($msg) {
wp_safe_redirect(add_query_arg('msg', rawurlencode($msg), admin_url('admin.php?page=' . self::SLUG)));
exit;
}
private function set_active_translation($translation) {
$settings = $this->settings();
$settings['translation'] = $translation;
update_option(self::OPTION_KEY, $settings, false);
}
private function import_vpl_translation($translation, $make_default = true) {
$translations = $this->available_translations();
if (empty($translations[$translation])) return 'Unknown translation requested.';
$info = $translations[$translation];
if (!class_exists('ZipArchive')) return 'ZipArchive is not available on this server.';
require_once ABSPATH . 'wp-admin/includes/file.php';
$tmp = download_url($info['url'], 120);
if (is_wp_error($tmp)) return 'Download failed: ' . $tmp->get_error_message();
$dir = wp_tempnam('brt-vpl');
if (file_exists($dir)) @unlink($dir);
wp_mkdir_p($dir);
$zip = new ZipArchive();
if ($zip->open($tmp) !== true) {
@unlink($tmp);
$this->delete_temp_dir($dir);
return 'Could not open downloaded ' . $translation . ' archive.';
}
$zip->extractTo($dir);
$zip->close();
@unlink($tmp);
$file = trailingslashit($dir) . $info['file'];
if (!file_exists($file)) {
$this->delete_temp_dir($dir);
return $translation . ' VPL file was not found in archive.';
}
$handle = fopen($file, 'r');
if (!$handle) {
$this->delete_temp_dir($dir);
return 'Could not read ' . $translation . ' VPL file.';
}
global $wpdb;
$wpdb->delete(self::table(), ['translation' => $translation], ['%s']);
$batch = [];
$count = 0;
while (($line = fgets($handle)) !== false) {
$parsed = $this->parse_vpl_line($line);
if (!$parsed) continue;
$batch[] = [$translation, $parsed['book']['abbr'], $parsed['book']['name'], $parsed['chapter'], $parsed['verse'], $parsed['text']];
if (count($batch) >= 400) {
$count += $this->insert_rows($batch, $info['source'], $info['license']);
$batch = [];
}
}
fclose($handle);
if ($batch) $count += $this->insert_rows($batch, $info['source'], $info['license']);
$this->delete_temp_dir($dir);
if ($make_default) $this->set_active_translation($translation);
self::log_event('text_imported', ['translation' => $translation, 'verses' => $count], 'Imported Bible text.');
return $translation . ' import complete: ' . number_format_i18n($count) . ' verses installed.';
}
private function import_vpl_book($translation, $target_abbr) {
$translations = $this->available_translations();
if (empty($translations[$translation])) return 0;
$info = $translations[$translation];
if (!class_exists('ZipArchive')) return 0;
require_once ABSPATH . 'wp-admin/includes/file.php';
$tmp = download_url($info['url'], 120);
if (is_wp_error($tmp)) return 0;
$dir = wp_tempnam('brt-vpl-book');
if (file_exists($dir)) @unlink($dir);
wp_mkdir_p($dir);
$zip = new ZipArchive();
if ($zip->open($tmp) !== true) {
@unlink($tmp);
return 0;
}
$zip->extractTo($dir);
$zip->close();
@unlink($tmp);
$file = trailingslashit($dir) . $info['file'];
if (!file_exists($file)) {
$this->delete_temp_dir($dir);
return 0;
}
$handle = fopen($file, 'r');
if (!$handle) {
$this->delete_temp_dir($dir);
return 0;
}
$batch = [];
$count = 0;
while (($line = fgets($handle)) !== false) {
$parsed = $this->parse_vpl_line($line);
if (!$parsed || strtoupper($parsed['book']['abbr']) !== strtoupper($target_abbr)) continue;
$batch[] = [$translation, $parsed['book']['abbr'], $parsed['book']['name'], $parsed['chapter'], $parsed['verse'], $parsed['text']];
if (count($batch) >= 200) {
$count += $this->insert_rows($batch, $info['source'], $info['license']);
$batch = [];
}
}
fclose($handle);
if ($batch) $count += $this->insert_rows($batch, $info['source'], $info['license']);
$this->delete_temp_dir($dir);
return $count;
}
private function delete_temp_dir($dir) {
if (!is_dir($dir)) return;
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($it as $file) {
$file->isDir() ? @rmdir($file->getRealPath()) : @unlink($file->getRealPath());
}
@rmdir($dir);
}
private function parse_vpl_line($line) {
$line = trim((string)$line);
if ($line === '') return null;
if (!preg_match('/^((?:[1-3]\s*)?[A-Za-z][A-Za-z0-9 .\'-]{1,40}?)\s+(\d{1,3}):(\d{1,3})\s+(.+)$/u', $line, $m)) return null;
$book = $this->normalize_source_book($m[1], 'ebible_vpl');
$text = trim(wp_specialchars_decode($m[4], ENT_QUOTES));
if ($text === '') return null;
return [
'book' => $book,
'chapter' => (int)$m[2],
'verse' => (int)$m[3],
'text' => $text,
];
}
private function insert_rows($rows, $source, $license) {
global $wpdb;
$count = 0;
foreach ($rows as $row) {
$result = $wpdb->replace(self::table(), [
'translation' => $row[0],
'book' => $row[1],
'book_name' => $row[2],
'chapter' => (int)$row[3],
'verse' => (int)$row[4],
'verse_text' => $row[5],
'source' => $source,
'license' => $license,
'created_at' => current_time('mysql'),
], ['%s','%s','%s','%d','%d','%s','%s','%s','%s']);
if ($result !== false) $count++;
}
return $count;
}
private function repair_book_aliases() {
if (get_option('brt_alias_repair_version') === self::VERSION) return;
global $wpdb;
foreach ($this->canonical_book_repairs() as $old => $new) {
$wpdb->query($wpdb->prepare(
"UPDATE IGNORE " . self::table() . " SET book = %s, book_name = %s WHERE book = %s",
$new[0],
$new[1],
$old
));
$wpdb->query($wpdb->prepare(
"UPDATE " . self::table() . " SET book_name = %s WHERE book = %s",
$new[1],
$new[0]
));
}
foreach ($this->canonical_book_name_repairs() as $old_name => $new) {
$wpdb->query($wpdb->prepare(
"UPDATE IGNORE " . self::table() . " SET book = %s, book_name = %s WHERE LOWER(REPLACE(REPLACE(REPLACE(book_name, ' ', ''), '.', ''), '-', '')) = %s",
$new[0],
$new[1],
$old_name
));
}
update_option('brt_alias_repair_version', self::VERSION, false);
}
private function canonical_book_repairs() {
$repairs = [];
foreach ($this->book_registry() as $book) {
foreach (array_merge($book['aliases'], $book['source_aliases']['ebible_vpl']) as $alias) {
$key = strtoupper(preg_replace('/[^A-Z0-9]/i', '', (string)$alias));
if ($key && $key !== $book['abbr']) $repairs[$key] = [$book['abbr'], $book['name']];
}
}
return $repairs;
}
private function canonical_book_name_repairs() {
$repairs = [];
foreach ($this->book_registry() as $book) {
foreach (array_merge([$book['name']], $book['aliases'], $book['source_aliases']['ebible_vpl']) as $alias) {
$key = $this->alias_key($alias);
if ($key) $repairs[$key] = [$book['abbr'], $book['name']];
}
}
return $repairs;
}
private function repair_missing_james_verses() {
if (get_option('brt_james_backfill_version') === self::VERSION) return;
global $wpdb;
$installed = $wpdb->get_col("SELECT DISTINCT translation FROM " . self::table() . " ORDER BY translation ASC");
$available = $this->available_translations();
$repaired = [];
foreach ((array)$installed as $translation) {
$translation = strtoupper((string)$translation);
if (empty($available[$translation])) continue;
$count = (int)$wpdb->get_var($wpdb->prepare(
"SELECT COUNT(*) FROM " . self::table() . " WHERE translation = %s AND (book IN ('JAS','JAM','JMS','JM','JA','JAC') OR book_name IN ('James','JAS','JAM','Jms','JMS','Jacob'))",
$translation
));
if ($count > 0) continue;
$inserted = $this->import_vpl_book($translation, 'JAS');
if ($inserted > 0) $repaired[$translation] = $inserted;
}
update_option('brt_james_backfill_version', self::VERSION, false);
if ($repaired) {
self::log_event('james_backfilled', ['translations' => $repaired], 'Backfilled missing James verses for installed Bible translations.');
}
}
private function book_name_from_abbr($abbr) {
$abbr = strtoupper(preg_replace('/[^A-Z0-9]/i', '', (string)$abbr));
foreach ($this->book_map() as $book) {
if ($book['abbr'] === $abbr) return $book['name'];
}
return $abbr;
}
private function admin_css() {
return '.brt-admin{max-width:1500px}.brt-hero{position:relative;overflow:hidden;margin:12px 0 20px;border-left:7px solid #d8a83d;border-radius:8px;background:#10141f;background-image:linear-gradient(105deg,rgba(8,11,18,.96) 0%,rgba(18,25,39,.88) 52%,rgba(31,41,55,.36) 100%),url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 1200 420%27%3E%3Cdefs%3E%3ClinearGradient id=%27g%27 x1=%270%27 y1=%270%27 x2=%271%27 y2=%271%27%3E%3Cstop stop-color=%27%23f7d67a%27/%3E%3Cstop offset=%27.55%27 stop-color=%27%238bbbd9%27/%3E%3Cstop offset=%271%27 stop-color=%27%231c2b45%27/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width=%271200%27 height=%27420%27 fill=%27%230d1422%27/%3E%3Ccircle cx=%27925%27 cy=%27112%27 r=%27102%27 fill=%27%23f4c957%27 opacity=%27.9%27/%3E%3Cpath d=%27M0 295 C190 235 310 270 470 215 C650 152 785 188 1200 116 L1200 420 L0 420Z%27 fill=%27url(%23g)%27 opacity=%27.72%27/%3E%3Cpath d=%27M650 300 C760 245 872 245 995 302 L995 343 C876 301 760 301 650 343Z%27 fill=%27%23f8fafc%27 opacity=%27.88%27/%3E%3Cpath d=%27M995 302 C1074 262 1145 263 1200 292 L1200 334 C1138 309 1068 310 995 343Z%27 fill=%27%23e2e8f0%27 opacity=%27.82%27/%3E%3Cpath d=%27M648 305 L997 305%27 stroke=%27%2394a3b8%27 stroke-width=%276%27 opacity=%27.65%27/%3E%3Cpath d=%27M727 318 C790 298 852 298 930 318%27 stroke=%27%23a16207%27 stroke-width=%274%27 fill=%27none%27 opacity=%27.55%27/%3E%3C/svg%3E");background-size:cover;background-position:center right;box-shadow:0 18px 42px rgba(15,23,42,.18)}.brt-hero-content{max-width:780px;padding:34px 38px 38px;color:#fff}.brt-kicker{color:#f6d78b;font-size:12px;font-weight:800;letter-spacing:0;text-transform:uppercase}.brt-hero h1{margin:8px 0 12px;color:#fff;font-size:34px;line-height:1.1;font-weight:900}.brt-lede{max-width:740px;margin:0;font-size:15px;line-height:1.65;color:#dbe7f5}.brt-hero-chips{display:flex;gap:8px;flex-wrap:wrap;margin-top:18px}.brt-hero-chips span{display:inline-flex;align-items:center;border:1px solid rgba(255,255,255,.28);border-radius:999px;padding:6px 10px;background:rgba(255,255,255,.1);color:#fff;font-size:12px;font-weight:800}.brt-grid{display:grid;grid-template-columns:1fr 1fr;gap:18px}.brt-card{background:#f8fafc;border:1px solid #cbd5e1;border-radius:8px;padding:20px;box-shadow:0 12px 28px rgba(15,23,42,.08)}.brt-card h2{margin-top:0}.brt-wide{grid-column:1/-1}.brt-actions{display:flex;gap:10px;flex-wrap:wrap;margin-top:16px}.brt-card label{display:block;margin:0 0 12px;font-weight:700}.brt-card input:not([type=checkbox]),.brt-card textarea,.brt-card select{width:100%;max-width:100%;border-radius:6px;min-height:38px}.brt-card label span,.brt-table span{display:block;margin-top:5px;color:#64748b;font-size:12px;font-weight:500}.brt-current{background:#e8eef8;border:1px solid #cbd5e1;border-radius:6px;margin:0 0 14px;padding:10px 12px}.brt-check{display:flex!important;gap:8px;align-items:center}.brt-row{display:grid;grid-template-columns:1fr 220px;gap:12px}.brt-skip-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 14px;margin:8px 0 16px}.brt-bulkbar{display:flex;gap:10px;align-items:center;margin:14px 0}.brt-bulkbar select{max-width:250px}.brt-table td,.brt-table th{vertical-align:middle}.brt-muted{color:#94a3b8!important}.brt-pill{display:inline-flex!important;margin:0!important;padding:4px 8px;border-radius:999px;background:#dbeafe;color:#1d4ed8!important;font-weight:800!important;font-size:11px!important}.brt-library .description{margin-top:10px}.brt-footer{display:flex;flex-wrap:wrap;gap:8px 14px;align-items:center;margin:20px 0 0;padding:14px 16px;border-left:5px solid #d8a83d;border-radius:8px;background:#111827;color:#e5edf7;font-size:13px}.brt-footer strong{color:#fff}.brt-footer span{font-weight:800;color:#f6d78b}.brt-footer em{color:#cbd5e1}@media(max-width:900px){.brt-hero-content{padding:28px 24px}.brt-hero h1{font-size:28px}.brt-grid,.brt-row,.brt-skip-grid{grid-template-columns:1fr}.brt-bulkbar{align-items:stretch;flex-direction:column}.brt-bulkbar select{max-width:none}}';
}
private function frontend_css() {
return '.brt-ref{cursor:help;text-decoration:underline;text-decoration-style:dotted;text-underline-offset:3px;color:inherit;font-weight:700}.brt-ref:focus{outline:2px solid rgba(47,128,237,.45);outline-offset:2px}.brt-ref.no-underline{text-decoration:none}.brt-pop{box-sizing:border-box;position:fixed;z-index:999999;width:max-content;max-width:min(560px,calc(100vw - 28px));min-width:min(320px,calc(100vw - 28px));padding:16px;border-radius:12px;border:1px solid rgba(148,163,184,.45);background:#fff;color:#0f172a;box-shadow:0 20px 50px rgba(15,23,42,.18);font:14px/1.55 system-ui,-apple-system,Segoe UI,sans-serif;pointer-events:auto;opacity:0;transform:translateY(5px);transition:opacity .22s ease,transform .22s ease}.brt-pop *{box-sizing:border-box}.brt-pop.ready{opacity:1;transform:translateY(0)}.brt-pop.dark{background:#080b10;color:#eef4ff;box-shadow:0 20px 60px rgba(0,0,0,.42)}.brt-pop.light{background:#fff;color:#0f172a;box-shadow:0 20px 50px rgba(15,23,42,.18)}.brt-head{display:flex;align-items:flex-start;justify-content:space-between;gap:10px;margin:0 0 12px}.brt-title{display:block;min-width:0;flex:1 1 auto;font-weight:800;font-size:15px;line-height:1.3;color:inherit;white-space:normal;overflow-wrap:anywhere}.brt-label{font-weight:700;color:#475569}.brt-pop.dark .brt-label{color:#a8b7cc}.brt-tabs{display:flex;flex:0 0 auto;max-width:210px;gap:6px;flex-wrap:wrap;justify-content:flex-end}.brt-tab{border:1px solid rgba(148,163,184,.45);border-radius:999px;background:rgba(148,163,184,.12);color:inherit;cursor:pointer;font:700 11px/1 system-ui,-apple-system,Segoe UI,sans-serif;padding:5px 8px}.brt-tab.active{background:#2f80ed;border-color:#2f80ed;color:#fff}.brt-pop.dark .brt-tab.active{background:#60a5fa;border-color:#60a5fa;color:#06101f}.brt-body{clear:both;display:block;min-height:1.55em}.brt-verse{display:block;margin:0 0 9px;color:inherit}.brt-verse:last-child{margin-bottom:0}.brt-verse-num{font-weight:900;margin-right:5px}.brt-foot{display:block;margin-top:11px;color:#64748b;font-size:12px}.brt-pop.dark .brt-foot{color:#93a4bb}.brt-pop .err{color:#b91c1c}.brt-pop.dark .err{color:#fca5a5}.brt-loading{display:flex;align-items:center;gap:10px;margin:3px 0 1px;color:#64748b}.brt-pop.dark .brt-loading{color:#93a4bb}.brt-spinner{width:14px;height:14px;border:2px solid rgba(148,163,184,.35);border-top-color:#2f80ed;border-radius:999px;animation:brtSpin .8s linear infinite}@keyframes brtSpin{to{transform:rotate(360deg)}}@media(max-width:520px){.brt-head{flex-direction:column}.brt-tabs{justify-content:flex-start;max-width:none}.brt-pop{min-width:min(280px,calc(100vw - 28px))}}';
}
private function frontend_js() {
return <<<'JS'
(function(){
if (!window.BibleReferenceTooltips || !BibleReferenceTooltips.rest) return;
const bookAliases = Array.isArray(BibleReferenceTooltips.bookAliases) ? BibleReferenceTooltips.bookAliases : [];
const book = '(?:' + bookAliases.sort((a,b) => b.length - a.length).join('|') + ')';
const chapterPattern = BibleReferenceTooltips.tagChapters ? '(?:\\s*[:.]\\s*\\d{1,3}(?:\\s*[-\\u2013\\u2014]\\s*\\d{1,3})?)?' : '\\s*[:.]\\s*\\d{1,3}(?:\\s*[-\\u2013\\u2014]\\s*\\d{1,3})?';
const refPattern = '\\b(' + book + ')[\\s.]*\\d{1,3}' + chapterPattern + '\\b';
const refFlags = BibleReferenceTooltips.caseSensitive ? 'g' : 'gi';
const refRe = new RegExp(refPattern, refFlags);
const refTestRe = new RegExp(refPattern, BibleReferenceTooltips.caseSensitive ? '' : 'i');
const configuredSkip = Array.isArray(BibleReferenceTooltips.skipTags) ? BibleReferenceTooltips.skipTags : [];
const skip = new Set(['A','SCRIPT','STYLE','TEXTAREA','INPUT','SELECT','BUTTON','CODE','PRE','NOSCRIPT','IFRAME','OBJECT','EMBED','SVG','MATH'].concat(configuredSkip.map(tag => String(tag || '').toUpperCase())));
const preferenceKey = 'brtTranslation';
const cache = new Map();
let pop = null;
let activeRef = '';
let activeTrigger = null;
let hideTimer = null;
let loadingTimer = null;
let requestToken = 0;
function getStoredPreference(){
try { return window.localStorage ? (localStorage.getItem(preferenceKey) || '') : ''; }
catch(e) { return ''; }
}
function setStoredPreference(code){
try { if (window.localStorage) localStorage.setItem(preferenceKey, code); }
catch(e) {}
}
function preferredTranslation(){
const available = Array.isArray(BibleReferenceTooltips.translations) ? BibleReferenceTooltips.translations.map(row => String(row.code || '').toUpperCase()).filter(Boolean) : [];
const stored = String(getStoredPreference()).toUpperCase();
if (stored && (!available.length || available.includes(stored))) return stored;
return String(BibleReferenceTooltips.translation || 'WEB').toUpperCase();
}
function rememberTranslation(code){
code = String(code || '').toUpperCase();
if (!code) return;
setStoredPreference(code);
}
function scan(root){
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
acceptNode(node){
if (!node.nodeValue || !refTestRe.test(node.nodeValue)) return NodeFilter.FILTER_REJECT;
refRe.lastIndex = 0;
let el = node.parentElement;
while (el) {
if (skip.has(el.tagName) || el.classList.contains('brt-ref') || el.classList.contains('brt-pop')) return NodeFilter.FILTER_REJECT;
el = el.parentElement;
}
return NodeFilter.FILTER_ACCEPT;
}
});
const nodes = [];
while (walker.nextNode()) nodes.push(walker.currentNode);
nodes.forEach(wrapNode);
}
function wrapNode(node){
const text = node.nodeValue;
const frag = document.createDocumentFragment();
let last = 0;
refRe.lastIndex = 0;
text.replace(refRe, function(match){
const offset = arguments[arguments.length - 2];
if (offset > last) frag.appendChild(document.createTextNode(text.slice(last, offset)));
const ref = makeReferenceNode(match);
frag.appendChild(ref);
last = offset + match.length;
});
if (last < text.length) frag.appendChild(document.createTextNode(text.slice(last)));
node.parentNode.replaceChild(frag, node);
}
function makeReferenceNode(ref){
const el = document.createElement('span');
el.className = 'brt-ref';
if (!BibleReferenceTooltips.underline) el.className += ' no-underline';
el.dataset.ref = ref;
el.textContent = ref;
el.tabIndex = 0;
return el;
}
async function show(e){
if (!BibleReferenceTooltips.showTooltips) return;
const target = e.target.closest('.brt-ref');
if (!target) return;
window.clearTimeout(hideTimer);
window.clearTimeout(loadingTimer);
const token = ++requestToken;
activeRef = target.dataset.ref;
activeTrigger = target;
loadingTimer = window.setTimeout(() => {
if (token !== requestToken || activeTrigger !== target) return;
ensurePop();
pop.className = 'brt-pop ' + resolvedTheme();
pop.innerHTML = '