Return to Snippet

Revision: 4086
at November 25, 2007 12:04 by raws


Updated Code
-- Wowhead Search Plugin
-- This Colloquy plugin searches Wowhead (wowhead.com). Type "/wh" or "/wowhead"
--  followed by a search string to open a Wowhead search in your default browser. To
--  share your search with the channel, use "/wha" or "/wowheadalt"!

-- by Raws (rosspaffett.com) on 21 Oct 2007

property wowheadSearchURL : "http://wowhead.com/?search=%s"

using terms from application "Colloquy"
	on process user command cmd with args for view
		if cmd is in {"wowhead", "wh"} then
			set queryString to args
			set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
			open location queryURL
		else if cmd is in {"wowheadalt", "wha"} then
			set queryString to args
			set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
			tell view to send message "searches for \"" & queryString & ¬
				"\": " & queryURL with action tense
		end if
	end process user command
end using terms from

-- Standard string and URL processing subroutines
-- These subroutines have been slightly modified from those provided
--   by Apple at the following site: http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.01.htm

on replaceString(haystack, needle, replacement)
	set AppleScript's text item delimiters to the needle
	set the item_list to every text item of haystack
	set AppleScript's text item delimiters to the replacement
	set haystack to the item_list as string
	set AppleScript's text item delimiters to ""
	return haystack
end replaceString

