You are not logged in.

#1101 2012-10-02 14:05:37

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

I also have 1.8.3 installed and i cannot reproduce it but i remember that there was someone on irc who had the same problem. I'm afraid i have no solution for your problem and i have no idea why it doesn't work for some people.

Offline

#1102 2012-10-02 14:27:33

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
Trying to pass to *bof and *position just a "string", for testing purpose, it compiles but hang when I run it with SIGSEGV.
Maybe it's because I don't know Webkit. tongue

Thanks for your work and suggestions anyway.

Last edited by rix (2012-10-02 14:27:54)

Offline

#1103 2012-10-02 16:56:43

denvist
Member
Registered: 2012-09-18
Posts: 6

Re: dwb - a webkit web browser

@ portix:
I think I understand what the problem is!
Tomorrow I will try to understand in more detail.


sorry for my bad english.

Offline

#1104 2012-10-02 22:57:42

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

rix wrote:

@ portix:
Trying to pass to *bof and *position just a "string", for testing purpose, it compiles but hang when I run it with SIGSEGV.
Maybe it's because I don't know Webkit. tongue

Thanks for your work and suggestions anyway.

You don't need to know anything about webkit to modify the status bar text. I added javascript bindings for the statusbar today, it's already available in dwb-hg but it should be considered experimental.
It should be simpler to modify the statusbar in a userscript. A statusbar similar to dwb's default statusbar:

#!javascript

signals.connect("statusBarChange", function(wv, data) {
    var uri = util.markupEscape(wv.uri);
    if (data.ssl == "trusted") 
        uri = "<span foreground='#0f0'>" + uri + "</span>";
    else if (data.ssl == "untrusted") 
        uri = "<span foreground='#f00'>" + uri + "</span>";

    var statusText = " ";
    if (data.canGoBack || data.canGoForward) {
        statusText += "[";
        if (data.canGoBack)
            statusText += "+";
        if (data.canGoForward)
            statusText += "-";
        statusText += "] ";
    }

    var adjustment = wv.parent.vadjustment;

    var lower = adjustment.lower;
    var upper = adjustment.upper - adjustment.pageSize + lower;
    var value = adjustment.value;

    if (upper == lower)
        statusText += "[all]";
    else if (value == lower)
        statusText += "[top]";
    else if (value == upper)
        statusText += "[bot]";
    else 
    {
        statusText += "[";
        var perc = Math.round(value * 100 / upper);
        if (perc < 10)
            statusText += " ";
        statusText += perc + "%]";
    }

    var progressBarLength = 20;
    var progress = wv.progress;
    if (progress > 0 && progress < 1) 
    {
        var len = Math.round(progress * progressBarLength);
        statusText += "[" + Array(len + 1).join("=") + Array(progressBarLength - len + 1).join(" ") + "] ";
    }
    io.statusBar({ middle : uri, right : statusText});
    return true;
});

Last edited by portix (2012-10-03 00:43:48)

Offline

#1105 2012-10-03 09:10:05

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
you know we love you man. smile

Anyway, I'm dumb so I can't get it working...

I've downloaded the last Hg version as .tar.gz from Dwb site and compile it (notice that when I open it with ./dwb, it loads Google pages instead of dwb:bookmarks and even doesn't recognize trusted and untrusted uri's).
Then I've added the Js above in $HOME/.config/dwb/userscript/ and for testing, I've tried to add (or leave) just a new

var testText = "Some text for testing";

and to add that to the io.statusBar function().
And nothing change. What's my fault? Thank sooo much. smile

Last edited by rix (2012-10-03 09:13:12)

Offline

#1106 2012-10-03 09:25:06

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

I cannot say what your fault is if i don't know how you tried to add it to the io.statusBar-function. The statusBar consists of 2 labels, a middle label and a right label, dwb uses the middle label for the uri and the right label for the rest. The statusBar function takes an object with a text for the middle label and one for the right label, if you want to add it to the right label you can append it to statusText:

io.statusBar({ middle : uri, right : statusText + testText});

