m-khvoinitsky / dark-background-light-text-extension

Firefox addon that turns every page colors into "light text on dark background"
Mozilla Public License 2.0
361 stars 27 forks source link

Feature request: automation support #38

Open schrauger opened 8 years ago

schrauger commented 8 years ago

I use this on Android, and I would love to be able to have automation hooks. Ideally, somehow responding to Tasker to enable or disable the dark text. I have no idea if that's possible with a Firefox add on, but if it is, that would be awesome to have.

Possibly more doable is to have an option for scheduling. That is, have a start and stop time, so that the plugin automatically activates in the evening and reverts to normal viewing in the morning. That is what I end up doing manually, anyway, and as long as plug-ins can determine the current time, it should be possible.

As a developer, I'm willing to try to add the time feature on. I've never worked with Firefox plug-ins before, but I am a programmer. But if the author of the plug-in can do it, so much the better.

m-khvoinitsky commented 7 years ago

Personally, I don't need such feature as I always use dark variant. So, I can't promise to make a solution quickly. Currently, AFAIK, it's impossible to send or receive intents from other Android applications. But it should be possible to setup a communication channel some other way. In the simplest case, if Tasker is able to write files to sdcard like /sdcard/firefox_dark with simple content ("on" or "off") depending on it's conditions, it's possible to write very simple add-on which will read this file and depending on it's content turn the add-on on or off.

I've just tried to write a simple demo of such add-on using Add-on SDK:

let file = require('sdk/io/file');
let prefs = require('sdk/preferences/service');
let { setInterval } = require('sdk/timers');

function check_and_do() {
    let enable = false;
    try {
        enable = (file.read('/tmp/fx_dark').indexOf('on') >= 0);
    } catch (e) { console.log(e) }
    prefs.set('extensions.jid1-QoFqdK4qzUfGWQ@jetpack.enabled', enable);
}

setInterval(check_and_do, 10000);
check_and_do();

It will check file /tmp/fx_dark every 10 seconds (10000 ms - it's better to use significantly larger value for mobile otherwise it will drain your battery) for 'on' substring and enable or disable (extensions.jid1-QoFqdK4qzUfGWQ@jetpack.enabled setting key) depending on it.