modified: pixi.toml
[GalaxyCodeBases.git] / etc / userscripts / CleanHide.js
blob8644b47069080e45c209c68b620174286193996b
1 // ==UserScript==
2 // @name CleanHide
3 // @namespace http://notebk.spaces.live.com/
4 // @description Created By Inorth,mod by cwjt
5 // @run-at document-start
6 // @include http://*
7 // ==/UserScript==
9 // http://userscripts.org/scripts/show/84230
10 // Script Summary:
11 // 清除隐藏文字的脚本,方便拷贝一些经过特别处理过的网页文字,快捷键alt+q http://bbs.chromi.org/thread-6554-1-1.html
13 var debug=false; //debug or release switch!!
14 var CleanHideObj=new CleanHideClass();
15 function CleanHideClass()
17 //functions;id mean cleanhid ,AppID mean call from firefox or mozilla (different! call from overlayFF or overlayMZ!)
18 this.on=function(id,bMZ)
20 //this.strBundle = document.getElementById("cleanhide-strings"); //get the strings use in js!
21 if(id == 0)
23 var page=/* document.getElementById("content").contentDocument */document; //main page
24 this.RemoveHide(page,"span");
25 this.RemoveHide(page,"font");
26 this.RemoveHide(page,"div");
27 this.RemoveHide(page,"p");
28 //alert(this.strBundle.getString("CleanHideSuccess"));
29 //document.getElementById("statusbar-display").label=this.strBundle.getString("CleanHideSuccess");
33 this.getobjstyle=function(node,prop)
35 try
37 return node.ownerDocument.defaultView.getComputedStyle(node, "").getPropertyValue(prop);
39 catch(e)
41 if(debug)
43 alert(e.message);
46 return "200";
50 this.RemoveHide=function(page,objname)
52 try
54 var minValue=25;
55 var objs=page.getElementsByTagName(objname); //get all element
57 if(objs.length == 0) //no span or font object found!
59 if(debug)
61 alert("no object found!:"+objname);
64 else
66 //determean every object!
67 for(var i=objs.length-1;i>=0;i--) //must from last to first!!! for detect every element!!
69 var node=objs.item(i); //get one element
71 //if this object is invisible,we delete it!!
72 if(this.getobjstyle(node,"display") == "none" ||
73 this.getobjstyle(node,"visibility") =="hidden" ||
74 parseInt(this.getobjstyle(node,"font-size")) == 0) //if this element'style is none,than remove it!!
76 if(debug)
78 alert("remove invisiable!");
80 node.parentNode.removeChild(node);
83 else //normal object!have color!
85 if(node.parentNode) //if it has parent node!!
87 var orgNode=node;
88 var orgColor=this.getobjstyle(orgNode,"color");
89 var orgRGB=getRGB(orgColor); //get org node's RGB only color.
90 var parentNode=node.parentNode
91 var parentBgColor=this.getobjstyle(parentNode,"background-color");
95 var isLast=false;
96 regtest=/rgba\((\s)*0,(\s)*0,(\s)*0,(\s)*0\)/;
97 while(regtest.test(parentBgColor)) //parent bg is transparent!!,get last no transparent node!!
100 if(parentNode.parentNode == null)
102 isLast=true;
103 break;
105 parentNode=parentNode.parentNode;
106 parentBgColor=this.getobjstyle(parentNode,"background-color");
107 parentBgColor=parentBgColor+"";
108 if(!regtest.test(parentBgColor))
111 break;
114 if(isLast) //body is RGB(255,255,255)!!!
116 if(debug)
118 alert("last!!");
120 if((Math.abs(orgRGB[0]-255)<=minValue)&&(Math.abs(orgRGB[1]-255)<=minValue)&&(Math.abs(orgRGB[2]-255)<=minValue))
122 orgNode.parentNode.removeChild(orgNode); //color is near white,we delete it!
125 else
127 if(debug)
129 alert("compare color and parent bgcolor!");
131 parentBgRGB=getRGB(parentBgColor);
132 if((Math.abs(orgRGB[0]-parentBgRGB[0])<=minValue)&&(Math.abs(orgRGB[1]-parentBgRGB[1])<=minValue)&&(Math.abs(orgRGB[2]-parentBgRGB[2])<=minValue))
134 orgNode.parentNode.removeChild(orgNode); //color is near white,we delete it!
137 }//end of hava parent
138 }//if invisible
139 }//for ... every object
140 }//object lentgth == 0
142 //find sub frames
143 var itemFrames = page.getElementsByTagName("frame");
144 var itemiFrames = page.getElementsByTagName("iframe");
146 var frame, iframe;
147 if (itemFrames.length > 0)
149 for (var i = 0 ; i< itemFrames.length ; i++)
151 frame = itemFrames[i].contentDocument;
152 this.RemoveHide(frame,objname); // recursion for frames
155 if (itemiFrames.length > 0)
157 for (var i = 0 ; i < itemiFrames.length ; i++)
159 iframe = itemiFrames[i].contentDocument;
160 this.RemoveHide(iframe,objname); // recursion for iframes
164 catch(e)
166 if(debug)
168 alert(e.message);
174 //this function for get R G B data from string rgb(r,g,b) or blue,etc
178 function getRGB(colorString)
180 var RGB = new Array;
181 var tempSting=colorString.substring(4,colorString.length-1);
182 var tempArray=tempSting.split(",");
184 RGB[0]=parseInt(tempArray[0]);
185 RGB[1]=parseInt(tempArray[1]);
186 RGB[2]=parseInt(tempArray[2]);
188 return RGB;
190 function keys(evt)
191 { //var evt=evt?evt:(window.event?window.event:null);
193 if(evt.keyCode == 81 && !evt.shiftKey && !evt.ctrlKey && evt.altKey)
195 CleanHideObj.on(0,1);
196 alert("Clean Hide successfully! Remember Hotkeys: ALT+Q");
200 document.addEventListener('keydown', keys, false);