btw.: the userscripts-directory is ~/.config/dwb/userscripts.

Offline

#1107 2012-10-03 09:41:36

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
first of all thanks for patience.
Then the directory is corrects, just mispelled.
And about the Js I've tried with:

[...]
var len = Math.round(progress * progressBarLength);
statusText  "[" Array(len 1).join("=") Array(progressBarLength - len 1).join(" ") "] ";
 }                                                                                                                                                                                                               
[b]var testText = "Some text for testing";[/b]
io.statusBar({ middle : uri, right : statusText [b]+ testText[/b] });
return true;
});

And doesn't work.
I've also tried to just add some text to var uri, to remove everything but testText in io.statusBar() and also to remove just statusText. But nothing happened at all.
Thanks for support, it's really appreciate.

Also, could you please suggest me a good free Js guide? The first error of mine was because I didn't know about labels. -_-
Many thanks.

Last edited by rix (2012-10-03 09:44:07)

Offline

#1108 2012-10-03 09:47:54

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

The labels are not javascript things, the labels are gtk-widgets that are used for the statusbar.
Your script seems to be correct, maybe you have whitespaces at the beginning of your script.
The script must begin with #!javascript, no whitespaces or empty lines are allowed.

Last edited by portix (2012-10-03 09:48:10)

Offline

#1109 2012-10-03 09:52:44

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
I thought that was Js things. So this is the reason why I've never found Js tutorials with them.
And, there is no space (except indentation) in my script. Neither at the end, nor at the top. And the first line is the shebang.

#!javascript
signals.connect("statusBarChange", function(wv, data) {
        var uri = util.markupEscape(wv.uri);
            if (data.ssl == "trusted") 
            uri = "<span foreground='#0f0'>" uri "</span>";
    else if (data.ssl == "untrusted") 
            uri = "<span foreground='#f00'>" uri "</span>";

    var statusText = " ";
        if (data.canGoBack || data.canGoForward) {
                    statusText  "[";
                            if (data.canGoBack)
                statusText  ";
        if (data.canGoForward)
                statusText  "-";
        statusText  "] ";
            }

            var adjustment = wv.parent.vadjustment;

                var lower = adjustment.lower;
                    var upper = adjustment.upper - adjustment.pageSize lower;
                        var value = adjustment.value;

                            if (upper == lower)
                                        statusText  "[all]";
                                else if (value == lower)
                                            statusText  "[top]";
                                    else if (value == upper)
                                                statusText  "[bot]";
                                        else 
                                                {
                                                            statusText  "[";
                                                                    var perc = Math.round(value * 100 / upper);
                                                                            if (perc < 10)
                                                                                            statusText  " ";
                                                                                    statusText  perc "%]";
                                                                                        }

                                            var progressBarLength = 20;
                                                var progress = wv.progress;
                                                    if (progress > 0 && progress < 1) 
                                                            {
                                                                        var len = Math.round(progress * progressBarLength);
                                                                                statusText  "[" Array(len 1).join("=") Array(progressBarLength - len 1).join(" ") "] ";
                                                                                    }
                                                                                var testText = "SOME TEXT";
                                                        io.statusBar({ middle : uri, right : statusText + testText });
                                                            return true;
});

Last edited by rix (2012-10-03 09:55:53)

Offline

#1110 2012-10-03 09:57:25

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

There are some syntax errors in your script, if you start dwb from command line dwb print the errors to stderr.

Edit: in javascript strings are concatenated with +.

Last edited by portix (2012-10-03 09:58:20)

Offline

#1111 2012-10-03 10:12:36

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
I've tried again. Clean the file, copy and paste your script and make the little change for the testText. Nothing happen.
If you still find errors just in the mine one, I'd end that it's a copy and paste problem between cli and X.

