Skip to content

Commit

Permalink
tieba 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lkytal committed Nov 15, 2014
1 parent 36d8024 commit ac9423b
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 354 deletions.
2 changes: 1 addition & 1 deletion meta/select.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// @author lkytal
// @homepage http://lkytal.github.io/
// @icon http://lkytal.qiniudn.com/ic.ico
// @version 1.0.2
// @version 1.1.0
// @description Select like opera
// @include *
// @grant unsafeWindow
Expand Down
4 changes: 2 additions & 2 deletions meta/tieba_enhance.meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// @name Tieba Enhance
// @namespace lkytal
// @author lkytal
// @description 贴吧小尾巴, 坟贴提醒, 去除跳转, 最近表情等功能
// @description 贴吧小尾巴, 坟贴提醒, 去除跳转等功能
// @include http://tieba.baidu.com/*
// @include https://tieba.baidu.com/*
// @version 5.9.7
// @version 6.0.0
// @author lkytal
// @require http://code.jquery.com/jquery-2.1.1.min.js
// @icon http://lkytal.qiniudn.com/ic.ico
Expand Down
58 changes: 29 additions & 29 deletions select.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// @author lkytal
// @homepage http://lkytal.github.io/
// @icon http://lkytal.qiniudn.com/ic.ico
// @version 1.0.2
// @version 1.1.0
// @description Select like opera
// @include *
// @grant unsafeWindow
Expand All @@ -16,24 +16,24 @@
// ==/UserScript==

selectLikeOpera = function() {
var f = function(a) {
var findHTMLAchor = function(a) {
if (a.nodeType === 3) a = a.parentNode;
do {
if (a.constructor === HTMLAnchorElement) return a;
} while ((a = a.parentNode) && a !== document.body);
return null;
};

var g = function(e) {
var preventEvent = function(e) {
e.preventDefault();
e.stopPropagation();
return false;
};

var h = (function() {
var rangeOperator = (function() {
var w = typeof InstallTrigger === 'undefined';
return {
qq: function(x, y) {
createRange: function(x, y) {
if (w) {
return document.caretRangeFromPoint(x, y)
}
Expand All @@ -44,15 +44,15 @@ selectLikeOpera = function() {
a.setStart(p.offsetNode, p.offset);
return a;
}
return null
return null;
},
qr: ((w ? '-webkit-' : '-moz-') + 'user-select')
rangeAttr: ((w ? '-webkit-' : '-moz-') + 'user-select')
}
})();

var j = (function() {
var o = [{
p: h.qr,
p: rangeOperator.rangeAttr,
v: 'text'
}, {
p: 'outline-width',
Expand All @@ -79,19 +79,19 @@ selectLikeOpera = function() {
}
})();

var toggleEvent = function(a, b) {
if (b === undefined) b = true;
if (a.constructor !== Array) a = [a];
var toggleEvent = function(events, bAdd) {
if (bAdd === undefined) bAdd = true;
if (events.constructor !== Array) events = [events];

for (var i = 0, len = a.length; i < len; i += 1)
for (var i = 0, len = events.length; i < len; i += 1)
{
if (b)
if (bAdd)
{
document.addEventListener(a[i], E[a[i]], true);
document.addEventListener(events[i], eventList[events[i]], true);
}
else
{
document.removeEventListener(a[i], E[a[i]], true);
document.removeEventListener(events[i], eventList[events[i]], true);
}
}
};
Expand All @@ -105,23 +105,23 @@ selectLikeOpera = function() {
u = z = false;
};

var B, s = document.getSelection();
var B, selected = document.getSelection();

selectEvent = function(e) {
if (e.which < 2) {
A();
var x = e.clientX,
y = e.clientY;
if (s.rangeCount > 0) {
var a = s.getRangeAt(0);
if (selected.rangeCount > 0) {
var a = selected.getRangeAt(0);
if (!a.collapsed) {
var r = h.qq(x, y);
var r = rangeOperator.createRange(x, y);
if (r && a.isPointInRange(r.startContainer, r.startOffset)) return;
}
}
j();
var t = e.target,
n = f(t);
n = findHTMLAchor(t);
if (!n) n = t.nodeType !== 3 ? t : t.parentNode;
if (n.constructor === HTMLCanvasElement || n.textContent === '') return;
var r = n.getBoundingClientRect();
Expand All @@ -142,15 +142,15 @@ selectLikeOpera = function() {

var D = 3,
K = 0.8,
E = {
eventList = {
'mousemove': function(e) {
if (B) {
if (B.c++ < 12) {
var r = B.n.getBoundingClientRect();
if (Math.round(r.left) !== B.x || Math.round(r.top) !== B.y) {
removeEvent(['mousemove', 'mouseup', 'dragend', 'dragstart', 'click']);
j();
s.removeAllRanges();
selected.removeAllRanges();
return;
}
} else {
Expand All @@ -160,11 +160,11 @@ selectLikeOpera = function() {
var x = e.clientX,
y = e.clientY;
if (v) {
s.removeAllRanges();
selected.removeAllRanges();
var a = x > m.x ? -2 : 2;
var b = h.qq(x + a, y);
var b = rangeOperator.createRange(x + a, y);
if (b) {
s.addRange(b);
selected.addRange(b);
v = false;
}
}
Expand All @@ -179,13 +179,13 @@ selectLikeOpera = function() {
}
}
if (u) {
var b = h.qq(x, y);
if (b) s.extend(b.startContainer, b.startOffset);
var b = rangeOperator.createRange(x, y);
if (b) selected.extend(b.startContainer, b.startOffset);
}
},
'dragstart': function(e) {
removeEvent('dragstart');
if (u) return g(e);
if (u) return preventEvent(e);
},
'mouseup': function(e) {
removeEvent(['mousemove', 'mouseup', 'dragstart', 'dragend']);
Expand All @@ -199,7 +199,7 @@ selectLikeOpera = function() {
},
'click': function(e) {
removeEvent('click');
if (z) return g(e);
if (z) return preventEvent(e);
}
};

Expand Down
Loading

0 comments on commit ac9423b

Please sign in to comment.