Wowhead Search Colloquy Plugin


/ Published in: AppleScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. -- Wowhead Search Plugin
  2. -- This Colloquy plugin searches Wowhead (wowhead.com). Type "/wh" or "/wowhead"
  3. -- followed by a search string to open a Wowhead search in your default browser. To
  4. -- share your search with the channel, use "/wha" or "/wowheadalt"!
  5.  
  6. -- by Raws (rosspaffett.com) on 21 Oct 2007
  7.  
  8. property wowheadSearchURL : "http://wowhead.com/?search=%s"
  9.  
  10. using terms from application "Colloquy"
  11. on process user command cmd with args for view
  12. if cmd is in {"wowhead", "wh"} then
  13. set queryString to args
  14. set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
  15. open location queryURL
  16. else if cmd is in {"wowheadalt", "wha"} then
  17. set queryString to args
  18. set queryURL to encodeURL(replaceString(wowheadSearchURL, "%s", args), false, false)
  19. tell view to send message "searches for \"" & queryString & ¬
  20. "\": " & queryURL with action tense
  21. end if
  22. end process user command
  23. end using terms from
  24.  
  25. -- Standard string and URL processing subroutines
  26. -- These subroutines have been slightly modified from those provided
  27. -- by Apple at the following site: http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.01.htm
  28.  
  29. on replaceString(haystack, needle, replacement)
  30. set AppleScript's text item delimiters to the needle
  31. set the item_list to every text item of haystack
  32. set AppleScript's text item delimiters to the replacement
  33. set haystack to the item_list as string
  34. set AppleScript's text item delimiters to ""
  35. return haystack
  36. end replaceString
  37.  
  38. on encodeURL(this_text, encode_URL_A, encode_URL_B)
  39. set the standard_characters to ¬
  40. "abcdefghijklmnopqrstuvwxyz0123456789"
  41. set the URL_A_chars to "$+!'/?;&@=#%><{}[]\"~`^\\|*"
  42. set the URL_B_chars to ".-_:"
  43. set the acceptable_characters to the standard_characters
  44. if encode_URL_A is false then ¬
  45. set the acceptable_characters to ¬
  46. the acceptable_characters & the URL_A_chars
  47. if encode_URL_B is false then ¬
  48. set the acceptable_characters to ¬
  49. the acceptable_characters & the URL_B_chars
  50. set the encoded_text to ""
  51. repeat with this_char in this_text
  52. if this_char is in the acceptable_characters then
  53. set the encoded_text to ¬
  54. (the encoded_text & this_char)
  55. else
  56. set the encoded_text to ¬
  57. (the encoded_text & encodeChar(this_char)) as string
  58. end if
  59. end repeat
  60. return the encoded_text
  61. end encodeURL
  62.  
  63. on encodeChar(this_char)
  64. if this_char as string is " " then
  65. return "+"
  66. else
  67. set the ASCII_num to (the ASCII number this_char)
  68. set the hex_list to ¬
  69. {"0", "1", "2", "3", "4", "5", "6", "7", "8", ¬
  70. "9", "A", "B", "C", "D", "E", "F"}
  71. set x to item ((ASCII_num div 16) + 1) of the hex_list
  72. set y to item ((ASCII_num mod 16) + 1) of the hex_list
  73. return ("%" & x & y) as string
  74. end if
  75. end encodeChar

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.