#!javascript
signals.connect("statusBarChange", function(wv, data) {
    var uri = util.markupEscape(wv.uri);
    if (data.ssl == "trusted") 
        uri = "<span foreground='#0f0'>" + uri + "</span>";
    else if (data.ssl == "untrusted") 
        uri = "<span foreground='#f00'>" + uri + "</span>";

    var statusText = " ";
    if (data.canGoBack || data.canGoForward) {
        statusText += "[";
        if (data.canGoBack)
            statusText += "+";
        if (data.canGoForward)
            statusText += "-";
        statusText += "] ";
    }

    var adjustment = wv.parent.vadjustment;

    var lower = adjustment.lower;
    var upper = adjustment.upper - adjustment.pageSize + lower;
    var value = adjustment.value;

    if (upper == lower)
        statusText += "[all]";
    else if (value == lower)
        statusText += "[top]";
    else if (value == upper)
        statusText += "[bot]";
    else 
    {
        statusText += "[";
        var perc = Math.round(value * 100 / upper);
        if (perc < 10)
            statusText += " ";
        statusText += perc + "%]";
    }

    var progressBarLength = 20;
    var progress = wv.progress;
    if (progress > 0 && progress < 1) 
    {
        var len = Math.round(progress * progressBarLength);
        statusText += "[" + Array(len + 1).join("=") + Array(progressBarLength - len + 1).join(" ") + "] ";
    }
    var text = "TEXT";
    io.statusBar({ middle : uri, right : statusText + text});
    return true;
});

When I run Dwb from cli, it show me the following:

Cannot open (null): file not found

(and many times)

Cannot read lib: Error in the attempt to read file "/usr/share/dwb/scripts/lib". It's a directory.

Last edited by rix (2012-10-03 10:13:47)

Offline

#1112 2012-10-03 10:24:20

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

Ah, you haven't installed dwb? dwb needs to be installed, if you don't install it you need to set the PREFIX variable when you compile it but I recommend to simply use dwb-hg from the AUR. If you build dwb-hg from AUR you will always get the latest revision.

Edit: if you don't want to install it you can build dwb with

make -B PREFIX=$PWD 

Last edited by portix (2012-10-03 10:27:21)

Offline

#1113 2012-10-03 10:29:32

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
for testing the script I've compiled and not installed the last Hg .tar.gz version.
And for everyday use I've installed the community one.

---
Edit 1:
I'm trying with the different prefix.

---
Edit 2:
Don't work even with the prefix.
Should I remove the Community one and install the Aur one?

---
Edit 3:
yes I should. big_smile
It's working like a charme! wink

Just another very little bit question: how I run external program in Js? Now I know how to add date and clock in the status (as I did in Conkeror) but what's about how to show other bash based infos (such as mails, ram, cpu temperature, volume, connection status and updates)?
Just to be clare, I don't want the script but just to understand how I can run an external program, such as lm_sensors for example and save its output in a variable which will be shown in the status.
Thanks a million. smile

Last edited by rix (2012-10-03 10:54:57)

Offline

#1114 2012-10-03 11:50:18

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

There are two functions that run system commands, system.spawn and system.spawnSync, there is also a manpage for the javascript api (man dwb-js) and an online version.

Offline

#1115 2012-10-03 11:59:11

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

rix wrote:

for testing the script I've compiled and not installed the last Hg .tar.gz version.
And for everyday use I've installed the community one.

You can also use dwb and dwb-hg, you can install dwb-hg without pacman into your homedirectory or into /opt, e.g.

make -B install PREFIX=/opt/dwb 

will install all files into /opt/dwb, you can then uninstall it with

make uninstall PREFIX=/opt/dwb

or simply with

rm -rf /opt/dwb

Last edited by portix (2012-10-03 12:01:27)

Offline

#1116 2012-10-03 21:01:41

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
so, I can't get the clock autoupdating itself. I've tried with setInterval(clock(),1000); but with no luck.

And I've also tried with the "spawn" functions for the other infos but again with no luck.
I've tried with piped commands and not piped ones, in many ways. The more I've reached is Dwb showing up a zero.
Like in this example:

[...]
function test() {
    var testing = system.spawn("echo ciao");
    return " " + testing;
    }
