You are not logged in.

#501 2011-08-18 13:33:21

jkr
Member
Registered: 2011-08-18
Posts: 1

Re: luakit browser framework (almost with jQuery!)

Hi all,

Thanks for the great browser, Mason. I've really been enjoying using it.

I've been playing around with adding element-hiding to the couple of adblock scripts available:

https://gist.github.com/1073680

and (the one its based on):

https://github.com/quigybo/luakit/blob/ … dblock.lua

I'm using a simple whitelist/blacklist as in the first one, instead of parsing easylist.txt, but either approach should be compatible with what  I've cobbled something together to do that for me. While I'd feel a bit silly sharing my entire "adaway" script (it still relies on too many personal conveniences, and there are many things I'm not sure of) I thought I'd put the relevant snippets up here in case it spurs anyone to make a more complete solution.

The following snippets assumes that, in addition to blacklist and whitelist pattern tables in the above scripts, you also have an `element_table` script, where each element is a table with optional "site", "id", "tag", and "class" elements. If site is there it will match elements only for pattern-matched uris; if not, it will match for all. "id" takes precedence, and it will assume there is only one element with the id in the doc. You can use "tag" and "class" together, or put '*" in the tag field.  So, you should somehow parse data into an element_table something like this:

{{ tag = "div",
      class = "Ads"},
             
   { site = "villagevoice%.com",
       tag = "div",
       class = "MiddleAdContainer"},

   { tag = "div",
      class = "r_ad_box"},

    { site = "bbc%.co%.uk",
        id = "advertiser-container"}}

