Due to U.S. trade controls law restrictions, your GitHub account has been restricted.
This is the message that’s been recently sent to Iranian developers from GitHub, stating their accounts has been restricted.
So I thought this might be a good time to try writing my first add-on for Firefox. It seemed like a trivial task and I was curious how much it’s going to take my time. Simple tasks must be simple to do.
At first I tried to remove the banner in browser inspector. All I had to do was to set display
property to none
for the element and it was gone.
So, that’s what we want our add-on to do: To simply set a CSS property for an element.
Write the extension
MDN web docs has a page called Your first extension and I followed the steps it said:
At first I created a directory for my add-on.
Then I created manifest.json
file. This file is the skeleton of your extension; What files does it include, a short description, extension version, icons and everything else.
content_scripts
section is the most interesting part: You define in what domains, which scripts must be injected.
I wanted to modify appearance of GitHub, which means all I wanted to do was to add a CSS property. So I modified content_scripts
in manifest.json
to look like this:
"content_scripts": [ { "matches": ["*://*.github.com/*"], "css": ["github-warn.css"], }
And in github-warn.css
I wrote this:
div.position-relative.js-header-wrapper > div.js-notice.flash-warn { display: none }
Run and debug
Now let’s test the add-on. First we must load it into the browser. To do so go to about:debugging
in FireFox and click on “Load Temporary add-on”. By selecting a file in your add-on directory it will be loaded in FireFox.
And now when we go to GitHub we no longer see the banner.
But there’s a problem: It seems it take a little bit of time before we see our CSS effects in browser. When you open the site you can see the banner when page is being loaded and after a few seconds it disappears.
To solve this issue we have to change when the CSS get’s injected. It can be altered by run_at
property in content_scripts
: "run_at" : "document_start"
It worth to take a glance of content_scripts
parameters in here.
Publish
There are two options for add-on publishing:
-
Self publish: You will be given the signed
.xpi
file that you can distribute yourself. -
Publishing on FireFox Add-on’s page (AMO)
In either cases first you have to login to Mozilla Developer Hub and upload your zipped add-on directory. To do so, go to your add-on directory and run:
zip -r github-warn.zip .
Tip: If you’re on macOS, to avoid.DS_Store
and __MACOSX
are not included in zip file. You can delete them by executing this command:
zip -d github-warn.zip __MACOSX/* .DS_Store
After you’ve uploaded the zip file you can choose between self-publishing and publishing on AMO. In case you choose the latter, it might take about a day or two before your extensions be approved and becomes publicly available. Self
You can access the add-on code explained in this post on GitHub.