Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正逻辑错误 #41

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions build/CommentCoreLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,10 @@ var CommentManager = (function() {
}
for(;this.position < this.timeline.length;this.position++){
if(this.options.limit > 0 && this.runline.length > this.limiter) break;
if(this.validate(this.timeline[this.position]) && this.timeline[this.position]['stime']<=time){
this.send(this.timeline[this.position]);
if(this.timeline[this.position]['stime']<=time){
if(this.validate(this.timeline[this.position])){
this.send(this.timeline[this.position]);
}
}else{
break;
}
Expand Down
129 changes: 129 additions & 0 deletions build/CommentFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* Created by Dev on 2015/9/2.
*/
function CommentFilter(){
this.modifiers = [];
this.runtime = null;
this.blockList = [];
this.rules = [{
item: "mode",
operator: "=",
subject: 4,
//底部弹幕
}];
this.config = {
useRegExp: false
};
this.allowTypes = {
"1":true,
"4":true,
"5":true,
"6":true,
"7":true,
"8":true,
"17":true
};
var rule_modifiers = [{
item: "mode",
operator: "=",
subject: 4,
//底部弹幕
},{
item: 'color',
operator: '!=',
subject: parseInt('FFFFFF')
},{
item: 'text',
operator: 'contain',
subject: '逗逼',
isdiy: true
}];
this.doModify = function(cmt){
for(var k=0;k<this.modifiers.length;k++){
cmt = this.modifiers[k](cmt);
}
return cmt;
};
this.beforeSend = function(cmt){
return cmt;
};
this.doValidate = function(cmtData){
if (!this.allowTypes[cmtData.mode]) return false;
var result = true;
var compare = function(op){
return function(a, b){
return eval("a" + op + "b");
}
};
var config = this.config;
for (var i = 0; i < this.rules.length; ++i){
if(!result) break;
var deal = null;

switch(this.rules[i].operator){
case '=':
case '==':
case '===':
case 'eq':
case 'equal':
case 'equals':
deal = compare('=='); break;
case '!=':
case '!==':
case 'ineq':
case 'inequal':
deal = compare('!='); break;
case '>':
case 'big than':
case 'bigger':
deal = compare('>'); break;
case '<':
case 'small than':
case 'smaller':
deal = compare('<'); break;
case '>=':
deal = compare('>='); break;
case '<=':
deal = compare('<='); break;
case 'has':
case 'contain':
deal = (function(){
if (config.useRegExp){
return function(a, b){
var reg = new RegExp(b);
return reg.test(a);
}
} else {
return function(a, b){
return a.indexOf(b) > -1;
}
}
})();
break;
default:
deal = function(){return true;}; break;
}
this.rules[i].item = this.rules[i].item.toLowerCase();
console.log(cmtData);
result = !(deal(cmtData[this.rules[i].item], this.rules[i].subject));
}
return result;
};
this.addRule = function(rule){
this.rules.push(rule);
};
this.delRule = function(index){
this.rules.splice(index, 1);
};
this.addModifier = function(f){
this.modifiers.push(f);
};
this.runtimeFilter = function(cmt){
if(this.runtime == null)
return cmt;
return this.runtime(cmt);
};
this.setRuntimeFilter = function(f){
this.runtime = f;
}
}
6 changes: 4 additions & 2 deletions src/CommentCoreLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ var CommentManager = (function() {
}
for(;this.position < this.timeline.length;this.position++){
if(this.options.limit > 0 && this.runline.length > this.limiter) break;
if(this.validate(this.timeline[this.position]) && this.timeline[this.position]['stime']<=time){
this.send(this.timeline[this.position]);
if( this.timeline[this.position]['stime']<=time){
if(this.validate(this.timeline[this.position])){
this.send(this.timeline[this.position]);
}
}else{
break;
}
Expand Down