(Part of the reason I'm only sharing snippets is that I currently use `dofile` to read my real table in, since it's just for personal use, but that doesn't seem a good thing to suggest that others do.)

And then the relevant js and blocking functions are as follows:

local my_js = [[ 
var adaway = {

    removeElementById: function (id) {
        var d = document.getElementById(id);
        if (d) {
           d.style.display = 'none';
        }
    },

    removeElementsByClass: function(classname) {
        var elems = document.getElementsByClassName(classname) 
        for (var i = 0; i < elems.length; i++) {
            elems[i].style.display = 'none';
        }
    },


    removeElementByTagAndClass: function(tagname, classname) {
        if (tagname == "*") {
            this.removeElementsByClass(classname);
        } else {
            var d = document.getElementsByTagName(tagname);
            for (var i = 0; i < d.length; i++) {
                if (d[i].className == classname)
                    d[i].style.display = 'none';
            }
        }
    }
};
]]

function remove_element_by_id(w, id)
   local js_string = string.format("adaway.removeElementById(\"%s\");", id)
   w:eval_js(js_string)
end

function remove_element_by_tag_and_class(w, tag, class)
   local js_string = string.format("adaway.removeElementByTagAndClass(\"%s\", \"%s\");", tag, class)
   w:eval_js(js_string)
end

function block_elements(w, uri)
   w:eval_js(my_js)
   for _, element in ipairs(element_table) do
      if (element.site and string.match(uri, element.site)) or (not element.site) then
         if element.id then
            remove_element_by_id(w, element.id)
         elseif (element.tag and element.class) then
            remove_element_by_tag_and_class(w, element.tag, element.class)
         end
      end
   end
end

And then I add the following to the whitelisting and blacklisting ad-blocking routines in the two scripts this was based on. (`uri_check` will return true or false based on the whitelist or blacklist.):

webview.init_funcs.adaway_signals = 
function(view, w)
   view:add_signal("navigation-request",
                   function(v, uri)
                      return uri_check(uri)
                end)
   view:add_signal("resource-request-starting",
                   function(v, uri)
                      return uri_check(uri)
                end)
   view:add_signal("load-status",
                   function (v, status)
                      if status == "first-visual" then
                         block_elements(w, v.uri)
                      end
                end)
end

Again, this isn't meant to be a drop-in replacement. I'm not really sure enough of my understanding of luakit or js to suggest it. But if you're already using one of the adblocking scripts, I'm posting these snippets in the hope that you might find them (or whatever improvement you make on them) useful.

Last edited by jkr (2011-08-18 13:34:53)

Offline

#502 2011-08-20 04:02:13

stryder
Member
Registered: 2009-02-28
Posts: 500

Re: luakit browser framework (almost with jQuery!)

joshdmiller wrote:
stryder wrote:

(libwebkit is 1.2.7-1 only BTW, and luakit is 20110815-1)

Are you able to compile libwebkit-git from the AUR on your platform to see if the age of libwebkit is indeed the problem?

I found out that the testing version is 1.4 and so upgraded the system to testing. Gmail now loads, yahoo still insists that I use their older version and arch wiki still does NOT load with css! No biggie though, I was just curious. Really enjoying this great browser.

Offline

#503 2011-08-21 06:15:59

innn
Member
Registered: 2010-10-12
Posts: 96

Re: luakit browser framework (almost with jQuery!)

please can someone tell me why can't I access https sites from luakit (yahoo mail, gmail), it says  TLS/SSL error ,install glib-networking, but that package is installed

Offline

#504 2011-08-21 08:07:18

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

Re: luakit browser framework (almost with jQuery!)

innn wrote:

please can someone tell me why can't I access https sites from luakit (yahoo mail, gmail), it says  TLS/SSL error ,install glib-networking, but that package is installed

That was a bug for 1 day. What's your version of glib-networking?

% pacman -Qi glib-networking | grep Version
Version        : 2.28.7-4

If you don't receive this version on a pacman -Syu, maybe your mirror is out of date and should be replaced.

Offline

#505 2011-08-21 14:30:54

innn
Member
Registered: 2010-10-12
Posts: 96

Re: luakit browser framework (almost with jQuery!)

@Army thanks, the version was 2.28.7-4 but I did an upgrade of whole system and now it works

Offline

#506 2011-08-23 06:58:06

stryder
Member
Registered: 2009-02-28
Posts: 500

Re: luakit browser framework (almost with jQuery!)

I notice that alt-number is programmed to jump to the corresponding tab. What I would like is to reprogram that so that it responds to pressing keys in succession, for example, if I press "g" and then "1" or some other number. Can someone show me how this can be done?

Offline

#507 2011-08-23 09:09:53

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

Re: luakit browser framework (almost with jQuery!)

Nice idea! I did it this way

# cat ~/.config/luakit/binds.lua
add_binds("normal", {
[...other stuff here...]
    buf("^g1$", function (w) w.tabs:switch(1) end),
    buf("^g2$", function (w) w.tabs:switch(2) end),
    buf("^g3$", function (w) w.tabs:switch(3) end),
    buf("^g4$", function (w) w.tabs:switch(4) end),
    buf("^g5$", function (w) w.tabs:switch(5) end),
    buf("^g6$", function (w) w.tabs:switch(6) end),
    buf("^g7$", function (w) w.tabs:switch(7) end),
    buf("^g8$", function (w) w.tabs:switch(8) end),
    buf("^g9$", function (w) w.tabs:switch(9) end),
    buf("^g0$", function (w) w.tabs:switch(10) end),
})

I know this can be done more beautifully with a loop, but I don't know how that works in lua wink

Last edited by Army (2011-08-23 09:11:48)

Offline

#508 2011-08-23 09:51:30

cf8
Member
From: Russia
Registered: 2008-10-21
Posts: 83

Re: luakit browser framework (almost with jQuery!)

@stryder, @Army
this binds are out-of-the-box : n-gt - will switch tab to "n"

Offline

#509 2011-08-23 09:55:47

cf8
Member
From: Russia
Registered: 2008-10-21
Posts: 83

Re: luakit browser framework (almost with jQuery!)

i have one interesting proposal to the tabs functionality:
will be good to implement firefox-like tab-groups, for example if im on the first tab-group, then i press 2-tg - the second tab-group will be created etc and ready for new tabs to fill, also need to make some tab-group indicator.
any thoughts?

Offline

#510 2011-08-23 10:27:21

stryder
Member
Registered: 2009-02-28
Posts: 500

Re: luakit browser framework (almost with jQuery!)

cf8 wrote:

@stryder, @Army
this binds are out-of-the-box : n-gt - will switch tab to "n"

Ah, thanks. Didn't figure out that part of binds.lua. Another evidence how wonderfully luakit has been packaged.

Offline

#511 2011-08-23 20:16:35

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

Re: luakit browser framework (almost with jQuery!)

I think I should take a good look into the binds.lua *lol* Looks like there are still some treasures to find smile

Offline

#512 2011-08-24 03:08:12

stryder
Member
Registered: 2009-02-28
Posts: 500

Re: luakit browser framework (almost with jQuery!)

I have remapped many binds but these below are defaults that I find useful. I thought putting them together might help someone. For others, look through binds.lua.

gd=view downloads page in same tab
gD=same but in new tab
[num]gt=go to tab[num]
d=close tab
f=map urls in page to keys to be activated by pressing relevant keys
(use F to load urls in new tab)
i=insert mode
Esc=clear all modes
o=open url in same tab
O=open the "open" dialog with the current url for editing
t=open url in new tab
w=open url in new window
r=reload current url
[num]b=load back page [num] in history
ctrl-ZZ=quit
M[letter or number]=quickmark url to that letter or number
(activate by go[quickmark] or gn[quickmark] (for new tab)
B[Enter]=create bookmark of current url
gb=view bookmarks (gB for new tab, you get the idea)
ctrl-click url=open in new tab

To use ctrl-c to copy to clipboard, go to insert mode first (press i)
You can then use ctrl-v to paste.


To use userconf.lua to remap binds,
paste the binding aliases there:
-- Binding aliases
local key, buf, but = lousy.bind.key, lousy.bind.buf, lousy.bind.but

then add binds within the brackets:

------------------ binds.lua
add_binds("normal", {

--for example
   -- History
    key({},          "b",           function (w, m) w:back(m.count)    end),
    key({},          "n",           function (w, m) w:forward(m.count) end),

}, true)

These are stuff I have learnt looking through this thread.

Last edited by stryder (2011-08-24 03:10:09)

Offline

#513 2011-08-25 16:19:29

TheImmortalPhoenix
Member
From: 127.0.0.1
Registered: 2011-08-13
Posts: 436

Re: luakit browser framework (almost with jQuery!)

Hi men, today i've decided to use luakit, but i don't know hot to configure it...could you help me? What are the commands to use it? Can i enable the middle mouse scroll? How can i set bookmarks? Please help me!!

Offline

#514 2011-08-25 16:35:55

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: luakit browser framework (almost with jQuery!)

TheImmortalPhoenix wrote:

Hi men, today i've decided to use luakit, but i don't know hot to configure it...could you help me? What are the commands to use it? Can i enable the middle mouse scroll? How can i set bookmarks? Please help me!!

Woah, slow down. Luakit is configured using lua scripts. Look in ~/.config/luakit/. The files you are interested are located there. If you don't know lua, don't be daunted. It's an easy language to learn. Luakit comes with sane defaults so you likely will not need to do more than some tweaking. Also be sure to visit the website. There is a wiki, a FAQ and other documentation.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#515 2011-08-25 17:34:56

TheImmortalPhoenix
Member
From: 127.0.0.1
Registered: 2011-08-13
Posts: 436

Re: luakit browser framework (almost with jQuery!)

the

fsckd wrote:
TheImmortalPhoenix wrote:

Hi men, today i've decided to use luakit, but i don't know hot to configure it...could you help me? What are the commands to use it? Can i enable the middle mouse scroll? How can i set bookmarks? Please help me!!

Woah, slow down. Luakit is configured using lua scripts. Look in ~/.config/luakit/. The files you are interested are located there. If you don't know lua, don't be daunted. It's an easy language to learn. Luakit comes with sane defaults so you likely will not need to do more than some tweaking. Also be sure to visit the website. There is a wiki, a FAQ and other documentation.

I use awesome Wm and i understand a bit tha lua language...however i found config file and edited them...i set the theme and the key bindings...tha only things i want to know are first how to enable scrolling with middle buttom of mouse and second how to set bookmarks and bind them....

Offline

#516 2011-08-26 08:43:32

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

Re: luakit browser framework (almost with jQuery!)

TheImmortalPhoenix wrote:

how to enable scrolling with middle buttom of mouse

Afaik that's not possible by default, maybe somebody knows how to do that? To be honest, I never saw this in a webkit browser..

TheImmortalPhoenix wrote:

how to set bookmarks and bind them....

Type a capitol b and optionally type a describtion after the link. To watch the bookmarks, type gb to open them in the current tab, type gB to open them in a new tab. What do you mean with "bind them"?

Offline

#517 2011-08-26 09:26:40

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

Re: luakit browser framework (almost with jQuery!)

Army wrote:

Afaik that's not possible by default, maybe somebody knows how to do that? To be honest, I never saw this in a webkit browser.

I have written a javascript-script that i use with dwb some time ago, it should also work with luakit but i don't know how to integrate scripts into luakit, but here it is: http://sprunge.us/FIIi

Offline

#518 2011-08-26 15:08:29

TheImmortalPhoenix
Member
From: 127.0.0.1
Registered: 2011-08-13
Posts: 436

Re: luakit browser framework (almost with jQuery!)

Army wrote:

Type a capitol b and optionally type a describtion after the link. To watch the bookmarks, type gb to open them in the current tab, type gB to open them in a new tab. What do you mean with "bind them"?

I mean to associate a bookmarks (Arch for example) to a combination of the keyboard

Last edited by TheImmortalPhoenix (2011-08-26 15:09:25)

Offline

#519 2011-08-26 15:45:42

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

Re: luakit browser framework (almost with jQuery!)

Do you mean a quickmark? To e.g. open bbs.archlinux.org by a specific command? For that, type :qmark 1 https://bbs.archlinux.org, after that you get to this page with "go1" opening it in the current tab, "gn1" to open it in a new tab.

Offline

#520 2011-08-26 16:30:15

TheImmortalPhoenix
Member
From: 127.0.0.1
Registered: 2011-08-13
Posts: 436

Re: luakit browser framework (almost with jQuery!)

Army wrote:

Do you mean a quickmark? To e.g. open bbs.archlinux.org by a specific command? For that, type :qmark 1 https://bbs.archlinux.org, after that you get to this page with "go1" opening it in the current tab, "gn1" to open it in a new tab.

That's what i meant!! Thanks!! I Have another few questions, then i could say luakit is perfect!!

1) Why luakit don't save passwords and usernames? Each time i have to re-insert all!!
2) I created a list of bookmarks, but i committed some mistakes with tags...how can i edit them?
3) Can i change commands synthax? For example change :bookmark in :b ?

