Power Sensor

sense the words under mouse very quick without selection&web page previewer for which links under mouse.

目前為 2016-01-11 提交的版本,檢視 最新版本

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