[...]
io.statusBar({ middle : uri, right : statusText + test()});

Also I think I don't really understand the "spawnSync" function.

I'm start thinking that even if Js isn't so bad as I was thinking, the best way to do what I'm attempting to do, is the good old Dwm status bar (when I'm in X at least).
Naturally I continue to use Dwb that's the best one (considering FireFox issues) I've ever tried.

Last edited by rix (2012-10-03 21:04:51)

Offline

#1117 2012-10-03 21:19:07

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

You cannot call setInterval in userscripts, in userscripts only the core javascript functions and the functions provided by dwb are available. setInterval is not part of the javascript core language, it is a function of the window-object which cannot directly be accessed from userscripts. You can find most of the builtin functions and objects here, there are also examples for every function but note that only the functions under JavaScript Objects Reference can be used.
dwb has a function that is similar to setInterval it's called timerStart

timerStart(1000, function() {
  var response = system.spawnSync("date +%H:%M");
  var time = response.stdout.replace("\n", "");
  io.statusBar({ right : time });
});

You cannot directly use pipes with the spawn functions, you need to wrap it with sh:

var stdout = system.spawnSync("sh -c 'command1 | command2'").stdout;

Last edited by portix (2012-10-03 21:24:28)

Offline

#1118 2012-10-04 10:14:59

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:
your clock with my date functions work. But the clock crashes Dwb after some seconds.

[...]
    /*function clock() {
        var curTime = new Date();
        if (curHour < 10) {
            var curHour = "  " + 0 + curTime.getHours();
        }
        else {
            var curHour = "  " + curTime.getHours();
        }
        if (curMin < 10) {
            var curMin = 0 + curTime.getMinutes();
        }
        else {
            var curMin = curTime.getMinutes();
        }
        var curTimeString = curHour + ":" + curMin;
        return curTimeString;
    }*/
/*    timerStart(1000, function clock() {
        var response = system.spawnSync("date +%H:%M");
        var time = response.stdout.replace("\n", "");
    
        io.statusBar({ right : date() + time});
    });*/
    io.statusBar({ middle : uri, right : statusText});

In the meanwhile I try for the pipe and will let you know.

Thank so much.


---
Edit:
pipe as you suggested also works but what should I do if I need quotes?
I.e.:

[...]
var volStat = system.spawnSync("sh -c 'amixer get Master | tail -1'").stdout;
[...]

The above works but the following obviously doesn't.

[...]
var volStat = system.spawnSync("sh -c 'amixer get Master | tail -1 | awk '{print $6}' | tr -d '[]'").stdout;
[...]

I've tried with escape sequences and also without the extras single quotes but both don't work.

Last edited by rix (2012-10-04 10:29:39)

Offline

#1119 2012-10-04 11:20:12

jakob
Member
From: Berlin
Registered: 2005-10-27
Posts: 419

Re: dwb - a webkit web browser

Just wanted to confirm here two things:

1) formfiller works again with my o2 wireless router… no idea why it didn't last time

2) I also belong to the people who can't use bandcamp in dwb (w/ adblock enabled), but that's not such an issue…

Offline

#1120 2012-10-04 11:39:04

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

rix wrote:

@ portix:
your clock with my date functions work. But the clock crashes Dwb after some seconds.

[...]
    /*function clock() {
        var curTime = new Date();
        if (curHour < 10) {
            var curHour = "  " + 0 + curTime.getHours();
        }
        else {
            var curHour = "  " + curTime.getHours();
        }
        if (curMin < 10) {
            var curMin = 0 + curTime.getMinutes();
        }
        else {
            var curMin = curTime.getMinutes();
        }
        var curTimeString = curHour + ":" + curMin;
        return curTimeString;
    }*/
/*    timerStart(1000, function clock() {
        var response = system.spawnSync("date +%H:%M");
        var time = response.stdout.replace("\n", "");
    
        io.statusBar({ right : date() + time});
    });*/
    io.statusBar({ middle : uri, right : statusText});

In the meanwhile I try for the pipe and will let you know.

