Skip to content

Commit

Permalink
Merge pull request #23 from forgetso/22-clear-history-button-not-working
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
forgetso authored Jun 8, 2023
2 parents a8a2359 + fba3260 commit e4b016d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"https://*/*"
],
"update_url": "http://clients2.google.com/service/update2/crx",
"version": "1.5.3"
"version": "1.5.4"

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "search_and_replace",
"version": "1.5.3",
"version": "1.5.4",
"resolutions": {
"author": "Chris Taylor <[email protected]>"
},
Expand Down
11 changes: 7 additions & 4 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ chrome.runtime.onConnect.addListener(function (port) {
port.onMessage.addListener(function (msg) {
if (msg['recover'] === true) {
chrome.storage.local.get(['storage'], function (result) {
const storage = result['storage'] as SearchReplaceStorage
const storage = result['storage'] as SearchReplaceStorageItems
port.postMessage(storage)
})
} else if (msg['clearHistory'] === true) {
chrome.storage.local.get(['storage'], function (result) {
const storage = result['storage'] as SearchReplaceStorage
storage.storage.history = []
chrome.storage.local.set(storage, function () {
const storage = result['storage'] as SearchReplaceStorageItems
storage.history = []
const searchReplaceStorage: SearchReplaceStorage = {
storage,
}
chrome.storage.local.set(searchReplaceStorage, function () {
port.postMessage('History cleared')
})
})
Expand Down
41 changes: 21 additions & 20 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ document.addEventListener('DOMContentLoaded', function () {
const history: SearchReplaceInstance[] = msg.history || []
let recentSearch: SearchReplaceInstance = msg.instance
if (history.length > 0) {
recentSearch = recentSearch || history[0]
recentSearch = history[0] || []
restoreSearchReplaceInstance(recentSearch)
createHistoryListItemElements(history)
}
Expand Down Expand Up @@ -76,7 +76,6 @@ document.addEventListener('DOMContentLoaded', function () {
function historyHeaderClickHandler(e) {
const historyContent = document.getElementById('historyContent')
if (historyContent) {
console.log(historyContent.style.display)
if (historyContent.style.display === 'block') {
historyContent.style.display = 'none'
} else {
Expand Down Expand Up @@ -182,6 +181,7 @@ function removeLoader() {
}

function storeTerms(e) {
console.debug('storing terms')
e = e || window.event
if (e.keyCode === 13) {
//if the user presses enter we want to trigger the search replace
Expand All @@ -208,27 +208,29 @@ function sendToStorage(searchReplaceInstance: SearchReplaceInstance, history: Se
}
port.postMessage(storageMessage)
port.onMessage.addListener(function (msg) {
console.log('Message received: ' + msg)
console.debug('Message received: ' + msg)
})
}

function createHistoryListItemElements(history: SearchReplaceInstance[]) {
const historyContent = document.getElementById('historyList')
if (historyContent) {
historyContent.innerHTML = ''

for (const [index, item] of history.entries()) {
const li = document.createElement('li')
li.setAttribute(`data-searchTerm`, item['searchTerm'])
li.setAttribute(`data-replaceTerm`, item['replaceTerm'])
for (const checkbox of CHECKBOXES) {
const checked = checkbox in item.options ? item.options[checkbox] : false
li.setAttribute(`data-${checkbox}`, String(checked))
}
li.setAttribute('class', `historyRow-${index % 2}`)
if (history.length > 0) {
const historyContent = document.getElementById('historyList')
if (historyContent) {
historyContent.innerHTML = ''

for (const [index, item] of history.entries()) {
const li = document.createElement('li')
li.setAttribute(`data-searchTerm`, item['searchTerm'])
li.setAttribute(`data-replaceTerm`, item['replaceTerm'])
for (const checkbox of CHECKBOXES) {
const checked = checkbox in item.options ? item.options[checkbox] : false
li.setAttribute(`data-${checkbox}`, String(checked))
}
li.setAttribute('class', `historyRow-${index % 2}`)

li.innerText = item.searchTerm + ' -> ' + item.replaceTerm
historyContent.appendChild(li)
li.innerText = item.searchTerm + ' -> ' + item.replaceTerm
historyContent.appendChild(li)
}
}
}
}
Expand All @@ -248,9 +250,8 @@ function constructSearchReplaceHistory(searchReplaceInstance?: SearchReplaceInst
historyItems = getUniqueHistoryItems(historyItems)
}
return historyItems
} else if (searchReplaceInstance) {
historyItems = [searchReplaceInstance]
}

return historyItems
}

Expand Down

0 comments on commit e4b016d

Please sign in to comment.