on encodeURL(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to ¬
		"abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to ¬
				(the encoded_text & this_char)
		else
			set the encoded_text to ¬
				(the encoded_text & encodeChar(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encodeURL

on encodeChar(this_char)
	if this_char as string is " " then
		return "+"
	else
		set the ASCII_num to (the ASCII number this_char)
		set the hex_list to ¬
			{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
				"9", "A", "B", "C", "D", "E", "F"}
		set x to item ((ASCII_num div 16) + 1) of the hex_list
		set y to item ((ASCII_num mod 16) + 1) of the hex_list
		return ("%" & x & y) as string
	end if
end encodeChar

Revision: 4085
at October 22, 2007 00:47 by raws


Updated Code
-- Wowhead Search Plugin
-- This Colloquy plugin searches Wowhead (wowhead.com). Type "/wh" or "/wowhead"
--  followed by a search string to open a Wowhead search in your default browser. To
--  share your search with the channel, use "/wha" or "/wowheadalt"!

-- by Raws (rosspaffett.com) on 21 Oct 2007

property wowheadSearchURL : "http://wowhead.com/?search=%s"

using terms from application "Colloquy"
	on process user command cmd with args for view
		if cmd is "wowhead" or cmd is "wh" then
			set queryString to args
			set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
			open location queryURL
		else if cmd is "wowheadalt" or cmd is "wha" then
			set queryString to args
			set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
			tell view to send message "searches for \"" & queryString & ¬
				"\": " & queryURL with action tense
		end if
	end process user command
end using terms from

-- Standard string and URL processing subroutines
-- These subroutines have been slightly modified from those provided
--   by Apple at the following site: http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.01.htm

on replaceString(haystack, needle, replacement)
	set AppleScript's text item delimiters to the needle
	set the item_list to every text item of haystack
	set AppleScript's text item delimiters to the replacement
	set haystack to the item_list as string
	set AppleScript's text item delimiters to ""
	return haystack
end replaceString

on encodeURL(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to ¬
		"abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to ¬
				(the encoded_text & this_char)
		else
			set the encoded_text to ¬
				(the encoded_text & encodeChar(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encodeURL

on encodeChar(this_char)
	if this_char as string is " " then
		return "+"
	else
		set the ASCII_num to (the ASCII number this_char)
		set the hex_list to ¬
			{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
				"9", "A", "B", "C", "D", "E", "F"}
		set x to item ((ASCII_num div 16) + 1) of the hex_list
		set y to item ((ASCII_num mod 16) + 1) of the hex_list
		return ("%" & x & y) as string
	end if
end encodeChar

Revision: 4084
at October 22, 2007 00:45 by raws


Updated Code
-- Wowhead Search Plugin
-- This Colloquy plugin searches Wowhead (wowhead.com). Type "/wh" or "/wowhead"
--   followed by a search string to open a Wowhead search in your default browser. To
--  share your search with the channel, use "/wha" or "/wowheadalt"!

-- by Raws (rosspaffett.com) on 21 Oct 2007

property wowheadSearchURL : "http://wowhead.com/?search=%s"

using terms from application "Colloquy"
	on process user command cmd with args for view
		if cmd is "wowhead" or cmd is "wh" then
			set queryString to args
			set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
			open location queryURL
		else if cmd is "wowheadalt" or cmd is "wha" then
			set queryString to args
			set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
			tell view to send message "searches for \"" & queryString & ¬
				"\": " & queryURL with action tense
		end if
	end process user command
end using terms from

-- Standard string and URL processing subroutines
-- These subroutines have been slightly modified from those provided
--   by Apple at the following site: http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.01.htm

on replaceString(haystack, needle, replacement)
	set AppleScript's text item delimiters to the needle
	set the item_list to every text item of haystack
	set AppleScript's text item delimiters to the replacement
	set haystack to the item_list as string
	set AppleScript's text item delimiters to ""
	return haystack
end replaceString

on encodeURL(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to ¬
		"abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to ¬
				(the encoded_text & this_char)
		else
			set the encoded_text to ¬
				(the encoded_text & encodeChar(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encodeURL

on encodeChar(this_char)
	if this_char as string is " " then
		return "+"
	else
		set the ASCII_num to (the ASCII number this_char)
		set the hex_list to ¬
			{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
				"9", "A", "B", "C", "D", "E", "F"}
		set x to item ((ASCII_num div 16) + 1) of the hex_list
		set y to item ((ASCII_num mod 16) + 1) of the hex_list
		return ("%" & x & y) as string
	end if
end encodeChar

Revision: 4083
at October 21, 2007 23:40 by raws


Initial Code
-- Wowhead Search Plugin
-- This Colloquy plugin searches Wowhead (wowhead.com). Type "/wh" or "/wowhead"
--   followed by a search string to open a Wowhead search in your default browser.

-- by Raws (rosspaffett.com) on 21 Oct 2007

property wowheadSearchURL : "http://wowhead.com/?search=%s"

using terms from application "Colloquy"
	on process user command cmd with args for view
		if cmd starts with "wowhead" or cmd starts with "wh" then
			set queryString to args
			set queryURL to replaceString(wowheadSearchURL, "%s", args)
			open location encodeURL(queryURL, false, false)
		end if
	end process user command
end using terms from

-- Standard string and URL processing subroutines
-- These subroutines have been slightly modified from those provided
--   by Apple at the following site: http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.01.htm

on replaceString(haystack, needle, replacement)
	set AppleScript's text item delimiters to the needle
	set the item_list to every text item of haystack
	set AppleScript's text item delimiters to the replacement
	set haystack to the item_list as string
	set AppleScript's text item delimiters to ""
	return haystack
end replaceString

on encodeURL(this_text, encode_URL_A, encode_URL_B)
	set the standard_characters to ¬
		"abcdefghijklmnopqrstuvwxyz0123456789"
	set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
	set the URL_B_chars to ".-_:"
	set the acceptable_characters to the standard_characters
	if encode_URL_A is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_A_chars
	if encode_URL_B is false then ¬
		set the acceptable_characters to ¬
			the acceptable_characters & the URL_B_chars
	set the encoded_text to ""
	repeat with this_char in this_text
		if this_char is in the acceptable_characters then
			set the encoded_text to ¬
				(the encoded_text & this_char)
		else
			set the encoded_text to ¬
				(the encoded_text & encodeChar(this_char)) as string
		end if
	end repeat
	return the encoded_text
end encodeURL

on encodeChar(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to ¬
		{"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
			"9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encodeChar

Initial URL


Initial Description


Initial Title
Wowhead Search Colloquy Plugin

Initial Tags


Initial Language
AppleScript