📄 css3selector.js
字号:
window.$ = function (){
var doc = [document];
var uid = 1;
var cache = {};
{
var REGEXP_0 = /^(\s)*([\)\*,\+>~]?)\s*([\[\.\:#]?)\s*([\w\u0080-\u00FFF_\-]*)/;
var REGEXP_1 = /^(?:\s*(\S?\=)\s*(?:([\+\-\d\.]+)|(\w+)|"((?:[^"]|`")*)"))?\s*\]/;
var NAME_MAP = {'name':'name', 'tagName':'tagName', 'id':'#'};
var VALUE_MAP = {'true':true, 'false':false, 'null':null, 'undefined':undefined};
function parse(src){
var tmp;
var token = [];
var sequence = [];
var chain = [sequence];
var group = [chain];
sequence.combinator = ' ';
while (src && src != ''){
if (REGEXP_0.test(src)){
src = RegExp.rightContext;
tmp = RegExp.$1 || RegExp.$2;
if (tmp){
if (tmp == ','){
sequence = [];
sequence.combinator = ' ';
chain = [sequence];
group.push(chain);
} else if (tmp == '*'){
} else if (tmp == ')'){
} else {
sequence = [];
sequence.combinator = tmp;
chain.push(sequence);
}
}
if (tmp = RegExp.$3 || RegExp.$4){
token.name = RegExp.$3 ? tmp : 'tagName';
if (tmp == ':'){
tmp = RegExp.$4;
if (tmp == 'not' || tmp == 'has'){
src = src.substring(1);
sequence = [];
sequence.combinator = tmp;
chain.push(sequence);
continue;
}
token.name = tmp;
if (/^\(([^\)]*)\)/.test(src)){
src = RegExp.rightContext;
tmp = RegExp.$1;
token.push(tmp);
}
} else if (tmp == '['){
tmp = RegExp.$4;
if (tmp == 'class'){
tmp = 'className';
}
token.push(tmp);
if (REGEXP_1.test(src)){
src = RegExp.rightContext;
if (tmp = RegExp.$1){
if (tmp === '=' && (tmp = NAME_MAP[token[0]])){
token.name = tmp;
token.length = 0;
} else if (tmp === '~=' && token[0] === 'className') {
token.name = '.';
token.length = 0;
} else {
token.name = RegExp.$1;
}
if (tmp = RegExp.$2){
tmp = Number(tmp);
} else if (tmp = RegExp.$3){
tmp = VALUE_MAP[tmp] || tmp;
} else if (tmp = RegExp.$4) {
tmp = tmp.replace(/`(`*")/g, '$1');
} else throw '';
token.push(tmp);
} else {
}
} else throw '';
} else {
token.push(RegExp.$4);
}
sequence.push(token);
token = [];
} else {
}
} else throw '';
}
return group;
}
function build(src){
return parse(src);
}
}
{
function SearchFunction(){
this.ovars = {};
this.tests = [];
this.ovlen = 0;
}
SearchFunction.prototype.setTemplate = function (template){
this.template = template;
};
SearchFunction.prototype.addArg = function (name, value){
if (!value) {
value = name;
name = 'P'+this.ovlen;
this.ovlen ++;
}
this.ovars[name] = value;
return name;
};
SearchFunction.prototype.addCon = function (condition){
this.tests.push('('+condition+')');
};
SearchFunction.prototype.compile = function (){
var fn;
fn = this.template.toString();
var condition = this.tests.length <= 0 ? 'true' : this.tests.join('&&');
fn = fn.replace(/\$CONDITION\$/g, condition);
with (this.ovars){
return eval('fn='+fn);
}
};
}
{
var $CONDITION$;
var byTagName = function (ret){
var hash = ret.hash = ret.hash || {};
var checkedhash = {};
var node;
var nodes;
for (var i=0; i<this.length; i++){
node = this[i];
node.uid = node.uid || uid++;
//if (node.uid in checkedhash){
// continue;
//} else {
// checkedhash[node.uid] = 1;
//}
nodes = node.uid + tagName;
nodes = cache[nodes] = cache[nodes] || node.getElementsByTagName(tagName);
for (var j=0,m=nodes.length; j<m; j++){
node = nodes[j];
node.uid = node.uid || uid++;
//checkedhash[node.uid] = 1;
if (!(node.uid in hash) && $CONDITION$){
hash[node.uid] = 1;
ret.push(node);
}
}
}
return ret;
};
byTagName = byTagName.toString();
var byClassName = function (ret){
var hash = ret.hash = ret.hash || {};
var node;
var nodes;
for (var i=0; i<this.length; i++){
node = this[i];
node.uid = node.uid || uid++;
nodes = node.uid + className;
nodes = cache[nodes] = cache[nodes] || node.getElementsByClassName(className);
for (var j=0,m=nodes.length; j<m; j++){
node = nodes[j];
node.uid = node.uid || uid++;
if (!(node.uid in hash) && $CONDITION$){
hash[node.uid] = 1;
ret.push(node);
}
}
}
return ret;
};
byClassName = byClassName.toString();
var byClassNameRE = function (ret){
var hash = ret.hash = ret.hash || {};
var node;
var nodes;
for (var i=0; i<this.length; i++){
node = this[i];
node.uid = node.uid || uid++;
nodes = node.getElementsByTagName('*');
for (var j=0,m=nodes.length; j<m; j++){
node = nodes[j];
node.uid = node.uid || uid++;
if (classNameRE.test(node.className) && !(node.uid in hash) && $CONDITION$){
hash[node.uid] = 1;
ret.push(node);
}
}
}
return ret;
};
byClassNameRE = byClassNameRE.toString();
var byId = function (ret){
var hash = ret.hash = ret.hash || {};
var node;
for (var i=0; i<this.length; i++){
node = this[i];
node = node.getElementById(id);
if (node){
node.uid = node.uid || uid++;
if (!(node.uid in hash) && $CONDITION$){
hash[node.uid] = 1;
ret.push(node);
}
}
}
return ret;
};
byId = byId.toString();
var childFind = function (ret){
var hash = ret.hash = ret.hash || {};
var checkedhash = {};
var node;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -