Lua Adblocker for Opera

An alternative implementation of OperaPythonAdblock in the much lighter and faster Lua.

See Opera Adblock page for more adblocking options.

Installation: Lua

Download and install the tiny Lua executable for your platform. Precompiled binaries are available from here:

http://lua-users.org/wiki/LuaBinaries

You can download a precompiled binary for windows from the wiki: Zipped Lua Win32 Binary (86KB)

You drop that single .exe ideally somewhere where windows can find it (I use the windows/winnt directory). You can also associate .lua files with lua.exe though it is not needed. If you add Lua.exe, the adblock.lua and the adblock.css into Opera's program folder, you do not need to add any absolute paths; it will just work as-is.

Installation: Adblocker CSS

Create an empty CSS file where the script will store your blocking rules. For the purposes of illustration, we assume it is named adblock.css, saved in C:\\PATH\\adblock.css, where PATH stands for the directory where you saved the CSS file. Again, if you use Opera's program folder, then you don't need the PATH

Installation: Script

Change PATH in the following script to the correct path to the adblock.css file (backslashes in PATH should be double, on *nix use single slashes), then save it as a text file with the .lua extension (e.g. adblock.lua):

if table.getn(arg)<1 then os.exit() end
BLOCK_CSS_FILE="PATH\\adblock.css"

cssFile=io.open(BLOCK_CSS_FILE)
if cssFile then
  cssStr=cssFile:read("*a") or ""
  cssFile:close()
end

cssFile=io.open(BLOCK_CSS_FILE,"w")
if table.getn(arg)==1 then cssFile:write('img[src="'..arg[1]..'"]')
elseif table.getn(arg)==2 then cssFile:write(arg[2]..'"'..arg[1]..'"]')
elseif table.getn(arg)==3 then cssFile:write(arg[2]..'['..arg[3]..'='..'"'..arg[1]..'"]')
elseif table.getn(arg)==4 then cssFile:write(arg[2]..'['..arg[3]..arg[4]..'"'..arg[1]..'"]')
end
if (cssStr=="\n") or (cssStr=="") then cssFile:write('\n{display:none !important;}')
						     else cssFile:write(',\n'..cssStr) end
cssFile:close()

Installation: Menu Command

The format of the menu command is slightly different to the Python version, we must call Lua and put the arguments in the next slot like so:

Item, "Destroy image" = Copy image address & Execute program, "Lua.exe", "PATH\adblock.lua %c" & Select user CSS file,1 & Deselect user CSS file, 1 & Select user CSS file,1 & Deselect user CSS file, 1

This assumes Lua.exe is somewhere in the path. If not you simply need to specify its path.

Comments [Hide comments/form]

Well done. Now everyone can choose option, that suits him the best.

TomekQ (2005-04-16 05:48:23)

all the instructions were very clear; however, how/where do I add/modify a menu command?

68.163.238.180 (2005-05-10 07:23:38)

sorry - should have signed btodd@yahoo.com

68.163.238.180 (2005-05-10 07:24:11)

erm.... what about Linux users?

81.197.4.250 (2005-09-25 23:17:33)

About menu:
Edit /usr/share/opera/ini/standard_menu.ini
(Me Linux is Slackware 10.2)

83.237.43.107 (2005-12-24 01:13:41)

perfect! i had just read about filter.ini and was going to write up a lua wrapper for it..thought i'd google...and here youve done it. great minds think alike :)

66.235.25.133 (2006-02-23 19:38:19)

In this case he saved you from a lot of frustration as the new Opera(now a preview) will have AdBlock? build in

81.4.131.95 (2006-02-24 01:41:19)

antivir says that the windows build linked on the page is a virus

87.5.234.148 (2006-07-01 04:24:15)

Add a comment to this page (use wiki formatting if needed, no HTML/BBCode please). Only registered users can submit links, your comment will be deleted otherwise: