nostr: link replacing.

this commit also includes (unrelated) naïvely hiding the private key and displaying on blur/focus.
This commit is contained in:
fiatjaf
2023-01-05 22:48:53 -03:00
parent 3d0a29a8fc
commit bdcf19ecef
5 changed files with 218 additions and 56 deletions

View File

@@ -46,7 +46,8 @@ window.nostr = {
window.addEventListener('message', message => {
if (
!message.data ||
!message.data.response ||
message.data.response === null ||
message.data.response === undefined ||
message.data.ext !== 'nos2x' ||
!window.nostr._requests[message.data.id]
)
@@ -60,5 +61,23 @@ window.addEventListener('message', message => {
window.nostr._requests[message.data.id].resolve(message.data.response)
}
delete window.nostr._requests[message.data.id];
delete window.nostr._requests[message.data.id]
})
// hack to replace nostr:nprofile.../etc links with something else
let replacing = null
let links = document.querySelectorAll('a[href^="nostr:"]')
for (let i = 0; i < links.length; i++) {
links[i].addEventListener('mouseenter', replaceNostrSchemeLink)
}
async function replaceNostrSchemeLink(e) {
if (replacing === false) return
let response = await window.nostr._call('replaceURL', {url: e.target.href})
if (response === false) {
replacing = false
return
}
e.target.href = response
}