|
3 | 3 | // @name:zh-CN 代码片段高亮 |
4 | 4 | // @name:zh-TW 程式碼片斷高亮 |
5 | 5 | // @namespace hoothin |
6 | | -// @version 1.3 |
| 6 | +// @version 1.5 |
7 | 7 | // @description Add a icon to popup a window that allows syntax highlighting and beautify and word count of source code snippets on current page |
8 | 8 | // @description:zh-CN 选择代码片段后点击图标弹出新窗口显示语法高亮美化与格式化后的代码与字数统计 |
9 | 9 | // @description:zh-TW 選擇程式碼片段後點選圖示彈出新視窗顯示語法高亮美化與格式化後的程式碼與字數統計 |
|
22 | 22 | var isChrome=unsafeWindow.chrome; |
23 | 23 | var codeIcon=document.createElement("img"); |
24 | 24 | var codes, selStr, scrollX, scrollY; |
25 | | - codeIcon.style.cssText="position:fixed;z-index:99999;cursor: pointer;"; |
| 25 | + codeIcon.style.cssText="position:fixed;z-index:99999;cursor:pointer;transition:opacity 0.5s ease-in-out 0s;opacity:0;border:5px solid rgba(0, 0, 0, 0.2);border-radius:10px;"; |
26 | 26 | codeIcon.title="Show this code snippet"; |
27 | 27 | codeIcon.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAYAgMAAACD0OXYAAAACVBMVEX7+/swMDBTU1MLxgsCAAAAJElEQVQI12MIBYEAGLUKBBbAqAUMQICgAoAqoBQ95JaCnASjAAgXMdk3d5HTAAAAAElFTkSuQmCC"; |
28 | 28 | codeIcon.onmousedown=function(){ |
|
56 | 56 | }; |
57 | 57 |
|
58 | 58 | document.addEventListener('mousedown', function(o) { |
| 59 | + codeIcon.style.opacity=0; |
59 | 60 | if(codeIcon.parentNode)codeIcon.parentNode.removeChild(codeIcon); |
60 | 61 | }); |
61 | 62 | document.addEventListener('mouseup', function(o) { |
|
68 | 69 | let pos=getMousePos(o); |
69 | 70 | let left, top; |
70 | 71 | if(isChrome){ |
71 | | - top=pos.y>document.documentElement.clientHeight-50?(pos.y-25):(pos.y+15); |
72 | | - left=pos.x>document.documentElement.clientWidth-50?(pos.x-25):(pos.x+15); |
| 72 | + top=pos.y>document.documentElement.clientHeight-50?(pos.y-30):(pos.y+20); |
| 73 | + left=pos.x>document.documentElement.clientWidth-50?(pos.x-30):(pos.x+20); |
73 | 74 | }else{ |
74 | | - top=pos.y-25; |
| 75 | + top=pos.y-30; |
75 | 76 | left=pos.x+15; |
76 | 77 | } |
| 78 | + codeIcon.style.opacity=0.9; |
77 | 79 | codeIcon.style.top=top+"px"; |
78 | 80 | codeIcon.style.left=left+"px"; |
79 | 81 | } |
|
0 commit comments