Add-on to exclude domains from right-click?

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15621
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Add-on to exclude domains from right-click?

Post by ChrisGreaves »

agibsonsw wrote: They almost fell off the end of my screen.
Well, Yes.
I wanted to talk about that with you.
When you have a minute :evilgrin:
I haven't quite finished though: The attached version can sort the list and delete all excluded domains.
I gave it a quick test, nothing strenuous. I think the real test will be regular use over the next few days when I am back in search-for-solutions mode.
Lacking real data I went to Hans's Post and quickly pasted those two URLs in as both URL and Title. Sorted the list, looks OK.
4.png
(Note in passing how you are shunting News, Weather etc off my toolbar!)
If you are looking for exercises to develop your skill, I could post a couple of suggestions, but they are just that - exercises to stretch your boundaries.
(1) A command button to allow me to EDIT an entry. Now that I see "www.experts-exchange.com" I realize that I'd like to title it something like "Issues a pop-up paynow screen". The title with "bigresource.com" ought to be something like "too low-level for me", or whatever. As far as I can see I need to paste the title into the box, click delete, then re-paste the title, which fortuitously in my example happens to be the URL, and Add back the domain.
Which leads to
(2) Display the URL and the Title rather than just the title
(3) Sort by URL or Sort by Title.
But don't rush into this. By mid-week I'll probably have some more interesting suggestions (grin)
Again I would be grateful if someone could test it a little more.
As noted above: I think the real test will be regular use over the next few days when I am back in search-for-solutions mode.. Once this thing gets strapped on for a full day's work ....

Why not take the rest of the weekend off? Nice hot bath, good book on origins of the Third Balkan War, ...
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15621
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Add-on to exclude domains from right-click?

Post by ChrisGreaves »

agibsonsw wrote: They almost fell off the end of my screen.
P.S. I see we are now into 5 screens of this thread, mainly because of my large screenshots.
It will soon be time to start a new thread, perhaps kicked off with your latest version as the first post?
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Add-on to exclude domains from right-click?

Post by HansV »

ChrisGreaves wrote:P.S. I see we are now into 5 screens of this thread, mainly because of my large screenshots.
The number and size of the screenshots don't matter - there's a fixed number of 20 posts per page. This thread now has more than 80 replies...
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15621
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Add-on to exclude domains from right-click?

Post by ChrisGreaves »

HansV wrote:
ChrisGreaves wrote:The number and size of the screenshots don't matter -
Thanks, Hans. Makes Sense. I still have a feeling that it's getting out of hand! (grin) I am overwhelmed.
There's nothing heavier than an empty water bottle

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

