List Info

Thread: javascript question re user.js




javascript question re user.js
user name
2006-09-13 15:25:16
Hallo 



i have this script in the user.js 


window.opera.addEventListener( 

'BeforeScript', 

function (e) { 

if(e.element.getAttribute('src').indexOf('googlesyndication.com') != -1 ){ 

e.preventDefault(); 

} 

} 

,false); 



and it produces error messages like this one: 

JavaScript - 

Event thread: BeforeScript 

Error: 

name: TypeError 

message: Statement on line 52: Could not convert undefined or null to object 

Backtrace: 

Line 52 of User JS script 

if (e.element.getAttribute("src").indexOf("googlesyndication.com") != - 1) 

At unknown location 

[statement source code not available] 




What do I have to change to make it work without producing an error? 


-- 

regards,

 Jurgen


"In Europe you have watches but in Africa we have time"


Using The Bat! v3.85.03

  Opera v9.01 on WinXP Home v2600 SP2


* PGP key available on request: send mail with subject PGP key request

javascript question re user.js
user name
2006-09-13 16:57:13
Hi Jürgen,

I think you have to use 'BeforeExternalScript' to prevent
external scripts  
 from being executed. The script, that I use looks like
this:

// ==UserScript==
// name Prevent some ads (added by external javascripts)
// author graste[ät]gmail[d0t]com
// namespace http://userjs.org/
// description Disables the loading of external
javascripts that
//				contain "googlesyndication",
"targetpoint",
//				"smarttargetting",
"intellitxt" etc. in
//                      their 'src' attribute
// include *
// ==/UserScript==

// This script is granted to the public domain.

// remove ads that are inserted by external javascripts
window.opera.addEventListener(
	'BeforeExternalScript',
	function(ev){
		var src = ev.element.getAttribute('src');
		if(
src.match(/https?:\/\/([^\/]*\.)?(googlesyndication|targ
etpoint|smarttargetting|intellitxt|aspalliance)\.com\//i) 

) {
			ev.preventDefault();
		}
	}
	,false
);

I put the code above in a .js file and saved that file in my
userjs  
directory with some other user javascripts as well.

Perhaps it helps...

Regards,

Graste

Am 14.09.2006, 01:25 Uhr, schrieb Jurgen Haug  
<MailingListsSafariBears.de>:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hallo
>
>
> i have this script in the user.js
>
> window.opera.addEventListener(
> 'BeforeScript',
> function (e) {
>
if(e.element.getAttribute('src').indexOf('googlesyndicati
on.com') != -1  
> ){
> e.preventDefault();
> }
> }
> ,false);
>
>
> and it produces error messages like this one:
> JavaScript -
> Event thread: BeforeScript
> Error:
> name: TypeError
> message: Statement on line 52: Could not convert
undefined or null to  
> object
> Backtrace:
> Line 52 of User JS script
> if
(e.element.getAttribute("src").indexOf("go
oglesyndication.com") != -  
> 1)
> At unknown location
> [statement source code not available]
>
>
>
> What do I have to change to make it work without
producing an error?
>
> - --
> regards,
>  Jurgen
>
> "In Europe you have watches but in Africa we have
time"
>
> Using The Bat! v3.85.03
>   Opera v9.01 on WinXP Home v2600 SP2
>
> * PGP key available on request: send mail with subject
PGP key request
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (MingW32)
>
>
iD8DBQFFCCLjoXyU9LPZSMERAo3GAJ9PrmGdEcWOyjbSRL3U2zriPtdCqQCf
diBx
> iew69MD4uTczNn+dtT8KcuI=
> =juDI
> -----END PGP SIGNATURE-----


-- 
Unsubscribe: mailto:opera-users-requestopera.com?subject=unsubscribe
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )