Skip to content

Commit 6e6da08

Browse files
authored
Prosopo ad and fix history clear (#120)
* fix history not clearing * create ad banner * bump version
1 parent a5df325 commit 6e6da08

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

assets/help.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
</head>
1818

1919
<body>
20-
<div class="container" class="bg-light-subtle">
20+
21+
<div class="container bg-light-subtle">
22+
<div class="text-center alert alert-info mt-2">
23+
<a href="https://prosopo.io/?utm_source=search_and_replace&utm_medium=extension&utm_campaign=help_link&term=need+bot+protection&utm_content=textlink" target="_blank" class="link-body-emphasis">
24+
Ad: Need bot protection? The builders of Search and Replace bring you Procaptcha - free for up to 100k requests per month.
25+
</a>
26+
</div>
2127
<div class="row">
2228
<div class="col-md-3" role="complementary">
2329
<nav class="navbar border-bottom border-bottom-dark">

assets/popup.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@
8787
</head>
8888

8989
<body>
90+
<div class="alert alert-info text-center m-2" id="ad">
91+
<span>Ad:</span>
92+
<a href="https://prosopo.io/?utm_source=search_and_replace&utm_medium=extension&utm_campaign=popup_link&term=need+bot+protection&utm_content=textlink" target="_blank" class="link-body-emphasis bold">
93+
Need bot protection?
94+
</a>
95+
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close" id="ad-close"></button>
96+
</div>
9097
<div id="loader">
9198
<img src="ajax-loader.gif" width="16" height="16" name="loading" alt="searching and replacing..." />
9299
</div>

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"permissions": ["activeTab", "storage", "notifications"],
3232
"host_permissions": ["http://*/*", "https://*/*"],
3333
"update_url": "http://clients2.google.com/service/update2/crx",
34-
"version":"2.0.8",
34+
"version":"2.0.9",
3535
"options_page": "assets/options.html",
3636
"icons": {
3737
"16": "assets/icon-16.png",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "search_and_replace",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"resolutions": {
55
"author": "Chris Taylor <cjtaylor38@gmail.com>"
66
},

src/background/admin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ export async function listenerAdmin(msg: SearchReplaceBackgroundMessage, port: c
6565
return
6666
} else if (msg.action === 'clearHistory') {
6767
// Clearing the history in the popup
68-
storage.history = []
69-
await saveStorage(instance, history, savedInstances)
68+
await saveStorage(instance, [], savedInstances)
7069
} else if (msg.action === 'save' && instance.options.save && url) {
7170
console.log('save message received', msg)
7271
// Saving a SearchReplaceInstance for use on subsequent page loads

src/popup.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ window.addEventListener('DOMContentLoaded', async function () {
6262

6363
// Restore the recent search replace instance and history list from storage
6464
port.onMessage.addListener(function (msg: SearchReplaceStorageItems) {
65+
console.log('received msg', msg)
6566
const history: SearchReplaceInstance[] = msg.history || []
67+
const hideAd: boolean = msg.hintPreferences?.ad || false
6668
let recentSearch: SearchReplaceInstance = msg.instance
6769
if (history.length > 0) {
6870
recentSearch = recentSearch || history[0]
@@ -71,6 +73,13 @@ window.addEventListener('DOMContentLoaded', async function () {
7173
if (recentSearch) {
7274
restoreSearchReplaceInstance(recentSearch)
7375
}
76+
if (hideAd) {
77+
const adElement = document.getElementById('ad')
78+
if (adElement) {
79+
document.body.removeChild(adElement)
80+
}
81+
}
82+
7483
// Trigger a search term count if there is an existing search term
7584
contentScriptCall('count', recentSearch, history).catch((e) => {
7685
console.error(e)
@@ -139,6 +148,18 @@ window.addEventListener('DOMContentLoaded', async function () {
139148
autoGrow(searchTerm)
140149
autoGrow(replaceTerm)
141150
})
151+
152+
// Click handler for closing the ad banner
153+
const adCloseElement = document.getElementById('ad-close')
154+
if (adCloseElement) {
155+
adCloseElement.onclick = function () {
156+
const searchReplaceInput = getInputValues(false)
157+
const history = constructSearchReplaceHistory()
158+
const hintPreferences: HintPreferences = { ['ad']: true }
159+
sendToStorage(searchReplaceInput, history, hintPreferences)
160+
}
161+
}
162+
142163
// Localize HTML elements
143164
localizeElements(langData)
144165
})

0 commit comments

Comments
 (0)