Skip to content

Commit 2a92521

Browse files
committed
fix
1 parent 8878e8b commit 2a92521

1 file changed

Lines changed: 54 additions & 55 deletions

File tree

Mouse Gestures/Mouse Gestures.user.js

Lines changed: 54 additions & 55 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.62
6+
// @version 0.63
77
// @description Just a Mouse Gestures
88
// @description:zh-CN 就是个鼠标手势
99
// @description:zh-TW 就是個滑鼠手勢
@@ -19,20 +19,57 @@
1919
// @compatible firefox
2020
// ==/UserScript==
2121

22+
var lastX,lastY,lastSign,afterGestures,gesturesWords,gesturesContent,gestures,signs;
23+
const defaultFun={
24+
close:"unsafeWindow.opener=null;unsafeWindow.open('', '_self', '');unsafeWindow.close();",
25+
openNew:"GM_openInTab('about:newtab', false)",
26+
scrollToTop:"unsafeWindow.scrollTo(0, 0)",
27+
scrollToBottom:"unsafeWindow.scrollTo(0, 1073741824)",
28+
back:"unsafeWindow.history.back()",
29+
forward:"unsafeWindow.history.forward()",
30+
reload:"unsafeWindow.location.reload()"
31+
};
32+
function initEventListener(start,move,end,tracer,clientX,clientY,startBool){
33+
var isMouse=start=="mousedown";
34+
var moveFun=function(e){
35+
tracer(eval(clientX),eval(clientY),isMouse);
36+
gesturesWords.innerHTML=signs;
37+
var gesturesWidth=signs.length*51+40;
38+
gesturesContent.style.width=gesturesWidth+"px";
39+
gesturesContent.style.marginLeft=-gesturesWidth/2+"px";
40+
};
41+
document.addEventListener(start, function(e) {
42+
if(!startBool || eval(startBool)){
43+
lastX=eval(clientX);
44+
lastY=eval(clientY);
45+
lastSign=signs="";
46+
document.addEventListener(move, moveFun, false);
47+
}
48+
}, false);
49+
document.addEventListener(end, function(e) {
50+
document.removeEventListener(move, moveFun, false);
51+
setTimeout(function(){if(gesturesContent.parentNode)gesturesContent.parentNode.removeChild(gesturesContent);},500);
52+
if(afterGestures)afterGestures();
53+
for(var g of gestures){
54+
var gSign=g.gesture;
55+
if(signs==gSign){
56+
if(!isMouse)document.body.appendChild(gesturesContent);
57+
var fun=defaultFun[g.fun];
58+
if(fun===undefined || !fun){
59+
eval(g.fun);
60+
}else eval(fun);
61+
e.stopPropagation();
62+
e.preventDefault();
63+
break;
64+
}
65+
}
66+
}, false);
67+
}
2268
(function() {
2369
'use strict';
24-
var lastX, lastY, signs, lastSign, gestures, i18n;
70+
var i18n;
2571
var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
26-
const minLength=256,tg=0.5,
27-
defaultFun={
28-
close:"unsafeWindow.opener=null;unsafeWindow.open('', '_self', '');unsafeWindow.close();",
29-
openNew:"GM_openInTab('about:newtab', false)",
30-
scrollToTop:"unsafeWindow.scrollTo(0, 0)",
31-
scrollToBottom:"unsafeWindow.scrollTo(0, 1073741824)",
32-
back:"unsafeWindow.history.back()",
33-
forward:"unsafeWindow.history.forward()",
34-
reload:"unsafeWindow.location.reload()"
35-
};
72+
const minLength=256,tg=0.5;
3673
switch (lang){
3774
case "zh-CN":
3875
i18n={
@@ -89,7 +126,7 @@
89126
{gesture:"←↑→",fun:"forward"},
90127
{gesture:"↑↓",fun:"reload"},
91128
{gesture:"↓↑↓",fun:"var t=((unsafeWindow.getSelection&&unsafeWindow.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var e=(document.charset||document.characterSet);if(t!=''){GM_openInTab('http://translate.google.cn/?text='+t+'&hl=zh-CN&langpair=auto|zh-CN&tbb=1&ie='+e,false);}else{GM_openInTab('http://translate.google.cn/translate?u='+encodeURIComponent(location.href)+'&hl=zh-CN&langpair=auto|zh-CN&tbb=1&ie='+e,false);}"},
92-
{gesture:"↓↑↓←",fun:'function R(a){var ona = "on"+a; if(unsafeWindow.addEventListener) unsafeWindow.addEventListener(a, function (e) { for(var n=e.originalTarget; n; n=n.parentNode) n[ona]=null; }, true); unsafeWindow[ona]=null; document[ona]=null; if(document.body) document.body[ona]=null; } R("contextmenu"); R("click"); R("mousedown"); R("mouseup"); R("selectstart");'},
129+
{gesture:"↓↑↓←",fun:'var d=document,b=d.body;with(b.onselectstart=b.oncopy=b.onpaste=b.onkeydown=b.oncontextmenu=b.onmousemove=b.ondragstart=d.oncopy=d.onpaste=null,d.onselectstart=d.oncontextmenu=d.onmousedown=d.onkeydown=function(){return!0},d.wrappedJSObject||d)onmouseup=null,onmousedown=null,oncontextmenu=null;for(var a=d.getElementsByTagName("*"),i=a.length-1;i>=0;i--){var o=a[i];with(o.wrappedJSObject||o)onmouseup=null,onmousedown=null}var h=d.getElementsByTagName("head")[0];if(h){var s=d.createElement("style");s.innerHTML="html,*{-webkit-user-select:text!important;-moz-user-select:text!important;}",h.appendChild(s)}unsafeWindow.Event.prototype.preventDefault=function(){};'},
93130
{gesture:"↓↑↓↑",fun:"var d = document, e = d.getElementById('wappalyzer-container') ; if ( e !== null ) { d.body.removeChild(e); } var u = 'https://wappalyzer.com/bookmarklet/', t = new Date().getTime(), c = d.createElement('div'), p = d.createElement('div'), l = d.createElement('link'), s = d.createElement('script') ; c.setAttribute('id', 'wappalyzer-container'); l.setAttribute('rel', 'stylesheet'); l.setAttribute('href', u + 'css/wappalyzer.css'); d.head.appendChild(l); p.setAttribute('id', 'wappalyzer-pending'); p.setAttribute('style', 'background-image: url(' + u + 'images/pending.gif) !important'); c.appendChild(p); s.setAttribute('src', u + 'js/wappalyzer.js?' + t); s.onload = function() { s = d.createElement('script'); s.setAttribute('src', u + 'js/apps.js?' + t); s.onload = function() { s = d.createElement('script'); s.setAttribute('src', u + 'js/driver.js?' + t); c.appendChild(s); }; c.appendChild(s); }; c.appendChild(s); d.body.appendChild(c);"},
94131
{gesture:"↓↑↓→",fun:"GM_openInTab('http://just998.com/xiu/photo'+unsafeWindow.location.search,false)"}
95132
];
@@ -123,51 +160,13 @@
123160
}
124161
}
125162
}
126-
function initEventListener(start,move,end,clientX,clientY,startBool){
127-
var isMouse=start=="mousedown";
128-
var moveFun=function(e){
129-
tracer(eval(clientX),eval(clientY),isMouse);
130-
gesturesWords.innerHTML=signs;
131-
var gesturesWidth=signs.length*51+40;
132-
gesturesContent.style.width=gesturesWidth+"px";
133-
gesturesContent.style.marginLeft=-gesturesWidth/2+"px";
134-
};
135-
document.addEventListener(start, function(e) {
136-
if(!startBool || eval(startBool)){
137-
lastX=eval(clientX);
138-
lastY=eval(clientY);
139-
lastSign=signs="";
140-
document.addEventListener(move, moveFun, false);
141-
}
142-
}, false);
143-
document.addEventListener(end, function(e) {
144-
document.removeEventListener(move, moveFun, false);
145-
setTimeout(function(){if(gesturesContent.parentNode)gesturesContent.parentNode.removeChild(gesturesContent);},500);
146-
if(afterGestures)afterGestures();
147-
for(var g of gestures){
148-
var gSign=g.gesture;
149-
if(signs==gSign){
150-
if(!isMouse)document.body.appendChild(gesturesContent);
151-
var fun=defaultFun[g.fun];
152-
if(!fun){
153-
eval(g.fun);
154-
}
155-
eval(fun);
156-
e.stopPropagation();
157-
e.preventDefault();
158-
break;
159-
}
160-
}
161-
}, false);
162-
}
163-
initEventListener("touchstart","touchmove","touchend","e.changedTouches[0].clientX","e.changedTouches[0].clientY");
164-
initEventListener("mousedown","mousemove","contextmenu","e.clientX","e.clientY","e.which === 3");
165-
var afterGestures;
166-
var gesturesContent=document.createElement("div");
163+
gesturesContent=document.createElement("div");
167164
gesturesContent.id="gesturesContent";
168165
gesturesContent.style.cssText="width:300px;height:70px;position:fixed;left:50%;top:50%;margin-top:-25px;margin-left:-150px;z-index:999999999;background-color:#000;border:1px solid;border-radius:10px;opacity:0.65;filter:alpha(opacity=65);box-shadow:5px 5px 20px 0px #000;";
169166
gesturesContent.innerHTML='<div id="gesturesWords" style="position:absolute;left:20px;top:5px;font:bold 50px \'黑体\';color:#ffffff"></div>';
170-
var gesturesWords=gesturesContent.querySelector("#gesturesWords");
167+
gesturesWords=gesturesContent.querySelector("#gesturesWords");
168+
initEventListener("touchstart","touchmove","touchend",tracer,"e.changedTouches[0].clientX","e.changedTouches[0].clientY");
169+
initEventListener("mousedown","mousemove","contextmenu",tracer,"e.clientX","e.clientY","e.which === 3");
171170
if(location.href=="https://github.com/hoothin/UserScripts/tree/master/Mouse%20Gestures"){
172171
var entryContent=document.querySelector("article.entry-content"),mobile=false;
173172
if(!entryContent){

0 commit comments

Comments
 (0)