Thanks to all friends!

Offline

#521 2011-08-26 20:16:59

mkaito
Member
From: Spain
Registered: 2010-06-12
Posts: 126
Website

Re: luakit browser framework (almost with jQuery!)

TheImmortalPhoenix wrote:

1) Why luakit don't save passwords and usernames? Each time i have to re-insert all!!

Have a look at /usr/share/luakit/lib/formfiller.lua

TheImmortalPhoenix wrote:

2) I created a list of bookmarks, but i committed some mistakes with tags...how can i edit them?

Your bookmarks are stored in $XDG_DATA_HOME/luakit/bookmarks

Although the current bookmarks implementation could use some love, really. I've tried, but my Lua seems to be lacking.

TheImmortalPhoenix wrote:

2) I created a list of boo3) Can i change commands synthax? For example change :bookmark in :b ?

No idea if there's support for alias tbh, I just bind things to keys tongue


Fear me! I have root! Sometimes...

Offline

#522 2011-08-26 20:22:42

mkaito
Member
From: Spain
Registered: 2010-06-12
Posts: 126
Website

Re: luakit browser framework (almost with jQuery!)

By the way, do you guys think it's possible to get this Convergence (distributed notary-based CA certificate thing) to run with luakit? I have no idea whether SSL is handled internally by libwebkit, or if luakit provides the necesary hooks for it.


