Skip to content

Commit e9976ef

Browse files
committed
fix
1 parent c99d228 commit e9976ef

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Highlight Every Code/Highlight Every Code.user.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN 代码片段高亮
44
// @name:zh-TW 程式碼片斷高亮
55
// @namespace hoothin
6-
// @version 0.81
6+
// @version 1.0
77
// @description Add a icon to popup a window that allows syntax highlighting and beautify and word count of source code snippets on current page
88
// @description:zh-CN 选择代码片段后点击图标弹出新窗口显示高亮美化与格式化后的代码与字数统计
99
// @description:zh-TW 選擇程式碼片段後點選圖示彈出新視窗顯示高亮美化與格式化後的程式碼與字數統計
@@ -20,7 +20,7 @@
2020
'use strict';
2121
var isChrome=unsafeWindow.chrome;
2222
var codeIcon=document.createElement("img");
23-
var codes, scrollX, scrollY;
23+
var codes, selStr, scrollX, scrollY;
2424
codeIcon.style.cssText="position:fixed;z-index:99999;display:none;cursor: pointer;";
2525
codeIcon.title="Show this code snippet";
2626
codeIcon.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAYAgMAAACD0OXYAAAACVBMVEX7+/swMDBTU1MLxgsCAAAAJElEQVQI12MIBYEAGLUKBBbAqAUMQICgAoAqoBQ95JaCnASjAAgXMdk3d5HTAAAAAElFTkSuQmCC";
@@ -35,7 +35,7 @@
3535
'Code formatting: <a href="#" onclick="code.innerHTML=js_beautify(codeStr.replace(/&amp;lt;/g, \'&lt;\').replace(/&amp;gt;/g, \'&gt;\'));code.className=\'prettyprint linenums\';prettyPrint();return false;">Javaspcript</a> '+
3636
'<a href="#" onclick="code.innerHTML=html_beautify(codeStr);code.className=\'prettyprint linenums\';prettyPrint();return false;">Html</a> '+
3737
'<a href="#" onclick="code.innerHTML=css_beautify(codeStr);code.className=\'prettyprint linenums\';prettyPrint();return false;">Css</a> '+
38-
'<a href="#" onclick="code.innerHTML=codeStr;code.className=\'prettyprint linenums\';prettyPrint();return false;">Raw</a> <b style="color:red">('+codes.length+' words)</b>'+
38+
'<a href="#" onclick="code.innerHTML=codeStr;code.className=\'prettyprint linenums\';prettyPrint();return false;">Raw</a> <b style="color:red">('+selStr.length+' words)</b>'+
3939
'<pre id="code" class="prettyprint linenums" style="word-wrap: break-word; white-space: pre-wrap;border: 1px solid rgb(136, 136, 204);border-radius: 8px;">' + codes + "</pre>";
4040
if(isChrome){
4141
let c = window.open("", "_blank", "width=750, height=400, location=0, resizable=1, menubar=0, scrollbars=0");
@@ -52,7 +52,8 @@
5252
document.addEventListener('mouseup', function(o) {
5353
if (o.button === 0 && (o.ctrlKey || o.altKey || o.metaKey || o.shiftKey)) {
5454
setTimeout(function(){
55-
codes = document.getSelection().toString().replace(/&/g, "&amp;").replace(/\</g,"&lt;").replace(/\>/g,"&gt;");
55+
selStr=document.getSelection().toString();
56+
codes=selStr.replace(/&/g, "&amp;").replace(/\</g,"&lt;").replace(/\>/g,"&gt;");
5657
if(codes){
5758
codeIcon.style.display="block";
5859
let pos=getMousePos(o);

0 commit comments

Comments
 (0)