// ==UserScript==
// @name 万能页内选中搜索【失效联系作者24小时更新】
// @namespace http://tampermonkey.net/
// @version 1.0.2
// @description 任何页面选中以后都可以快捷搜索,实现不跳出网页浏览进行搜索,目前支持必应搜索。
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @author 蜡小新
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=greasyfork.org
// @grant none
// @license MIT
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
var content = "";
$("body").bind('mouseup', function(e) {
processSelection(e);
});
function processSelection(e) {
var text = getSelectedText();
if (!!text && text != "" && text.length != 0) {
showBubble(e, text);
} else {
hideBubble();
}
}
function getSelectedText() {
var text = "";
if (window.getSelection) {
text = window.getSelection()
.toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange()
.text;
}
return text;
}
function showBubble(e, text) {
content = text;
if($('#any-searcher-bubble').length == 0) {
$("body").append("
点我页内搜索
");
$("#any-searcher-bubble").click(function(e) {
if($("#any-searcher-iframe-container").length ==0) {
$("body").append(""+
"
X
"+
"
Reset
"+
"
Left
"+
"
Right
"+
"
");
$("#any-searcher-iframe-x").click(function(e){
$("#any-searcher-iframe-container").hide();
});
$("#any-searcher-iframe-reset").click(function(e){
$('#any-searcher-iframe').attr('src', $('#any-searcher-iframe').attr('src'));
});
$("#any-searcher-iframe-left").click(function(e){
$('#any-searcher-iframe-container').hide();
$('#any-searcher-iframe-container').css('left',"10px");
$('#any-searcher-iframe-container').show();
});
$("#any-searcher-iframe-right").click(function(e){
$('#any-searcher-iframe-container').hide();
$('#any-searcher-iframe-container').css('right',"10px");
$('#any-searcher-iframe-container').css('left',"");
$('#any-searcher-iframe-container').show();
});
$('#any-searcher-iframe-container').css('left',"10px");
}
$('#any-searcher-iframe-container').css('top', e.pageY - 40 + "px");
$('#any-searcher-iframe-container').show();
e.stopPropagation();
});
}
$('#any-searcher-bubble').css('top', e.pageY - 40 + "px");
$('#any-searcher-bubble').css('left', e.pageX + 20 + "px");
$('#any-searcher-bubble').show();
}
function hideBubble() {
$('#any-searcher-bubble').hide();
}
function makeASelf(){
var elements = $("a");
for(var i = 0 ; i < elements.length; i++) {
$(elements[i]).attr("target","_self")
}
}
window.setInterval(makeASelf, 500);
})();