Change local Persona by running a Script


(Mozilla) #1

Hello Mozilla,

I am using linux and I have a setup that automatically extracts the 16 main colors of my Desktop Background and applies it to my Terminal, Texteditor, Steam, Taskbars and to the whole Lightsetup in Room aswell as the Pc case. Yes, it is unbelivably awesome :smiley:

Now I think you already know what I wan’t to ask: How can I convince FF to change colors based on external influence. I have researched in to prefs.js, specifically the setting lightweightThemes.usedThemes

All personas data is stored in the pref lightweightThemes.usedThemes in prefs.js in the profile folder and you can backup that pref to a file or copy that pref to user.js
if you want to initialize a new profile.
Don’t leave it in user.js or you won’t be able to add new personas because it is read on every start of Firefox and you lose personas added in the previous browser session.

I am inclined to crop the exact part of my background and apply it as “persona” to FF without restarting it.

Personas Plus is able to set it by javascript, of witch i know very litte…
If it is installed you can reach the “Apply a Custom Theme” with this URL:

moz-extension://49a96e4c-e7a0-46e4-aa37-b350872c94fd/custom/custom.html

Calling the following “custom.js”:
document.querySelector("#form-submit").addEventListener(“click”, () => {
let backgroundColor = document.querySelector("#accent-color").value;
let textColor = document.querySelector("#text-color").value;

    let header = document.querySelector("#header-image");
    let file = header.files[0];
    let reader = new FileReader();
    reader.addEventListener("load", () => {
        let data = {
            images: {
                headerURL: reader.result,
            },
            colors: {
                accentcolor: backgroundColor,
                textcolor: textColor
            }
        };
        browser.theme.update(data);
        browser.storage.local.set({"currentPersona": data});
    });

    if (file) {
        reader.readAsDataURL(file);
    }

Is there a way to force FF to run a local .js file that then sets a Persona? If so could you point me in the direction ?

Thankyou,
Moz


(Martin Giger) #2

You could make an extension where you’d load an external file every time you want it to update your theme. However for real-time updates you’d probably need to use native messaging: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging

It seems you already found the theming API, but let me link the documentation either way: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/theme

You’ll also find guides etc. for how to get started with WebExtensions as a whole.