From 11d818a70f81648a3f524eccce2fdc14f3e71f0b Mon Sep 17 00:00:00 2001 From: dbFlower Date: Wed, 2 Sep 2015 15:53:30 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 此处逻辑应该为 先验证是否stime < time 再验证 此条弹幕是否能通过filter的验证, 否则当补全validate的时候会让人抓狂。 --- build/CommentCoreLibrary.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/CommentCoreLibrary.js b/build/CommentCoreLibrary.js index ce15407..6298082 100644 --- a/build/CommentCoreLibrary.js +++ b/build/CommentCoreLibrary.js @@ -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; } From 6272eb3810c54decd021ac9bce711b0f24d5c13b Mon Sep 17 00:00:00 2001 From: dbFlower Date: Wed, 2 Sep 2015 16:02:14 +0800 Subject: [PATCH 2/3] Create CommentFilter.js rewrite CCL CommentFilter function --- build/CommentFilter.js | 132 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 build/CommentFilter.js diff --git a/build/CommentFilter.js b/build/CommentFilter.js new file mode 100644 index 0000000..00e0bb5 --- /dev/null +++ b/build/CommentFilter.js @@ -0,0 +1,132 @@ +/** + * 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': + 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 (this.useRegExp){ + return function(a, b){ + var reg = new RegExp(b); + return reg.test(a); + } + } else { + return function(a, b){ + return a.indexOf(b); + } + } + }; + break; + default: + deal = function(){return true;}; break; + } + this.rules[i].item = this.rules[i].item.toLowerCase(); + console.log(this.rules[i].item); + console.log(cmtData); + console.log(cmtData[this.rules[i].item]); + console.log(this.rules[i].subject); + result = !(deal(cmtData[this.rules[i].item], this.rules[i].subject)); + } + console.log(result); + return result; + }; + this.addRule = function(rule){ + this.blockList.push(new RegExp(rule)); + }; + this.delRule = function(index){ + this.blockList.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; + } +} From 245aceed99a0938ee794ae0f944164eb4b243fe2 Mon Sep 17 00:00:00 2001 From: dbFlower Date: Wed, 2 Sep 2015 17:30:01 +0800 Subject: [PATCH 3/3] Update CommentFilter.js repair addrule module, --- build/CommentFilter.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/build/CommentFilter.js b/build/CommentFilter.js index 00e0bb5..003b85a 100644 --- a/build/CommentFilter.js +++ b/build/CommentFilter.js @@ -55,10 +55,11 @@ function CommentFilter(){ return eval("a" + op + "b"); } }; + var config = this.config; for (var i = 0; i < this.rules.length; ++i){ - if(!result) continue; - //if(this.rules[i].mode != 'all' && this.rules[i].mode != cmtData.mode) continue; + if(!result) break; var deal = null; + switch(this.rules[i].operator){ case '=': case '==': @@ -86,37 +87,33 @@ function CommentFilter(){ deal = compare('<='); break; case 'has': case 'contain': - deal = function(){ - if (this.useRegExp){ + 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); + return a.indexOf(b) > -1; } } - }; + })(); break; default: deal = function(){return true;}; break; } this.rules[i].item = this.rules[i].item.toLowerCase(); - console.log(this.rules[i].item); console.log(cmtData); - console.log(cmtData[this.rules[i].item]); - console.log(this.rules[i].subject); result = !(deal(cmtData[this.rules[i].item], this.rules[i].subject)); } - console.log(result); return result; }; this.addRule = function(rule){ - this.blockList.push(new RegExp(rule)); + this.rules.push(rule); }; this.delRule = function(index){ - this.blockList.splice(index, 1); + this.rules.splice(index, 1); }; this.addModifier = function(f){ this.modifiers.push(f);