Fear me! I have root! Sometimes...

Offline

#523 2011-08-26 21:07:08

TheImmortalPhoenix
Member
From: 127.0.0.1
Registered: 2011-08-13
Posts: 436

Re: luakit browser framework (almost with jQuery!)

I resolved bookmarks problem...but i still have problems with formfiller...i click "zn", i add user and pass and when i click "zl" my profile is not load!

Offline

#524 2011-08-26 22:05:37

mkaito
Member
From: Spain
Registered: 2010-06-12
Posts: 126
Website

Re: luakit browser framework (almost with jQuery!)

I don't use formfill myself... I just type the stuff out. Having my passwords on my hard drive isn't something I like anyway. But I know it can be used for this purpose, so maybe there's something wrong on your side. I'm sure some of the other luakit users will provide some more insight on formfill.


Fear me! I have root! Sometimes...

Offline

#525 2011-08-27 06:35:51

nXqd
Member
Registered: 2010-07-01
Posts: 173

Re: luakit browser framework (almost with jQuery!)

Just switch from jumanji to luakit. I hope this will be better. Figuring out how to open developer tool in luakit wink


When you live for a strong purpose, then hard work isn't an option. It's a necessity. - Steve Pavlina
dotFiles

Offline

Board footer

Powered by FluxBB