Jump to content



Photo

.JS Opera Extension - URL Filter API

site blocking url filter opera extension

  • Please log in to reply
No replies to this topic

#1 Grayski

Grayski

    Neowinian

  • Joined: 10-November 06
  • Location: Wales - UK

Posted 07 March 2013 - 12:16

Hey guys,

I need some assistance (as I am a total noob at this but fancied trying my hand)
I was trying to create an extension for Opera to Block all websites except a handful of white listed ones using the opera.extension.urlfilter

Working from the example here: http://dev.opera.com...url-filter-api/ I have the extension blocking all web sites '* ://*.*/*' tested and working.

The problem comes when I try and remove sites from the block list or add them to the allow (I have tried both ways) .block.remove and .allow.add in accordance with the API - http://dev.opera.com...-api-urlfilter/

The extension just continues to block everything. Could someone take a look and tell me wtf I am actually missing please :)

// Check that the URL Filter API exists
if (typeof opera.extension.urlfilter != 'undefined') {
  
	// Put the sites we want to block in an array
	var sites = ['*<img src='http://www.neowin.net/forum/public/style_emoticons/<#EMO_DIR#>/hmm.gif' class='bbc_emoticon' alt=':/' />/*.*/*',  '*<img src='http://www.neowin.net/forum/public/style_emoticons/<#EMO_DIR#>/hmm.gif' class='bbc_emoticon' alt=':/' />/*.*.*'];

   // Put the sites we want to remove in an array
	var sitesremove = ['*<img src='http://www.neowin.net/forum/public/style_emoticons/<#EMO_DIR#>/hmm.gif' class='bbc_emoticon' alt=':/' />/twitter.com/*',  '*<img src='http://www.neowin.net/forum/public/style_emoticons/<#EMO_DIR#>/hmm.gif' class='bbc_emoticon' alt=':/' />/*.twitter.com'];

	// Asign the URLFilter object to a variable for efficiency
	var filter = opera.extension.urlfilter;

	 // Loop through the array of sites and add each one to the "block" list
	for (var i = 0, len = sites.length; i < len; i++) {
		filter.block.add(sites[i]);

	}

	// Loop through the array of sites and add each one to the "remove" list
	for (var i = 0, len = sitesremove.length; i < len; i++) {
		filter.block.remove(sitesremove[i]);

	}
  
}