Creating blockers - Schmiddiii/qute-cookie-block GitHub Wiki
To block the cookies, you probably will need to click some buttons.
To tell this script what button to press, it will need the selector of the button.
You can get the selector by opening the dev-tools in qutebrowser (usually by typing wi
or wIh
).
Now right click on the button you want to be clicked and click Inspect
.
A line will now be highlighted in the dev-tools.
Right-click that line and select Copy > Copy Selector
.
You now have the selector of the button in your clipboard ready to be used in creating the new blocker.
The simple way to create blockers is by using a xml file.
Lets say you want to block the cookies on example.com.
You will need to create the file example.com.xml
in the cookie-blockers
folder with the following content:
<?xml version="1.0" encoding="utf-8"?>
<block>
<click element="<selector>"/>
</block>
Please replace <selector>
with the selector you copied in the previous part.
Sometimes you might need to click many buttons in succession.
To do that you will have to copy the line containing <click element=...\>
as often as you need.
Replace the <selector>
with the selector for the next button to press.
If the website needs to load content after clicking a button, insert a <wait/>
before the next command.
This tag can also have a optional argument time
.
This argument indicates the number of milliseconds to wait and defaults to 500
.
This argument must be a whole natural number.
Don't forget to run make.sh
or copy the cookie-blockers
folder to the qutebrowser user data directory.
This way is only recommended for more complex websites or cookie banners, that are available on many different websites.
This is done by writing some rust code.
To be able to block cookies in this way, create a new rust file in src/blockers
and write a struct
implementing the Blocker
trait defined in src/blocker.rs
. Your new struct will need the functions matches
and block
.
The first function determents if your blocker can be used on the given url with the given html, usually by checking the url to match the url of your website (make sure that this also matches when the urls don't match exactly, for example the given url might have a different path).
The second function will be called when your blocker can block the given website and describes the steps to block cookies.
This function will have to return a Vec<QuteCommand>
, these will be executed in order.
The QuteCommand
s are defined in src/commands.rs
, please look there for more information.
Please also look at src/blockers/fandom.rs
for a example implementation.
To add your new blocker to the list, edit src/blockers/mod.rs
to include your new struct and add a object of your type to the get_blockers
function in src/blocker.rs
.
Don't forget to recompile and move the compiled binary to the userscripts
folder of qutebrowser.
You should now have created a blocker for the website. You should not need to restart qutebrowser, so just try it out.