Search Selected text on Amazon .com

Im Mahi, and this script helps people to select and seacrh a product by name without having to download any new extension.

目前为 2018-01-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @description Im Mahi, and this script helps people to select and seacrh a product by name without having to download any new extension.
  3. // @name Search Selected text on Amazon .com
  4. // @copyright Mahi Balan M | RCA | VBI
  5. // @version 1.0
  6. // @website https://phonetool.amazon.com/users/mahibala
  7. // @namespace *
  8. // @include *
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js
  10. // ==/UserScript==
  11. // ==/UserScript==
  12. $(document).ready(function(){
  13. $("body").mouseup(function(e){
  14. // get selected text
  15. var seltext = getSelectedText();
  16. if(seltext != "")
  17. {
  18. if($(".searchit").attr("class") == null)
  19. {
  20. $("<a></a>").appendTo("body")
  21. .attr("title","Search Product on Amazon.com")
  22. .attr("class","searchit")
  23. .css("width","24px")
  24. .css("height","24px")
  25. .css("background-image","url(http://lh4.ggpht.com/_9NnLYMRJob8/TQ9GrnFaweI/AAAAAAAAAVc/f4UtNPKEMUU/find.png)")
  26. .css("display","inline")
  27. .css("background-position","0px 0px")
  28. .attr("href","https://www.amazon.com/s?ie=UTF8&field-keywords="+seltext)
  29. .attr("target","_blank")
  30. .css("left",e.pageX - 5)
  31. .css("top",e.pageY - 30)
  32. .css("display","block")
  33. .css("position","absolute")
  34. .hide()
  35. .fadeIn("very very fast");
  36. }
  37. else{
  38. $(".searchit").animate({"left": e.pageX - 2,"top" : e.pageY - 30}, "very very fast")
  39. .attr("href","https://www.amazon.com/s?ie=UTF8&field-keywords="+seltext).fadeIn("very very fast");
  40. }
  41. }
  42. else
  43. $(".searchit").fadeOut("very very fast");
  44. });
  45. $(".searchit").mouseover(function(){
  46. alert("asa");
  47. });
  48. });
  49. function getSelectedText()
  50. {
  51. // For Firefox
  52. if(window.getSelection)
  53. return window.getSelection();
  54. else if(document.getSelection)
  55. return document.getSelection();
  56. else
  57. {
  58. // For IE
  59. var selection = document.selection && document.selection.createRange();
  60. if(selection.text)
  61. return selection.text;
  62. return false;
  63. }
  64. return false;
  65. }