Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prosopo ad and fix history clear #120

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion assets/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
</head>

<body>
<div class="container" class="bg-light-subtle">

<div class="container bg-light-subtle">
<div class="text-center alert alert-info mt-2">
<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">
Ad: Need bot protection? The builders of Search and Replace bring you Procaptcha - free for up to 100k requests per month.
</a>
</div>
<div class="row">
<div class="col-md-3" role="complementary">
<nav class="navbar border-bottom border-bottom-dark">
Expand Down
7 changes: 7 additions & 0 deletions assets/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@
</head>

<body>
<div class="alert alert-info text-center m-2" id="ad">
<span>Ad:</span>
<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">
Need bot protection?
</a>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close" id="ad-close"></button>
</div>
<div id="loader">
<img src="ajax-loader.gif" width="16" height="16" name="loading" alt="searching and replacing..." />
</div>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"permissions": ["activeTab", "storage", "notifications"],
"host_permissions": ["http://*/*", "https://*/*"],
"update_url": "http://clients2.google.com/service/update2/crx",
"version":"2.0.8",
"version":"2.0.9",
"options_page": "assets/options.html",
"icons": {
"16": "assets/icon-16.png",
Expand Down
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": "2.0.8",
"version": "2.0.9",
"resolutions": {
"author": "Chris Taylor <[email protected]>"
},
Expand Down
3 changes: 1 addition & 2 deletions src/background/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export async function listenerAdmin(msg: SearchReplaceBackgroundMessage, port: c
return
} else if (msg.action === 'clearHistory') {
// Clearing the history in the popup
storage.history = []
await saveStorage(instance, history, savedInstances)
await saveStorage(instance, [], savedInstances)
} else if (msg.action === 'save' && instance.options.save && url) {
console.log('save message received', msg)
// Saving a SearchReplaceInstance for use on subsequent page loads
Expand Down
21 changes: 21 additions & 0 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ window.addEventListener('DOMContentLoaded', async function () {

// Restore the recent search replace instance and history list from storage
port.onMessage.addListener(function (msg: SearchReplaceStorageItems) {
console.log('received msg', msg)
const history: SearchReplaceInstance[] = msg.history || []
const hideAd: boolean = msg.hintPreferences?.ad || false
let recentSearch: SearchReplaceInstance = msg.instance
if (history.length > 0) {
recentSearch = recentSearch || history[0]
Expand All @@ -71,6 +73,13 @@ window.addEventListener('DOMContentLoaded', async function () {
if (recentSearch) {
restoreSearchReplaceInstance(recentSearch)
}
if (hideAd) {
const adElement = document.getElementById('ad')
if (adElement) {
document.body.removeChild(adElement)
}
}

// Trigger a search term count if there is an existing search term
contentScriptCall('count', recentSearch, history).catch((e) => {
console.error(e)
Expand Down Expand Up @@ -139,6 +148,18 @@ window.addEventListener('DOMContentLoaded', async function () {
autoGrow(searchTerm)
autoGrow(replaceTerm)
})

// Click handler for closing the ad banner
const adCloseElement = document.getElementById('ad-close')
if (adCloseElement) {
adCloseElement.onclick = function () {
const searchReplaceInput = getInputValues(false)
const history = constructSearchReplaceHistory()
const hintPreferences: HintPreferences = { ['ad']: true }
sendToStorage(searchReplaceInput, history, hintPreferences)
}
}

// Localize HTML elements
localizeElements(langData)
})
Expand Down
Loading