Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sortn(es) {
- if (es.length<1)
- return [];
- es.sort();
- var name = es[0];
- var count = 1;
- var res = [];
- for (var i=1;i<es.length;i++) {
- if (es[i] != name) {
- res.push({name:name,count:count});
- name = es[i];
- count = 1;
- } else {
- count = count + 1;
- }
- }
- res.push({name:name,count:count});
- res.sort(function(a,b){
- if (a.count<b.count) {
- return 1;
- } else if (a.count>b.count) {
- return -1;
- }
- return 0;
- });
- return res;
- }
- function query(qs,es,res) {
- var q = qs.shift();
- var tag = null;
- var class_ = null;
- var first = false;
- if (q.hasOwnProperty('tag')) {
- tag = q['tag'];
- }
- if (q.hasOwnProperty('class')) {
- class_ = q['class'];
- }
- if (es == null) {
- es = [document.body];
- }
- if (tag != null) {
- var es_ = [];
- es.forEach(function(m){
- [].slice.call(m.getElementsByTagName(tag)).forEach(function(n){
- if (class_ != null) {
- if (n.classList.contains(class_)) {
- es_.push(n);
- }
- } else {
- es_.push(n);
- }
- });
- });
- es = es_;
- } else {
- console.log('function query(q,f) error: tag not defined, q:');
- console.log(q);
- }
- if (qs.length == 0) {
- if (res.hasOwnProperty('all')) {
- res.all(es);
- }
- if (res.hasOwnProperty('each')) {
- es.forEach(res.each);
- }
- } else {
- query(qs,es,res);
- }
- }
- function objectArrayAsTable(oa,props) {
- var trs = [];
- for (var i=0;i<oa.length;i++) {
- var o = oa[i];
- var row = [];
- for (var j=0;j<props.length;j++) {
- if (o.hasOwnProperty(props[j])) {
- row.push(o[props[j]]);
- } else {
- row.push('');
- }
- }
- trs.push('<td>' + row.join('</td><td>') + '</td>');
- }
- return '<table>' + '<tr>' + trs.join('</tr><tr>') + '</tr>' + '</table>';
- }
- var perf = [];
- query([{tag:'div','class':'title_wrap'},{tag:'b'},{tag:'a'}],null,{each:function(e){
- e.textContent.split(/[,&]/).forEach(function(n){
- var m = n.match(/\(C[.]?[Vv][:.] (.*)\)/);
- if (m) {
- perf.push(m[1].trim());
- //console.log('cv: ' + n.trim() + ' -> ' + m[1].trim());
- } else {
- perf.push(n.trim());
- //console.log('no cv: ' + n.trim());
- }
- });
- }
- });
- var perf_ = sortn(perf);
- document.body.innerHTML = objectArrayAsTable(perf_,['name','count']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement