My apologies for the oversight. Due to security reasons, the javascript: URL scheme does not work in Chrome as it does in Firefox. For Chrome, a different approach is needed. Since we can't directly create a link with the javascript: URL scheme in the href attribute, we'll use an anchor tag without an href attribute and instead, use a click event listener to execute the bookmarklet's code.
Here's the updated code that should work in both Chrome and Firefox.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bookmarklet Manager</title>
<style>
.bookmarklet-section {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 10px;
}
button {
cursor: pointer;
}
</style>
</head>
<body>
<div id="bookmarklet-container">
<div class="bookmarklet-section">
<label>Name: <input type="text" class="name"></label><br>
<label>Code: <input type="text" class="code"></label><br>
<label>Description: <input type="text" class="description"></label><br><br>
<button class="delete-section">Delete Section</button>
</div>
</div>
<br>
<button id="add-section">Add Section</button>
<button id="generate-page">Generate Page</button>
<br><br>
<a id="output-link" href="" target="_blank"></a>
<script>
const addSectionButton = document.getElementById('add-section');
const generatePageButton = document.getElementById('generate-page');
const outputLink = document.getElementById('output-link');
const bookmarkletContainer = document.getElementById('bookmarklet-container');
addSectionButton.addEventListener('click', () => {
const newSection = document.createElement('div');
newSection.innerHTML = `
<div class="bookmarklet-section">
<label>Name: <input type="text" class="name"></label><br>
<label>Code: <input type="text" class="code"></label><br>
<label>Description: <input type="text" class="description"></label><br><br>
<button class="delete-section">Delete Section</button>
</div>
`;
bookmarkletContainer.appendChild(newSection);
const deleteBtn = newSection.querySelector('.delete-section');
deleteBtn.addEventListener('click', () => {
deleteBtn.parentElement.remove();
});
});
generatePageButton.addEventListener('click', () => {
const sections = bookmarkletContainer.children;
let linksHTML = '';
for (let i = 0; i < sections.length; i++) {
const name = sections[i].querySelector('.name').value;
const code = encodeURIComponent(sections[i].querySelector('.code').value);
const description = sections[i].querySelector('.description').value;
linksHTML += `<a class="bookmarklet-link">${name}</a> (${description})<br><script>document.querySelector('.bookmarklet-link:last-child').addEventListener('click', function() {eval(decodeURIComponent('${code}'))})</script>`;
}
const pageTitle = '<h1>Bookmarklets</h1>';
const generatedPage = `data:text/html;charset=utf-8, ${pageTitle}${linksHTML}`;
outputLink.setAttribute('href', generatedPage);
outputLink.innerText = "Click here for the generated page";
});
bookmarkletContainer.addEventListener('click', (event) => {
if (event.target.matches('.delete-section')) {
event.target.parentElement.remove();
}
});
</script>
</body>
</html>
This version of the code will insert an event listener to execute the bookmarklet's code when the user clicks on the generated link. This should work in Chrome and other browsers as well.