forked from ywzhaiqi/userChromeJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findScriptForGreaemonkeyOrScriptish.uc.js
82 lines (76 loc) · 2.37 KB
/
findScriptForGreaemonkeyOrScriptish.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// ==UserScript==
// @name findScriptForGreasemonkeyOrScriptish.uc.js
// @namespace [email protected]
// @description 给 Greasemonkey、Scriptish 添加 "为本站搜索脚本" 功能。
// @include main
// @charset utf-8
// @compatibility Firefox 4.0+
// @author ywzhaiqi
// @version 2013/06/18
// ==/UserScript==
var findScriptForScriptish = {
_id: "Scriptish-find-script",
init: function(){
if(document.getElementById(this._id)){
return;
}
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("id", this._id);
menuitem.setAttribute("label", "为本站搜索脚本(S)");
menuitem.setAttribute("accesskey", "s");
menuitem.setAttribute("oncommand", "findScriptForScriptish.findscripts()");
// Scriptish
var scriptishShow = document.getElementById("scriptish-tb-show-us");
if(scriptishShow){
scriptishShow.parentNode.insertBefore(menuitem, scriptishShow.nextSibling);
scriptishShow.parentNode.insertBefore(
document.createElement("menuseparator"),
scriptishShow.nextSibling
);
}
// Greasemonkey
var GM_popup = document.querySelector("#greasemonkey-tbb menupopup");
if(GM_popup){
GM_popup.insertBefore(menuitem, GM_popup.children[3]);
}
},
getFocusedWindow: function () {
var win = document.commandDispatcher.focusedWindow;
return (!win || win == window) ? content : win;
},
findscripts: function(){
var wins = this.getFocusedWindow();
var href = wins.location.href;
if(!href) return;
var p=0; //for number of "."
var f= new Array();
var q=2;
var t=1;
var a=0;
var y;
var o;
var m=4;
var stringa; //= new Array();
var re = /(?:[a-z0-9-]+\.)+[a-z]{2,4}/;
href=href.match(re); //extract the url part
href=href.toString();
//get the places and nunbers of the "."
for (var i=0;i<href.length;i++){
if (href[i]=="."){
f[p]=i;
p++ ;
}
}
if (p==t){
stringa=href.substring(a,f[0]);
}else if (p==q){
stringa=href.substring(++f[0],f[1]);
}
else {
stringa=href.substring(++f[0],f[2]);
}
//openLinkIn("http://www.google.com/search?btnG=Google+Search&q=site:userscripts.org+inurl:scripts+inurl:show+"+ stringa, "tab", {});
openLinkIn("http://userscripts.org/scripts/search?q="+ stringa + "&submit=Search", "tab", {});
}
};
findScriptForScriptish.init();