elektroelch.net – blog

Firefox Addon: Add options menu to addon icon

Especially during development it’s annoying to reach the option page of a Firefox addon:

  1. Hamburger
  2. Addons and Themes
  3. Options

There should be a faster way. At least for your own Add-ons you can quite easily add an “Options” menu item to the browser action:

browser.contextMenus.create({
    title: 'Options',
    contexts: ['browser_action'],
    onclick: () => {
      browser.runtime.openOptionsPage();
    },
  });

Additionally to have to add a new permission to the manifest.json file:

 "permissions": ["contextMenus"],

That was easy!

Set selections in a multiple select element with ES6

If you’re looking on the web for a solution to programmatically set the selections of a multiple select element in JavaScript you most likely find answers using jQuery, an indexed loop and an if condition, or some other complicated stuff. Modern browsers and ES6 gives you a simple solution in (almost) a single line of code:

<select id="selectElement" size="3" multiple>
    <option value="oranges">Oranges</option>
    <option value="apples">Apples</option>
    <option value="cherries">Cherries</option>
</select>
let selectElement = document.getElementById('selectElement');
let a = ['oranges', 'cherries'];
for (option of selectElement.options) option.selected = 
    a.includes(option.value);  

There you go!

(Photo by Anthony Martino on Unsplash)

Big Tech 0wns web development

Web development is based on free software by developers like you and me, isn’t it? At first glance, this seems to be the case. Let’s take a look at the main tools modern web is mainly developed with nowadays:

  1. Visual Studio Code
  2. TypeScript
  3. React
  4. npm
  5. GitHub
  6. Chrome

Most of the tools are Open Source projects (VS Code only in parts, npm is proprietary). So where are the big companies? Well, all six tools and sites are owned by Big Tech:

  1. Microsoft
  2. Microsoft
  3. Facebook
  4. Microsoft
  5. Microsoft
  6. Google

The tools we use all day rise and fall with the benevolence of companies typically seen as enemies of Free Software by the majority of Open Source developers.

Especially GitHub and npm are irreplaceable because of their large data collection. If Microsoft decides to pull the plug from one moment to the next, the access to the vast collection of free code will be gone at least for some time and the build processes of millions of programs will break.

Of course, these services can and would be replaced by others, but it would take some time until dominant services will emerge and web developers would need to find an interim way of accessing their externalized source code.

(Photo by Max Bender on Unsplash)

Supperfood – Not so tasty after all

This month’s surprise box from Degustabox contained two bottles of “Superfood” by the Austrian company Friya. With basil seeds. OK, nowadays basil seems to be a superfood, too.
The stuff isn’t too tasty after all. The basil seeds are covered with a slimy substance. The whole thing looks like frog spawn.

 

The drink is quite alright but the frog spawn (the basil seeds) is quite disgusting. I really don’t need to have it a second time. I have another bottle containing Chia seeds but I’m not sure about it…

WordPress: add_filter or add_action? It actually doesn’t matter!

It’s a doctrine of WordPress plugin development:

Use actions to expand the functionality and filters to change information.

We’ve all heard it, we always follow that demand. Always? Well…

… if I want to add some functionality and nowhere near or far there is an action hook in the core but only a filter hook, I use that hook without considering the doctrine.

Surprisingly it works. But why? If we all insist that you have to use the right hook type, there has to be a difference between them. Let’s take a look behind the scenes (/wp-includes/plugin.php):

function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
   return add_filter($tag, $function_to_add, $priority, $accepted_args);
}

What? add_action does nothing but call add_filter and nothing else? There is no difference in functionality, it’s only a different name. So there is no reason why you shouldn’t use add_filter instead of add_action if you have no other solution.

I don’t say that you should interchange filter and action hooks at will. Using the correct hook type makes your code more readable and maintainable, for yourself and for others. Nevertheless, if there’s not other way to accomplish your goal but to use a filter hook instead of an action, don’t hesitate, it virtually makes no difference.

Firefox Add-On version hack: Cutomize titlebar

If I want to tweet a link of a site currently opened in my Firefox/Waterfox browser I using the “Hootlet” from “Hootsuite“. This little Add-On simply takes the text  of the titlebar of the browser and adds an ow.ly link so I can tweet it with a single click.

Unfortunately Firefox adds “Firefox” to the titlebar which I have to delete manually every time. But hey, computers are for automationing things so this should be automated, too. The Add-On repository contains an Add-Ons called “Customize Titlebar” which would do exact the requested task but it hasn’t been updated 2009 and is compatible with Firefox 3.9 (!).

In many cases those Add-Ons still work with current versions of Firefox the only problem is that they are marked incompatible. It’s always worth a try to simply increase the entry and check if it still works. Especially Add-Ons that are not critical like “Customize titlebar“. In this case this little hack actually works and I’m happy to be able to use the plugin.

I set the compatibility information of the Add-On to “50.*” so it should work for some while.

 

WordPress: New Version 0.5 of LinkList plugin

For a long time there was no update of my Linklist plugin because it simply worked, no need for a change. The other day I got a request to expand the functionality and I agreed to the proposal.

Version 0.5 now contains the option to include/exclude individual posts or pages from displaying the linklist:

linklist-addnew

The plugin still assumes that you want to add the linklist ater each post or page because that’s why you installed the plugin after all. Nevertheless you can disable the list by de-selecting the provided checkbox.

If you want to change the display for an existing post/page you not need to go to the posts edit page but can easily do it using the Quick edit feature:

linklist-quickedit

I decided to use a drop down menu instead of a check box because WordPress renders the edit screen in a wilful manner and it can’t be manipulated (Can it? Drop me a mail!).

To change the display of the linklist for a large amount of posts/pages you do not need to edit every single post/page individually but can use the Bulk Edit feature:

linklist-bulkedit-1

(If you don’t know how to use Quick or Bulk Edit you can learn it on wordpress.tv.)

You can update your installation by using WordPress’ own update feature or by downloading it from the repository.