Power Sensor

sensing words of web pages under mouse very quickly without selection&a web page links previewer

  1. // ==UserScript==
  2. // @name Power Sensor
  3. // @author aldev
  4. // @namespace aldev
  5. // @description sensing words of web pages under mouse very quickly without selection&a web page links previewer
  6. // @description this is a test version,if you like it,please give me ur suggestions or feel free to improve ,just dont forget to update your codes!! thx a lot !
  7. // @version 0.0.0.1
  8. // @homepage https://greasyfork.org/zh-CN/scripts/16115
  9. // @include *
  10. // @grant GM_xmlhttpRequest
  11. // @charset UTF-8
  12. // @run-at document-end
  13. // ==/UserScript==
  14. d=document;
  15. body=d.body;
  16. create=d.createElement;
  17. q=d.querySelector;
  18. qa=d.querySelectorAll;
  19. efp=d.elementFromPoint;
  20. function p(s) {
  21. console.log(s);
  22. }
  23. function _(s) {
  24. return create.call(d,s);
  25. }
  26. function $(s) {
  27. return q.call(d,s);
  28. }
  29. function $$(s) {
  30. return qa.call(d,s);
  31. }
  32. function frome(e) {
  33. return efp.call(d,e.clientX,e.clientY);
  34. }
  35. //el ele
  36. function worde(el) {
  37. texts=el.textContent.split(/\s+/ig);
  38. if(texts.length<2)return;
  39. el.textContent='';
  40. for(i in texts){
  41. w=_('span');
  42. w.textContent=texts[i]+' ';
  43. el.appendChild(w);
  44. }
  45. return el;
  46. }
  47. function word(e) {
  48. if(e.target.id=='c')return;
  49. el=frome(e);
  50. ori_text=el.innerHTML;
  51. worde(el);
  52. el2=frome(e);
  53. text=el2.textContent.replace(/\W+/ig,'');
  54. el.innerHTML=ori_text;
  55. return text;
  56. }
  57.  
  58. function handlejs(js) {
  59. return js.replace(/<img[^<]*?>/ig,'').replace(/<script[^<]*? src=[^<]*?\/>/ig,'').replace(/<script[^`]*?<\/script>/ig,'').replace(/<link[^<]*?>/ig,'');
  60. }
  61. function mov(c,e) {
  62. s=c.style;
  63. s.left=e.clientX+'px';
  64. s.top=e.clientY+'px';
  65. }
  66. function preview(u,e) {
  67. c=$('#c');
  68. GM_xmlhttpRequest( {
  69. method: "GET",
  70. url: u,
  71. onload: function(response) {
  72. c.innerHTML=handlejs(response.responseText);
  73. mov(c,e);
  74. c.style.display='';
  75. setTimeout("c.style.display='none'",5000);
  76. }
  77. });
  78. }
  79. function handlehover() {
  80. as=$$('a');
  81. for (i in as){
  82. as[i].onmouseover=function(e){
  83. preview(e.target.href,e);
  84. }}}
  85. function handleevents() {
  86. //events
  87. body.onmousemove=function(e){
  88. /* text=word(e);
  89. u='http://m.haosou.com/s?q='+text+'&mode=jisu&src=home_input&srcg=home';
  90. preview(u,e); */
  91. };
  92. body.ondblclick=function(e){
  93. $('#c').style.display='none';
  94. };
  95. body.onclick=function(e){
  96. text=word(e);
  97. if(text.length<1)return;
  98. u='http://m.haosou.com/s?q='+text+'&mode=jisu&src=home_input&srcg=home';
  99. preview(u,e);
  100. };
  101. $('#c').ondblclick=function(e){
  102. this.style.display='none';
  103. };
  104. handlehover();
  105. //end events
  106. }
  107. function main() {
  108. console.clear();
  109. console.log("-----------------------begin sensor----------------------");
  110. c=_('div');
  111. c.id='c';
  112. c.style='font:3pt;display:none;top:0px;float:right;width:600px;height:300px;position:fixed;overflow:auto;zIndex:2999999999;background:gray' ;
  113. body.appendChild(c);
  114. handleevents();
  115. console.log("-----------------------end sensor----------------------");
  116. }
  117. //app entrance
  118. main();