import test from 'node:test'; import assert from 'node:assert/strict'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); const cc = require('../currency-converter.user.js'); // Fixed deterministic rates for unit tests cc.setRatesForTest({ USD: 1, CNY: 7.2, EUR: 0.9, GBP: 0.8, JPY: 150, HKD: 7.8, KRW: 1350, TWD: 32, AUD: 1.5, CAD: 1.4, SGD: 1.35, CHF: 0.9, BRL: 5, INR: 80, THB: 35, RUB: 90, TRY: 30, VND: 25000, MYR: 4.5, IDR: 16000, PHP: 58, MXN: 20, NZD: 1.6, PLN: 4, SEK: 10, NOK: 11, DKK: 7, AED: 3.6, SAR: 3.75, MOP: 8 }); // -------------------- Minimal DOM Mock for Non-Destructive Rendering Tests -------------------- function createMockDocument() { class MockClassList { constructor(el) { this.el = el; this.set = new Set(); } _syncFromAttr(val) { this.set = new Set(String(val || '').split(/\s+/).filter(Boolean)); } _syncToAttr() { this.el._className = Array.from(this.set).join(' '); } add(...cls) { cls.forEach((c) => this.set.add(c)); this._syncToAttr(); } remove(...cls) { cls.forEach((c) => this.set.delete(c)); this._syncToAttr(); } contains(c) { return this.set.has(c); } } class MockNode { constructor(nodeType) { this.nodeType = nodeType; this.parentNode = null; this.childNodes = []; } get parentElement() { return this.parentNode && this.parentNode.nodeType === 1 ? this.parentNode : null; } get isConnected() { let cur = this; while (cur) { if (cur === doc.body || cur === doc.documentElement) return true; cur = cur.parentNode; } return false; } get nextSibling() { if (!this.parentNode) return null; const idx = this.parentNode.childNodes.indexOf(this); return idx >= 0 && idx + 1 < this.parentNode.childNodes.length ? this.parentNode.childNodes[idx + 1] : null; } } class MockText extends MockNode { constructor(val) { super(3); this.nodeValue = String(val); } get textContent() { return this.nodeValue; } set textContent(v) { this.nodeValue = String(v); } } class MockElement extends MockNode { constructor(tagName) { super(1); this.tagName = tagName.toUpperCase(); this.attrs = new Map(); this.classList = new MockClassList(this); this._className = ''; this.hidden = false; this.isContentEditable = false; this.title = ''; } get className() { return this._className; } set className(val) { this._className = String(val || ''); this.classList._syncFromAttr(this._className); } get children() { return this.childNodes.filter((n) => n.nodeType === 1); } setAttribute(k, v) { this.attrs.set(k, String(v)); } getAttribute(k) { return this.attrs.has(k) ? this.attrs.get(k) : null; } appendChild(node) { if (node.nodeType === 11) { for (const c of [...node.childNodes]) { this.appendChild(c); } return node; } if (node.parentNode) { node.parentNode.removeChild(node); } node.parentNode = this; this.childNodes.push(node); return node; } insertBefore(newNode, refNode) { if (!refNode) return this.appendChild(newNode); if (newNode.nodeType === 11) { for (const c of [...newNode.childNodes]) { this.insertBefore(c, refNode); } return newNode; } if (newNode.parentNode) { newNode.parentNode.removeChild(newNode); } const idx = this.childNodes.indexOf(refNode); if (idx === -1) return this.appendChild(newNode); newNode.parentNode = this; this.childNodes.splice(idx, 0, newNode); return newNode; } removeChild(node) { const idx = this.childNodes.indexOf(node); if (idx >= 0) { this.childNodes.splice(idx, 1); node.parentNode = null; } return node; } replaceChild(newNode, oldNode) { const idx = this.childNodes.indexOf(oldNode); if (idx === -1) return oldNode; if (newNode.nodeType === 11) { const items = [...newNode.childNodes]; this.childNodes.splice(idx, 1, ...items); for (const item of items) item.parentNode = this; oldNode.parentNode = null; return oldNode; } if (newNode.parentNode) newNode.parentNode.removeChild(newNode); newNode.parentNode = this; this.childNodes[idx] = newNode; oldNode.parentNode = null; return oldNode; } get textContent() { return this.childNodes.map((n) => n.textContent).join(''); } set textContent(v) { this.childNodes = []; if (v !== '' && v != null) { this.appendChild(new MockText(v)); } } closest(selector) { if (!selector.startsWith('.')) return null; const cls = selector.slice(1); let cur = this; while (cur && cur.nodeType === 1) { if (cur.classList.contains(cls)) return cur; cur = cur.parentElement; } return null; } querySelector(selector) { const classes = selector.split(',').map((s) => s.trim().replace(/^\./, '')); const stack = [...this.children]; while (stack.length > 0) { const cur = stack.shift(); if (classes.some((c) => cur.classList.contains(c))) return cur; stack.unshift(...cur.children); } return null; } } class MockFragment extends MockNode { constructor() { super(11); } appendChild(node) { node.parentNode = this; this.childNodes.push(node); return node; } } const doc = { documentElement: new MockElement('HTML'), body: new MockElement('BODY'), createElement: (tag) => new MockElement(tag), createTextNode: (t) => new MockText(t), createDocumentFragment: () => new MockFragment() }; doc.documentElement.lang = 'en-US'; doc.documentElement.appendChild(doc.body); return doc; } // -------------------- Unit Tests -------------------- test('Prefix & suffix currency matching across 25+ currencies', () => { const cases = [ ['$99.99', 'USD', 99.99], ['US$ 100', 'USD', 100], ['CA$100', 'CAD', 100], ['AU$ 45.50', 'AUD', 45.5], ['HK$88', 'HKD', 88], ['NT$1,200', 'TWD', 1200], ['SG$60', 'SGD', 60], ['NZ$75', 'NZD', 75], ['MX$350', 'MXN', 350], ['R$ 250.00', 'BRL', 250], ['€89.00', 'EUR', 89], ['£79.99', 'GBP', 79.99], ['₩10000', 'KRW', 10000], ['₹1,499', 'INR', 1499], ['฿590', 'THB', 590], ['₽2,500', 'RUB', 2500], ['₺999', 'TRY', 999], ['₫250000', 'VND', 250000], ['₱1,250', 'PHP', 1250], ['RM 49.90', 'MYR', 49.9], ['Rp 150.000', 'IDR', 150000], ['19.99 €', 'EUR', 19.99], ['100 USD', 'USD', 100], ['1,980円', 'JPY', 1980], ['10,000원', 'KRW', 10000], ['120 zł', 'PLN', 120], ['250 kr', 'SEK', 250], ['AED 367', 'AED', 367], ['SAR 100', 'SAR', 100], ['CHF 120', 'CHF', 120] ]; for (const [input, expectedCode, expectedAmount] of cases) { const matches = cc.findAllMatches(input, { yenAsJpy: false, hostname: 'example.com' }); assert.equal(matches.length, 1, `Expected 1 match for "${input}", got ${matches.length}`); assert.equal(matches[0].code, expectedCode, `Wrong code for "${input}"`); assert.ok(Math.abs(matches[0].amount - expectedAmount) < 1e-6, `Wrong amount for "${input}": ${matches[0].amount}`); } }); test('European, Swiss, whitespace, leading-dot, signed, and magnitude formats', () => { const eu1 = cc.findAllMatches('€19,99'); assert.equal(eu1[0].amount, 19.99); const eu2 = cc.findAllMatches('€1.299,99'); assert.equal(eu2[0].amount, 1299.99); const eu3 = cc.findAllMatches('1 299,50 €'); assert.equal(eu3[0].amount, 1299.5); const chf = cc.findAllMatches("CHF 1'250.00"); assert.equal(chf[0].amount, 1250); const dotOnly = cc.findAllMatches('$.99'); assert.equal(dotOnly[0].amount, 0.99); const multiWs = cc.findAllMatches('$\n 25.50'); assert.equal(multiWs[0].amount, 25.5); const neg = cc.findAllMatches('-$20.00'); assert.equal(neg[0].amount, -20); const magK = cc.findAllMatches('$1.5K'); assert.equal(magK[0].amount, 1500); const magM = cc.findAllMatches('€2.3M'); assert.equal(magM[0].amount, 2300000); }); test('Price ranges merge cleanly without dropping second number', () => { const r1 = cc.findAllMatches('$10 - 20'); assert.equal(r1.length, 1); assert.equal(r1[0].isRange, true); assert.equal(r1[0].amount, 10); assert.equal(r1[0].amountEnd, 20); const r2 = cc.findAllMatches('€50~100'); assert.equal(r2.length, 1); assert.equal(r2[0].isRange, true); assert.equal(r2[0].amount, 50); assert.equal(r2[0].amountEnd, 100); // Two separate currency symbols remain two matches const two = cc.findAllMatches('$10 - $20'); assert.equal(two.length, 2); }); test('False-positive boundary protection', () => { assert.equal(cc.findAllMatches('ARS$50').length, 0); assert.equal(cc.findAllMatches('EUR$100').length, 0); assert.equal(cc.findAllMatches('BTC$50000').length, 0); assert.equal(cc.findAllMatches('XUSD100').length, 0); assert.equal(cc.findAllMatches('100USDX').length, 0); assert.equal(cc.findAllMatches('≈¥720.00').length, 0); assert.equal(cc.findAllMatches('$99.99 ≈¥719.93').length, 0); }); test('Nordic kr inference by hostname', () => { assert.equal(cc.findAllMatches('250 kr', { hostname: 'shop.no' })[0].code, 'NOK'); assert.equal(cc.findAllMatches('250 kr', { hostname: 'shop.dk' })[0].code, 'DKK'); assert.equal(cc.findAllMatches('250 kr', { hostname: 'shop.se' })[0].code, 'SEK'); }); test('Yen (¥) smart context detection', () => { assert.equal(cc.detectYenContext({ hostname: 'www.amazon.co.jp', lang: 'ja', textSample: '', yenMode: 'auto' }), true); assert.equal(cc.detectYenContext({ hostname: 'item.taobao.com', lang: 'zh-CN', textSample: '价格 ¥199', yenMode: 'auto' }), false); assert.equal(cc.detectYenContext({ hostname: 'global.example.com', lang: 'en', textSample: '合計 ¥3,500 (税込)', yenMode: 'auto' }), true); assert.equal(cc.detectYenContext({ hostname: 'item.taobao.com', lang: 'zh-CN', textSample: '', yenMode: 'jpy' }), true); assert.equal(cc.detectYenContext({ hostname: 'www.amazon.co.jp', lang: 'ja', textSample: '', yenMode: 'off' }), false); assert.equal(cc.findAllMatches('¥1,980', { yenAsJpy: false }).length, 0); const jpy = cc.findAllMatches('¥1,980', { yenAsJpy: true }); assert.equal(jpy.length, 1); assert.equal(jpy[0].code, 'JPY'); assert.equal(jpy[0].amount, 1980); }); test('formatPrice handles tiny AI prices, normal, 万, 亿, and negative', () => { assert.equal(cc.formatPrice(0.0036, 2), '≈¥0.0036'); assert.equal(cc.formatPrice(72.5, 2), '≈¥72.50'); assert.equal(cc.formatPrice(15200, 2), '≈¥1.52万'); assert.equal(cc.formatPrice(152000, 2), '≈¥15.2万'); assert.equal(cc.formatPrice(250000000, 2), '≈¥2.50亿'); assert.equal(cc.formatPrice(-144, 2), '-≈¥144.00'); }); test('isUrlInList wildcard matching and normalizeApiRates', () => { assert.equal(cc.isUrlInList('www.amazon.co.jp', ['*.amazon.co.jp']), true); assert.equal(cc.isUrlInList('amazon.com', ['amazon.com']), true); assert.equal(cc.isUrlInList('evil-amazon.com', ['amazon.com']), false); const normalized = cc.normalizeApiRates({ usd: 1, cny: 7.24, jpy: 154.2, bad: -1 }); assert.equal(normalized.CNY, 7.24); assert.equal(normalized.JPY, 154.2); assert.equal(normalized.BAD, undefined); }); test('Non-destructive DOM conversion, idempotency, and clean restore', () => { const doc = createMockDocument(); globalThis.document = doc; globalThis.GM_getValue = () => ({ mode: 'append', enabled: true, decimalPlaces: 2, yenMode: 'auto' }); // Case 1: Single price TextNode const span = doc.createElement('span'); const tn = doc.createTextNode('$10.00'); span.appendChild(tn); doc.body.appendChild(span); // Case 2: Split-DOM price container (e.g. Amazon / React) const splitBox = doc.createElement('div'); const s1 = doc.createElement('span'); s1.appendChild(doc.createTextNode('$')); const s2 = doc.createElement('span'); s2.appendChild(doc.createTextNode('29')); const s3 = doc.createElement('sup'); s3.appendChild(doc.createTextNode('.99')); splitBox.appendChild(s1); splitBox.appendChild(s2); splitBox.appendChild(s3); doc.body.appendChild(splitBox); // First scan const count1 = cc.scanRoot(doc.body); assert.equal(count1, 2); // Original TextNode is preserved untouched! assert.equal(tn.nodeValue, '$10.00'); assert.equal(span.childNodes.length, 2); assert.equal(span.childNodes[1].textContent, '≈¥72.00'); // Split container children are preserved untouched, only 1 badge appended! assert.equal(splitBox.children.length, 4); assert.equal(s1.textContent, '$'); assert.equal(s2.textContent, '29'); assert.equal(s3.textContent, '.99'); assert.equal(splitBox.children[3].textContent, '≈¥215.93'); // Second scan must be completely idempotent (0 changes, 0 duplicate badges) const count2 = cc.scanRoot(doc.body); assert.equal(count2, 0); assert.equal(span.childNodes.length, 2); assert.equal(splitBox.children.length, 4); // Restore must clean up all injected badges cc.restoreAllConversions(); assert.equal(span.childNodes.length, 1); assert.equal(span.textContent, '$10.00'); assert.equal(splitBox.children.length, 3); assert.equal(splitBox.textContent, '$29.99'); delete globalThis.document; delete globalThis.GM_getValue; }); test('Translator immunity, trailing-unit non-destructive insert, and anti-thrash circuit breaker', () => { const doc = createMockDocument(); globalThis.document = doc; globalThis.GM_getValue = () => ({ mode: 'append', enabled: true, decimalPlaces: 2, yenMode: 'auto' }); // 1. Short text with trailing unit ("$0.04 /M input tokens") keeps TextNode intact and adds translate="no" const unitSpan = doc.createElement('span'); const unitTn = doc.createTextNode('$0.04 /M input tokens'); unitSpan.appendChild(unitTn); doc.body.appendChild(unitSpan); assert.equal(cc.scanRoot(doc.body), 1); assert.equal(unitSpan.childNodes[0], unitTn); assert.equal(unitTn.nodeValue, '$0.04 /M input tokens'); const badge = unitSpan.childNodes[1]; assert.equal(badge.getAttribute('translate'), 'no'); assert.equal(badge.classList.contains('notranslate'), true); // 2. Anti-thrash circuit breaker: external actor removes badge 3 times -> element is frozen for (let i = 0; i < 3; i++) { unitSpan.removeChild(unitSpan.childNodes[1]); cc.scanRoot(doc.body); } // After 3rd external removal/re-evaluation within window, element is frozen -> no more badge re-inserted assert.equal(unitSpan.childNodes.length, 1); // 3. Split container with > 6 children is ignored const bigRow = doc.createElement('div'); for (let i = 0; i < 7; i++) { const c = doc.createElement('span'); c.appendChild(doc.createTextNode(i === 0 ? '$' : String(i))); bigRow.appendChild(c); } doc.body.appendChild(bigRow); assert.equal(cc.processSplitContainer(bigRow), false); cc.restoreAllConversions(); delete globalThis.document; delete globalThis.GM_getValue; }); test('Compound prefixes (JP¥, GB£, UK£, EU€, KR₩) and CN¥/RMB¥ guard', () => { const jpCases = [ ['JP¥720/月', 720], ['JP¥2,900', 2900], ['JP¥1,500', 1500], ['JPY¥500', 500], ['JP ¥300', 300] ]; for (const [input, expected] of jpCases) { const res = cc.findAllMatches(input, { yenAsJpy: false }); assert.equal(res.length, 1, `Expected 1 match for "${input}"`); assert.equal(res[0].code, 'JPY'); assert.equal(res[0].amount, expected); } assert.equal(cc.findAllMatches('GB£50')[0].code, 'GBP'); assert.equal(cc.findAllMatches('UK£12.50')[0].code, 'GBP'); assert.equal(cc.findAllMatches('EU€99')[0].code, 'EUR'); assert.equal(cc.findAllMatches('KR₩10,000')[0].code, 'KRW'); // CN¥ / RMB¥ must NOT match as JPY even when yenAsJpy is true assert.equal(cc.findAllMatches('CN¥100', { yenAsJpy: true }).length, 0); assert.equal(cc.findAllMatches('RMB¥200', { yenAsJpy: true }).length, 0); }); test('Odometer / digit-reel guard prevents 1e+24亿 astronomical miscalculation', () => { assert.equal(cc.parseLocalizedNumber('10123456789012345678901234567890', 'USD'), null); assert.equal(cc.parseLocalizedNumber('9999999999999999', 'USD'), null); const doc = createMockDocument(); globalThis.document = doc; globalThis.GM_getValue = () => ({ mode: 'append', enabled: true, decimalPlaces: 2, yenMode: 'auto' }); // Case A: Odometer with sr-only accessible price const odoA = doc.createElement('div'); const prefixA = doc.createElement('span'); prefixA.appendChild(doc.createTextNode('US$')); const srOnly = doc.createElement('span'); srOnly.className = 'sr-only'; srOnly.appendChild(doc.createTextNode('100')); const reelWrap = doc.createElement('span'); reelWrap.setAttribute('aria-hidden', 'true'); const r1 = doc.createElement('span'); r1.appendChild(doc.createTextNode('0123456789')); const r2 = doc.createElement('span'); r2.appendChild(doc.createTextNode('0123456789')); reelWrap.appendChild(r1); reelWrap.appendChild(r2); odoA.appendChild(prefixA); odoA.appendChild(srOnly); odoA.appendChild(reelWrap); doc.body.appendChild(odoA); assert.equal(cc.processSplitContainer(odoA), true); assert.equal(odoA.children[odoA.children.length - 1].textContent, '≈¥720.00'); // Case B: Odometer with aria-label on digit wrapper const odoB = doc.createElement('div'); const prefixB = doc.createElement('span'); prefixB.appendChild(doc.createTextNode('US$')); const numWrap = doc.createElement('span'); numWrap.setAttribute('aria-label', '100'); const r3 = doc.createElement('span'); r3.setAttribute('aria-hidden', 'true'); r3.appendChild(doc.createTextNode('01234567890123456789')); numWrap.appendChild(r3); odoB.appendChild(prefixB); odoB.appendChild(numWrap); doc.body.appendChild(odoB); assert.equal(cc.processSplitContainer(odoB), true); assert.equal(odoB.children[odoB.children.length - 1].textContent, '≈¥720.00'); // Case C: Odometer without sr-only or aria-label -> safely skipped const odoC = doc.createElement('div'); const prefixC = doc.createElement('span'); prefixC.appendChild(doc.createTextNode('US$')); const r4 = doc.createElement('span'); r4.appendChild(doc.createTextNode('101234567890123456789')); odoC.appendChild(prefixC); odoC.appendChild(r4); doc.body.appendChild(odoC); assert.equal(cc.processSplitContainer(odoC), false); cc.restoreAllConversions(); delete globalThis.document; delete globalThis.GM_getValue; }); test('Invisible Unicode bidi/format chars, custom elements, and in-place odometer tier switching', () => { // 1. Invisible bidi marks inside JP¥ prices const m1 = cc.findAllMatches('JP\u200E¥720/月', { yenAsJpy: false }); assert.equal(m1.length, 1); assert.equal(m1[0].code, 'JPY'); assert.equal(m1[0].amount, 720); const m2 = cc.findAllMatches('JP¥\u200E2,900', { yenAsJpy: false }); assert.equal(m2.length, 1); assert.equal(m2[0].code, 'JPY'); assert.equal(m2[0].amount, 2900); const doc = createMockDocument(); globalThis.document = doc; globalThis.GM_getValue = () => ({ mode: 'append', enabled: true, decimalPlaces: 2, yenMode: 'auto' }); // 2. Custom Web Component element () const customTag = doc.createElement('price-tag'); const c1 = doc.createElement('span'); c1.appendChild(doc.createTextNode('JP¥')); const c2 = doc.createElement('span'); c2.appendChild(doc.createTextNode('720')); customTag.appendChild(c1); customTag.appendChild(c2); doc.body.appendChild(customTag); assert.equal(cc.scanRoot(doc.body), 1); assert.equal(customTag.children[2].textContent, '≈¥34.56'); // 3. Dynamic odometer tier switching: 100 -> 200 -> 500 -> 100 -> 500 (5 switches in a row) const odo = doc.createElement('div'); const pfx = doc.createElement('span'); pfx.appendChild(doc.createTextNode('US$')); const srOnly = doc.createElement('span'); srOnly.className = 'sr-only'; const srText = doc.createTextNode('100'); srOnly.appendChild(srText); const reel = doc.createElement('span'); reel.setAttribute('aria-hidden', 'true'); reel.appendChild(doc.createTextNode('01234567890123456789')); odo.appendChild(pfx); odo.appendChild(srOnly); odo.appendChild(reel); doc.body.appendChild(odo); assert.equal(cc.processSplitContainer(odo), true); const initialBadge = odo.children[odo.children.length - 1]; assert.equal(initialBadge.textContent, '≈¥720.00'); const transitions = [ ['200', '≈¥1440.00'], ['500', '≈¥3600.00'], ['100', '≈¥720.00'], ['500', '≈¥3600.00'] ]; for (const [val, expectedBadge] of transitions) { srText.nodeValue = val; assert.equal(cc.processSplitContainer(odo), true); // Same badge element updated in-place, never frozen or duplicated assert.equal(odo.children.length, 4); assert.equal(odo.children[odo.children.length - 1], initialBadge); assert.equal(initialBadge.textContent, expectedBadge); } cc.restoreAllConversions(); delete globalThis.document; delete globalThis.GM_getValue; }); test('Google One DOM structure converts every non-zero JP¥ price cleanly', () => { const doc = createMockDocument(); globalThis.document = doc; globalThis.GM_getValue = () => ({ mode: 'append', enabled: true, decimalPlaces: 2, yenMode: 'auto' }); // 1. 原价 JP¥725 const lteuze = doc.createElement('span'); lteuze.className = 'LTeuze'; const iaQerf = doc.createElement('span'); iaQerf.className = 'iaQerf'; iaQerf.appendChild(doc.createTextNode('原价 JP¥725')); const hiddenDup = doc.createElement('span'); hiddenDup.setAttribute('aria-hidden', 'true'); hiddenDup.appendChild(doc.createTextNode('JP¥725')); lteuze.appendChild(iaQerf); lteuze.appendChild(hiddenDup); doc.body.appendChild(lteuze); // 2.
JP¥720
const kef720 = doc.createElement('div'); kef720.className = 'kef9me'; kef720.appendChild(doc.createTextNode('JP¥720')); doc.body.appendChild(kef720); // 3.
(为期 12 个月),之后价格为 JP¥725/月
const kr725 = doc.createElement('div'); kr725.className = 'krEaxf'; kr725.appendChild(doc.createTextNode('(为期 12 个月),之后价格为 JP¥725/月')); doc.body.appendChild(kr725); // 4.
长达 4 年,试用期结束后价格:JP¥2,900/月3
const kr2900 = doc.createElement('div'); kr2900.className = 'krEaxf'; kr2900.appendChild(doc.createTextNode('长达 4 年,试用期结束后价格:JP¥2,900/月')); const sup = doc.createElement('sup'); sup.appendChild(doc.createTextNode('3')); kr2900.appendChild(sup); doc.body.appendChild(kr2900); // 5. JP¥0 should remain untouched (amount === 0) const kef0 = doc.createElement('div'); kef0.className = 'kef9me'; kef0.appendChild(doc.createTextNode('JP¥0')); doc.body.appendChild(kef0); const count = cc.scanRoot(doc.body); assert.equal(count, 5); assert.equal(iaQerf.children[0].textContent, '≈¥34.80'); assert.equal(kef720.children[0].textContent, '≈¥34.56'); assert.equal(kr725.children[0].textContent, '≈¥34.80'); assert.equal(kr2900.children[0].textContent, '≈¥139.20'); assert.equal(kef0.children.length, 0); cc.restoreAllConversions(); delete globalThis.document; delete globalThis.GM_getValue; }); test('Wildcard rule removal, root wildcard derivation, own UI guard, and converted count', () => { assert.deepEqual( cc.removeMatchingRules('www.amazon.com', ['*.amazon.com', 'ebay.com']), ['ebay.com'] ); assert.equal(cc.getRootWildcardDomain('www.amazon.co.jp'), '*.amazon.co.jp'); assert.equal(cc.getRootWildcardDomain('sub.example.com'), '*.example.com'); assert.equal(cc.getRootWildcardDomain('localhost'), 'localhost'); const doc = createMockDocument(); const uiHost = doc.createElement('div'); uiHost.id = 'currency-converter-ui-host'; const pillHost = doc.createElement('div'); pillHost.id = 'currency-converter-pill-host'; const toastHost = doc.createElement('div'); toastHost.id = 'currency-converter-toast-host'; assert.equal(cc.isOwnUIElement(uiHost), true); assert.equal(cc.isOwnUIElement(pillHost), true); assert.equal(cc.isOwnUIElement(toastHost), true); globalThis.document = doc; globalThis.GM_getValue = () => ({ mode: 'append', enabled: true, decimalPlaces: 2, yenMode: 'auto' }); const p1 = doc.createElement('span'); p1.appendChild(doc.createTextNode('$10')); const p2 = doc.createElement('span'); p2.appendChild(doc.createTextNode('€20')); doc.body.appendChild(p1); doc.body.appendChild(p2); assert.equal(cc.scanRoot(doc.body), 2); assert.equal(cc.getConvertedCount(), 2); cc.restoreAllConversions(); assert.equal(cc.getConvertedCount(), 0); delete globalThis.document; delete globalThis.GM_getValue; });