There is a (very) slight error in the last version - which I shall blame on Dreamweaver. Please try this one (which should also sort in ascending and descending order).

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Andy's Search Page</title>
<script type="text/javascript">

	function Go(frm)
	{
		var sText;
		var sSites = "";
		sText = document.getElementById("searchText").value;
		if ( sText != "" )
		{
			for (var i=0; i < frm.elements.length; i++)
				if ( frm.elements[i].name == 'checks' )
					if ( frm.elements[i].checked == true )
						sSites += ' -site:' + frm.elements[i].value;     		
			// window.open("http://www.google.com/search?q=" + escape(sText).replace(/ /g,"+") + sSites);
			window.open("http://www.google.com/search?q=" + sText + sSites);
		}
		else
		{
			window.alert('You must enter something into the search box!');
			document.getElementById("searchText").focus();
		}
	}
	
	function SetCookie( name, value, expires, path, domain, secure )
	{
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );
		/*
		If the expires variable is set, make the correct expires time.
		Expires is a number of days. To make it hours delete * 24,
		to make it minutes delete * 60 * 24. */
		if ( expires )
		{
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date( today.getTime() + (expires) );
		
		document.cookie = name + "=" +escape( value ) +
			( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
			( ( path ) ? ";path=" + path : "" ) +
			( ( domain ) ? ";domain=" + domain : "" ) +
			( ( secure ) ? ";secure" : "" );
	}
	
	// this fixes an issue with the old method, ambiguous values
	// with this test document.cookie.indexOf( name + "=" );
	function GetCookie( check_name ) 
	{
		// first we'll split this cookie up into name/value pairs
		// note: document.cookie only returns name=value, not the other components
		var a_all_cookies = document.cookie.split( ';' );
		var a_temp_cookie = '';
		var cookie_name = '';
		var cookie_value = '';
		var b_cookie_found = false; // set boolean t/f default f
	
		for ( i = 0; i < a_all_cookies.length; i++ )
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );

			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
			// if the extracted name matches passed check_name
			if ( cookie_name == check_name )
			{
				b_cookie_found = true;
				// we need to handle case where cookie has no value but exists (no = sign, that is):
				if ( a_temp_cookie.length > 1 )
				{
					cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
				}
				// note that in cases where cookie is initialized but no value, null is returned
				return cookie_value;
				break;
			}
			a_temp_cookie = null;
			cookie_name = '';
		}
		if ( !b_cookie_found )
		{
			return null;
		}
	}
	
	// this deletes the cookie when called
	function DeleteCookie( name, path, domain ) 
	{
		if ( GetCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) +
				";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
	function DeleteDomain( dTitle )
	{
		var cValue;
		if ( dTitle == "" || dTitle == null )
		{
			window.alert('Enter the correct Title to delete it.');
			document.getElementById("otherT").focus();
			return 0;
		}
		cValue = GetCookie(dTitle);
		if ( cValue )
		{	
			DeleteCookie(dTitle);
			var dadId = cValue.replace(/\./g,'') + '_dad';
			var dad = document.getElementById(dadId);
			var grandad = document.forms[0];
			var discard = grandad.removeChild(dad);    
		}
		else
		{
			window.alert("That title is incorrect, or it\'s deleted already." + dTitle);
			document.getElementById("otherT").focus();
		}
	}
	function AddCheck(sDomain, sTitle, usingBox)	
	{
		if ( sDomain != "")
		{
			var newDiv = document.createElement("p");
			var newText = document.createTextNode((sTitle != "") ? sTitle : sDomain);
			var newChk = document.createElement("input");
			newChk.type = "checkbox";
			newChk.id = sDomain.replace(/\./g,'');
			newDiv.id = newChk.id + '_dad';
			newChk.name = "checks";
			newChk.checked = "checked";
			newChk.value = sDomain;
			newDiv.appendChild(newChk);
			newDiv.appendChild(newText);
			document.forms[0].appendChild(newDiv);
			SetCookie((sTitle != "") ? sTitle : sDomain, sDomain, 30);	// , '', '/', '', '' //
			// Cookie name/values will expire in 30 days - change this number to any other you fancy.
			if ( usingBox )
			{
				document.getElementById("otherD").value = '';
				document.getElementById("otherT").value = '';
			}
		}
		else if ( usingBox )
        {
            window.alert('Type a domain to exclude.');
            document.getElementById("otherD").focus();
        }
	}
	function GetAllDomains()
	{
		var allDoms = document.cookie.split( ';' );
		var pairs = '';
		var title = '';
		var dom = '';
		for ( var i = 0; i < allDoms.length; i++ )
		{
			pairs = allDoms[i].split( '=' );
			// and trim left/right whitespace while we're at it
			title = pairs[0].replace(/^\s+|\s+$/g, '');
			dom = unescape( pairs[1].replace(/^\s+|\s+$/g, '') );
			AddCheck(dom,title,false);
		}
	}
	function DelAllDomains(ask)
	{
		if ( document.cookie.length > 0 )
		{
			if ( ask ) 
			{
				var ans = confirm("Delete all domains?");
				if ( !ans ) return 0;
			}
			var allDoms = document.cookie.split( ';' );
			var pairs = '';
			var title = '';
			for ( var i = allDoms.length-1; i >=0 ; i-- )
			{
				pairs = allDoms[i].split( '=' );
				// and trim left/right whitespace while we're at it
				title = pairs[0].replace(/^\s+|\s+$/g, '');
				DeleteDomain(title);
			}
		}
		else 
			window.alert('Nothing to delete.');
	}
	function SortDomains(btn)
	{
		if ( document.cookie.length > 0 )
		{
			var allDoms = document.cookie.replace(/(;)\s+/g, '$1').split(';').sort();
			if ( btn.value == 'Asc' )
			{
				btn.value = 'Desc';
			}
			else
			{
				allDoms.reverse();
				btn.value = 'Asc';
			}
			DelAllDomains(false);
			var pairs = '';
			var title = '';
			var dom = '';
			for ( var i = 0; i < allDoms.length; i++ )
			{
				pairs = allDoms[i].split( '=' );
				// and trim left/right whitespace while we're at it
				title = pairs[0].replace(/^\s+|\s+$/g, '');
				dom = unescape( pairs[1].replace(/^\s+|\s+$/g, '') );
				AddCheck(dom,title,false);
			}
		}
		else
			window.alert('Nothing to sort.');
	}
</script>
</head>

<body style="font-family:Trebuchet MS, Georgia, Lucida;" onload="GetAllDomains();">
<h1>Andy's Search </h1>

<form id="myForm" action="" onsubmit="return false;">
<input type="text" id="searchText" size="80" maxlength="100" />
<button type="submit" id="search" onclick="Go(document.forms[0]);">Go Search</button>
<p>Choose sites to exclude:</p>
<p>Domain&nbsp;<input type="text" id="otherD" />&nbsp;Title&nbsp;<input type="text" id="otherT" />&nbsp;&nbsp;&nbsp;
<button type="button" onclick="AddCheck(document.getElementById('otherD').value,document.getElementById('otherT').value,true);">
Add</button>&nbsp;&nbsp;
<button type="button" onclick="DeleteDomain(document.getElementById('otherT').value);">Delete</button>
<p><button type="button" onclick="DelAllDomains(true);">Delete All</button>&nbsp;&nbsp;
<button type="button" id="sort" value="Asc" onclick="SortDomains(document.forms[0].sort);">Sort</button></p>
</form>

</body>
</html>
You do not have the required permissions to view the files attached to this post.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

Hi, and this could be (almost) the final product -(but probably not..).

When you move the mouse under the Title the domain is revealed. If you click on this domain it will remain visible. If you double-click it all domains will become visible. These will persist until the page is sorted or refreshed. Most people do this by hiding the text, but I just used white text :grin:
go_search5.png
When the list is sorted the domains/cookies are deleted and re-created. This re-sets the expire time for another 30 days. This is slightly illogical but ...
You do not have the required permissions to view the files attached to this post.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Add-on to exclude domains from right-click?

Post by HansV »

It's getting better and better!

:whisper: Can it make a nice cup of tea too? :smile:
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12605
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Add-on to exclude domains from right-click?

Post by StuartR »

HansV wrote:It's getting better and better!

:whisper: Can it make a nice cup of tea too? :smile:
How about a pint of Guinness?
StuartR


User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

StuartR wrote:
HansV wrote:It's getting better and better!

:whisper: Can it make a nice cup of tea too? :smile:
How about a pint of Guinness?
It will do this if you triple-click :cheers:
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

I was reminded by Chris that this enquiry began (for me) on Tuesday evening and I was at work for the rest of the week. i think this shows the power of the internet!

I would search for bits of code I would need, scanning through, say, ten sites to find a good implementation. Grab it, strip out the bits I didn't need and modify it for my page. (Of course it helped that I kinda new what I was looking for.)

In the (good) old days I would have had to leaf through a number of books, and then realise that I needed another book. I would then have to wait until morning and get on a bus (or wait til payday!).
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15621
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Add-on to exclude domains from right-click?

Post by ChrisGreaves »

agibsonsw wrote:... scanning through, say, ten sites to find a good implementation.
How did you filter out garbage sites, such as http://www.experts-exchange" onclick="window.open(this.href);return false;? :innocent:
There's nothing heavier than an empty water bottle

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15621
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Add-on to exclude domains from right-click?

Post by ChrisGreaves »

agibsonsw wrote:It will do this if you triple-click :cheers:
This shows up in Toronto as "It will do this if you triple-click :coffeetime: ". We are a few hours, and years, behind you.

Speaking of triple-click.
Back in the Good Old Days(TM) of this littlelet, I was able to select some text in a web page, click on the button, and the search box would be loaded with the selected text AND the search executed.
It seems to me that this project is turning into a speed-of-light version of Microsoft Office, but they pull the rug from under me only once every 3 years or so.
And no cat wants me, really, to go from petulant to exhilarated to :burnup: in less than a week.
Trust me.
There's nothing heavier than an empty water bottle

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

Last (optional) version today I promise! You can enter words to exclude as well. They will remain in the textbox between searches.
go_search6.png
and double-clicking a checkbox will un-check them all. You could then re-check them by sorting the list.

I mentioned that sorting the list causes their cookie expiration to be extended for another 30 days. On reflection I think this could be quite handy.

No one's mentioned any errors as yet? Andy.
You do not have the required permissions to view the files attached to this post.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
Hey Jude
5StarLounger
Posts: 1015
Joined: 24 Jan 2010, 15:45
Location: Ohio, U.S.A.

Re: Add-on to exclude domains from right-click?

Post by Hey Jude »

I am quite excited over your latest rendition Andy :cheers:
's latest version results.png
I substituted this one in my Bookmark Toolbar now :thankyou: :blowup: :bananas:

It worked so nicely :fanfare: :clapping: Thank you for all your hard work for our benefit. I know I came up with a simple code, but this won't take the rest of my lifetime to figure out thanks to good techs as yourself :grin:
You do not have the required permissions to view the files attached to this post.
♫...Take a sad song and make it better . . .♫ Image

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

Hello.

Your screenshot shows the site titles rather than the domains in the Google search bar. Is that you or me?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
Hey Jude
5StarLounger
Posts: 1015
Joined: 24 Jan 2010, 15:45
Location: Ohio, U.S.A.

Re: Add-on to exclude domains from right-click?

Post by Hey Jude »

Mine..I failed to type out the domain name and put the title in there instead...I'll re-try it.
Jelly Bean Key Finder.png
You do not have the required permissions to view the files attached to this post.
Last edited by Hey Jude on 16 Jan 2011, 19:48, edited 1 time in total.
♫...Take a sad song and make it better . . .♫ Image

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

I created a version that uses an iframe to display the results, screenshot attached. But people don't tend to like iframes (myself included).

I excluded the word cheese from my quarter pounder search, but I notice the images include cheese. Still nobody's perfect (meaning Google :evilgrin: ).

(I couldn't prevent the screenshot from appearing within this post.) Andy.
You do not have the required permissions to view the files attached to this post.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
Hey Jude
5StarLounger
Posts: 1015
Joined: 24 Jan 2010, 15:45
Location: Ohio, U.S.A.

Re: Add-on to exclude domains from right-click?

Post by Hey Jude »

Is that better?
♫...Take a sad song and make it better . . .♫ Image

User avatar
Hey Jude
5StarLounger
Posts: 1015
Joined: 24 Jan 2010, 15:45
Location: Ohio, U.S.A.

Re: Add-on to exclude domains from right-click?

Post by Hey Jude »

Loose Meat Sandwiches.png
You do not have the required permissions to view the files attached to this post.
♫...Take a sad song and make it better . . .♫ Image

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Add-on to exclude domains from right-click?

Post by agibsonsw »

That's better although not very appetizing.

I notice you placed a comma after the chicken, (why did the chicken pause, before crossing the road?)

It took me a little while to remove spaces from the words to exclude (having to correct someone's regular expressions!), then I see an unexpected comma. I don't need to change anything but this demonstrates why it's important to 'gently persuade' others to help test your code.

Thinking about Parental Control it occurred to me that a version could be created that hides all the checkboxes, etc., and remembers all the excluded words. If this version were saved in the same location as the main search page (i.e. the same domain) then the cookie information should be available to both pages. Then there could effectively be two versions, one for the parent and one for their little treasure.

Of course, this wouldn't prevent the child typing in the address bar. They could also view the source for the page, but the site list and excluded words wouldn't have to display within the page - they could be read from the cookies at the point of pressing 'Go Search'.

Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.