Often websites have content that you don't want to see, such as ads, newsletter popups etc.
If you have access to dev tools, you can always right click on an element, select *Inspect Element*, and then hit Backspace to remove it,
or just type `$0.remove()` in the console.
However, most Web users cannot use the dev tools and thus are stuck with the undesirable content
(AdBlock removes some of it, but what it does is not customizable)
Write a [bookmarklet](https://en.wikipedia.org/wiki/Bookmarklet) that, when invoked, allows you to click on elements to remove them from the page.
It should also insert two buttons at the top of the page that are always visible until the removal process is terminated:
- *Undo*, which re-inserts the last removed element (you don't need to keep a stack of more than 1, though that would be a welcome improvement)
- *End*, which terminates the element removal process and removes the *Undo* and *End* buttons
You should actually remove the elements, not just hide them.
You can use [`element.remove()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/remove) for that.
- Pay attention to visibility of system status / Learnability.
The user should be able to easily answer the question *If I click right here, which element will be removed?*
- Pay attention to efficiency: The user should be able to quickly remove a large number of elements.
- Pay attention to safety: The user should be able to undo the last removed element
- To re-insert an element that has been removed, you need to save its position in the DOM.
One way to do that is to keep track of its parent and previous or next sibling (if any).
- You may find [`document.elementFromPoint()`](https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint) useful.
See also [document.elementsFromPoint()](https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint).
- Minimize side effects when the user is clicking on elements to remove them.
Whenever possible, try to prevent the `click` event from propagating further or triggering default actions.
You cannot fully prevent undesirable side effects, because there is no way to read what `click` event listeners the host page
has assigned to an element, and because not all default actions are cancellable, but try to minimize them.
- When writing CSS to be combined with a host page's CSS, there will always be edge cases where things don’t look as intended.
This is ok, as long as you try to minimize these cases, and test in enough websites.
We're not aiming for perfection when writing code that will be executed on websites we don’t control
(such as code for bookmarklets, browser extensions, or libaries),
just for code that works in a sufficiently large number of websites that it's still useful.
You do not need to try and persist the removed elements across page loads.
**Deliverable:**
An HTML page with your bookmarklet as a link that can be dragged to the bookmarks toolbar.
To facilitate both iterating on code for you, and grading by the graders,
please include your JS in `exercise-5/bookmarklet.js`.
Then, all your actual bookmarklet link needs to do is insert a script element that points to `http://localhost:8000/bookmarklet.js` into the page.
Note that for this to work, you need to have a server running on port 8000 in your `exercise-5` directory.
In your HTML page, also include a list of websites you have tried your bookmarklet on and verified it works (mention what types of elements you removed).
You should test on at least 5 websites.