diff --git a/assets/popup.html b/assets/popup.html index 196e118..60057a5 100644 --- a/assets/popup.html +++ b/assets/popup.html @@ -163,7 +163,7 @@ -
Version 1.6.7
+
Version 1.6.8
diff --git a/manifest.json b/manifest.json index 197eaf0..b6bd80e 100644 --- a/manifest.json +++ b/manifest.json @@ -32,7 +32,7 @@ ] } ], - "description": "Search for text in on a webpage and replace it with different text.", + "description": "Search for text on a webpage and replace it with different text.", "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCr3R0tWRUKUERxg/cghorcvKPDxba+0Ko/3Metk/0XsUTPZcU1xBQZCY441i3lK2ZkH/Td3rs/l8HvbVnkN37NiFm0QQOIJGJi7vp1GdQsrr5uZA/611TsQAWpxxHzR9N4km5wu8e/Xmw2ZG5WKfWVPtUhozEDHTk5CVgeTUOMAQIDAQAB", "manifest_version": 3, "name": "Search and Replace", @@ -46,6 +46,6 @@ "https://*/*" ], "update_url": "http://clients2.google.com/service/update2/crx", - "version": "1.6.7", + "version": "1.6.8", "options_page": "assets/options.html" } diff --git a/package.json b/package.json index 29668a0..e0bc46a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "search_and_replace", - "version": "1.6.7", + "version": "1.6.8", "resolutions": { "author": "Chris Taylor " }, diff --git a/src/popup.ts b/src/popup.ts index 1c33b85..a458899 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -51,6 +51,8 @@ window.addEventListener('DOMContentLoaded', function () { if (recentSearch) { restoreSearchReplaceInstance(recentSearch) } + // Trigger a search term count if there is an existing search term + tabQuery('store', recentSearch, history, tabQueryCallback).then((r) => console.log(r)) }) ;(document.querySelector('#historyHeader')).addEventListener('click', historyHeaderClickHandler) diff --git a/src/searchreplace.ts b/src/searchreplace.ts index 30d8730..d70b32e 100644 --- a/src/searchreplace.ts +++ b/src/searchreplace.ts @@ -331,8 +331,12 @@ async function cmsEditor( } else { const editor = document.querySelector(richTextEditor.editor.value) const initialText = editor.textContent || '' + console.log('initial Text', initialText) + console.log('inner Text', editor.innerText) + console.log('inner HTML', editor.innerHTML) const newText = initialText.replace(searchPattern, replaceTerm) - await replaceInContentEditableElement(window, editor, newText) + console.log('newText', newText) + await replaceInContentEditableElement(window, editor, initialText, newText) replaced = initialText !== newText } } catch (err) { @@ -347,55 +351,24 @@ async function cmsEditor( async function replaceInContentEditableElement( window: Window, element: HTMLElement, + initialText: string, replacementText: string ): Promise { return new Promise((resolve) => { - const dataTransfer = new DataTransfer() - - // this may be 'text/html' if it's required - dataTransfer.setData('text/plain', `${replacementText}`) - // select the content editable area element.dispatchEvent(new FocusEvent('focus', { bubbles: true })) + console.log('element.textContent', element.textContent) + if (element.innerText === element.innerHTML) { + console.log('set textContent in element', element) + element.textContent = replacementText + } else { + console.log('replacing', initialText, 'in', element.innerHTML, 'with', replacementText) + element.innerHTML = element.innerHTML.replace(initialText, replacementText) + } - // select all the text - selectElementContents(window, element) - - // delete any text in the content editable area - element.dispatchEvent( - new KeyboardEvent('keydown', { - bubbles: true, - cancelable: true, - keyCode: 46, - shiftKey: true, - }) - ) - - // wait a short time for the delete to happen - setTimeout(() => { - // paste the replacement text - element.dispatchEvent( - new ClipboardEvent('paste', { - clipboardData: dataTransfer, - - // need these for the event to reach Draft paste handler - bubbles: true, - cancelable: true, - }) - ) - - // clear DataTransfer Data - dataTransfer.clearData() + element.dispatchEvent(new Event('input', { bubbles: true })) - if (element.textContent !== replacementText) { - console.log('set textContent') - element.textContent = replacementText - } else { - console.log("didn't need to set textContent ") - element.dispatchEvent(new Event('input', { bubbles: true })) - } - resolve(true) - }, 100) + resolve(element.innerText !== initialText) }) } diff --git a/tests/test.html b/tests/test.html index 7b742dc..3830b56 100644 --- a/tests/test.html +++ b/tests/test.html @@ -5,33 +5,34 @@
+

Tests

-

Input Field

+

Input Field

-

Text Area

+

Text Area

-

Text Area with HTML

+

Text Area with HTML

-

Editable div with [role="textbox"]

+

Editable div with [role="textbox"]

This is a test!!!
-

Hidden input

+

Hidden input

-

Plain old div

+

Plain old div

This is a test!!!