Thank so much.


---
Edit:
pipe as you suggested also works but what should I do if I need quotes?
I.e.:

[...]
var volStat = system.spawnSync("sh -c 'amixer get Master | tail -1'").stdout;
[...]

The above works but the following obviously doesn't.

[...]
var volStat = system.spawnSync("sh -c 'amixer get Master | tail -1 | awk '{print $6}' | tr -d '[]'").stdout;
[...]

I've tried with escape sequences and also without the extras single quotes but both don't work.

I've tried with the unescape() function too and guess what? No luck.

Last edited by rix (2012-10-04 11:40:13)

Offline

#1121 2012-10-04 13:21:10

hellomynameisphil
Member
From: /home/phil/Vancouver
Registered: 2009-10-02
Posts: 257
Website

Re: dwb - a webkit web browser

I have switched to Fedora (for access to the Planet CCRMA repos) and find that when I open dwb, the tabbar is hidden completely by default and only shows up when I switch tabs. I must manually hit 'xt' to show it at the beginning of every session. This setting seems not to be affected by the 'hide tabbar if only one tab' setting, and I can't locate a setting to change this behaviour.

Offline

#1122 2012-10-04 14:43:46

Shinryuu
Member
From: /dev/urandom
Registered: 2010-02-27
Posts: 339

Re: dwb - a webkit web browser

hellomynameisphil wrote:

I have switched to Fedora (for access to the Planet CCRMA repos) and find that when I open dwb, the tabbar is hidden completely by default and only shows up when I switch tabs. I must manually hit 'xt' to show it at the beginning of every session. This setting seems not to be affected by the 'hide tabbar if only one tab' setting, and I can't locate a setting to change this behaviour.

Are you using dwb or dwb-hg?" With hg there's an option like this, "show-single-tab" whether to show the tabbar if only one tab is open [x]. Check your widget packing too.

Offline

#1123 2012-10-04 18:49:49

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: dwb - a webkit web browser

jakob wrote:

2) I also belong to the people who can't use bandcamp in dwb (w/ adblock enabled), but that's not such an issue…

Works for me. But last time I checked it didn't work. Right now I'm logged in. Could this depend on cookies being allowed or not? Certainly looks that way.

Offline

#1124 2012-10-04 19:37:32

portix
Member
Registered: 2009-01-13
Posts: 757

Re: dwb - a webkit web browser

@rix: I don't understand why you want this information in the statusbar of a webbrowser. Anyway, you have to change the quotes and escape them: 

system.spawnSync('sh -c "amixer get Master | tail -1 | awk \'{print $6}\' | tr -d \'[]\'"'

but i think a better solution would be to not pipe at all

system.spawnSync('amixer get Master').stdout.replace(/^(.*[\r\n]*)*\[|\]\s*$/g, "");

You can also achieve it without regular expressions using substring and indexOf.
@hellomynameisphil: is there a capital T in your widget-packing setting?

Offline

#1125 2012-10-04 20:10:53

rix
Member
Registered: 2012-07-25
Posts: 238

Re: dwb - a webkit web browser

@ portix:

portix wrote:

[...] I don't understand why you want this information in the statusbar of a webbrowser. [...]

Because I want a minimal system (also for the lack of memory).
I use Tmux and its status in terminal which isn't visible when I use a graphical app (such a browser).
I'd use the Wm one but this I have two status: Tmux and Wm.
So scripting  the web browser status I can use it and I don't need the Wm one anymore.
If you know a better solution please let me know.

portix wrote:

[...] you have to change the quotes and escape them:  [...]

Already tried. Don't work here.

portix wrote:

[...] but i think a better solution would be to not pipe at all [...]

I'll try and let you know.

And what about the clock which crashes Dwb?

Thanks again.


---
Edit:
sorry if I'm abusing of your patience smile but how I can also make a conditional statement which test if the volume is turn on and then show its level, otherwise just "off"?

Last edited by rix (2012-10-04 20:19:05)

Offline

Board footer

Powered by FluxBB