ibillingsley / HumbleNewTabPage

New tab page extension for Chrome and Firefox
https://chrome.google.com/webstore/detail/mfgdmpfihlmdekaclngibpjhdebndhdj
MIT License
646 stars 103 forks source link

feature request: Icon customization in Firefox #95

Open pcepulionis opened 3 years ago

pcepulionis commented 3 years ago

Blank default icons (or blurry ones) instead of the correct icons are annoying in Firefox. Especially if those webpage are some of the main ones you use with this extension. So I've looked into a code and I have an idea how to fix this problem with favicons provided as base64 images.

  1. In newtab.html we add options_favicon_json as one of the advanced options:

            <fieldset>
                <legend>Favicon JSON</legend>
                <label><textarea id="options_favicon_json"></textarea></label>
            </fieldset>
  2. in newtab.js we are appending favicon_json option in var config dict:

    number_recent: 10,
    icon_provider: 1,
    favicon_json: "{}" // <--- Right here
    };
  3. in newtab.js we are modifying function getIcon(node) function to search for icons in dictionary first. If there is no defined domain, then extension is searching icon in selected provider:

        if (domain) {
            var json_dict_temp = getConfig('favicon_json');
            var json_dict = JSON.parse(json_dict_temp);
            for (var d_key in json_dict) {
                var d_value = json_dict[d_key];
                if (domain[1].includes(d_key)) {
                    var icon = document.createElement('img');
                    icon.style.width = 64;
                    icon.style.height = 64;
                    icon.src = d_value
                    icon.className = 'icon';
                    icon.alt = ' ';
                    return icon;
                }
            } if (iconProvider == 1) {

and after this, users can assign icon as base64 image based on domain: image

The only missing part is favicon_json validation to avoid the error in JSON.parse step. Also, I think my code could be better optimized because for the first time in my life I looked at JavaScript code and it was just a quick test.

I hope this suggestion was helpful and I could add a verification step for JSON.parse step if you would like to implement it.

Btw, I love your extension and have been using it for many years ❤️

e1a6 commented 3 years ago

Thank you P. Cepulionis!

I love the extension Isaiah Billingsley has made as well and I've been waiting this feature for a long time but i don't have the knowledge to help like you did...

I hope he will implement it.