diff --git a/build/CommentCoreLibrary.js b/build/CommentCoreLibrary.js index 3268db0..458fe44 100644 --- a/build/CommentCoreLibrary.js +++ b/build/CommentCoreLibrary.js @@ -1430,7 +1430,11 @@ var BilibiliFormat = (function () { } BilibiliFormat.XMLParser.prototype.parseOne = function (elem) { - var params = elem.getAttribute('p').split(','); + try { + var params = elem.getAttribute('p').split(','); + } catch (e) { + throw new Error("Unsupported object type or could not decompose."); + } if (!elem.childNodes[0]) { // Not a comment or nested comment, skip return null; @@ -1613,7 +1617,7 @@ var BilibiliFormat = (function () { for (var i = 0; i < elements.length; i++) { var comment = this.parseOne(elements[i]); if (comment !== null) { - commentList.push(); + commentList.push(comment); } } return commentList; @@ -1622,6 +1626,7 @@ var BilibiliFormat = (function () { BilibiliFormat.TextParser = function (params) { this._allowInsecureDomParsing = true; this._attemptEscaping = true; + this._canSecureParse = false; if (typeof params === 'object') { this._allowInsecureDomParsing = params.allowInsecureDomParsing === false ? false : true; this._attemptEscaping = params.attemptEscaping === false ? false : true; @@ -1630,7 +1635,10 @@ var BilibiliFormat = (function () { // We can't rely on innerHTML anyways. Maybe we're in a restricted context (i.e. node). this._allowInsecureDomParsing = false; } - if (this._allowInsecureDomParsing) { + if (typeof DOMParser !== 'undefined' && DOMParser !== null) { + this._canSecureNativeParse = true; + } + if (this._allowInsecureDomParsing || this._canSecureNativeParse) { this._xmlParser = new BilibiliFormat.XMLParser(params); } }; @@ -1650,8 +1658,12 @@ var BilibiliFormat = (function () { } else { return this._xmlParser.parseOne(tags[0]); } - } else { - throw new Error('Secure parsing not implemented yet.'); + } else if (this._canSecureNativeParse) { + var domParser = new DOMParser(); + return this._xmlParser.parseOne( + domParser.parseFromString(comment, 'application/xml')); + } else{ + throw new Error('Secure native js parsing not implemented yet.'); } }; @@ -1666,8 +1678,13 @@ var BilibiliFormat = (function () { temp.innerHTML = source; var tags = temp.getElementsByTagName('d'); return this._xmlParser.parseMany(tags); + } else if (this._canSecureNativeParse) { + var domParser = new DOMParser(); + return this._xmlParser.parseMany( + domParser.parseFromString(comment, 'application/xml')); + } else { - throw new Error('Secure parsing not implemented yet.'); + throw new Error('Secure native js parsing not implemented yet.'); } }; diff --git a/build/CommentCoreLibrary.min.js b/build/CommentCoreLibrary.min.js index ec01177..6769847 100644 --- a/build/CommentCoreLibrary.min.js +++ b/build/CommentCoreLibrary.min.js @@ -1 +1 @@ -/*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */function CommentFilter(){this.modifiers=[],this.runtime=null,this.allowTypes={1:!0,4:!0,5:!0,6:!0,7:!0,8:!0,17:!0},this.doModify=function(a){for(var b=0;b=0)return a.length;for(var d=0,e=0,f=0,g=a.length-1;d<=g;){if(e=Math.floor((g+d+1)/2),f++,c(b,a[e-1])>=0&&c(b,a[e])<0)return e;c(b,a[e-1])<0?g=e-1:c(b,a[e])>=0?d=e:console.error("Program Error"),f>1500&&console.error("Too many run cycles.")}return-1},a.binsert=function(b,c,d){var e=a.bsearch(b,c,d);return b.splice(e,0,c),e},a}(),__extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},CommentSpaceAllocator=function(){function a(a,b){void 0===a&&(a=0),void 0===b&&(b=0),this._pools=[[]],this.avoid=1,this._width=a,this._height=b}return a.prototype.willCollide=function(a,b){return a.stime+a.ttl>=b.stime+b.ttl/2},a.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=b.right,f=0;fd||c[f].bottome))return!1;if(this.willCollide(c[f],b))return!1}return!0},a.prototype.assign=function(a,b){for(;this._pools.length<=b;)this._pools.push([]);var c=this._pools[b];if(0===c.length)return a.cindex=b,0;if(this.pathCheck(0,a,c))return a.cindex=b,0;for(var d=0,e=0;ethis._height));e++)if(this.pathCheck(d,a,c))return a.cindex=b,d;return this.assign(a,b+1)},a.prototype.add=function(a){a.height>this._height?(a.cindex=-2,a.y=0):(a.y=this.assign(a,0),BinArray.binsert(this._pools[a.cindex],a,function(a,b){return a.bottomb.bottom?1:0}))},a.prototype.remove=function(a){if(!(a.cindex<0)){if(a.cindex>=this._pools.length)throw new Error("cindex out of bounds");var b=this._pools[a.cindex].indexOf(a);b<0||this._pools[a.cindex].splice(b,1)}},a.prototype.setBounds=function(a,b){this._width=a,this._height=b},a}(),AnchorCommentSpaceAllocator=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.add=function(b){a.prototype.add.call(this,b),b.x=(this._width-b.width)/2},b.prototype.willCollide=function(a,b){return!0},b.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=0;ed||c[e].bottom0&&this.animate()},Object.defineProperty(a.prototype,"x",{get:function(){return null!==this._x&&void 0!==this._x||(this.align%2===0?this._x=this.dom.offsetLeft:this._x=this.parent.width-this.dom.offsetLeft-this.width),this.absolute?this._x:this._x/this.parent.width},set:function(a){this._x=a,this.absolute||(this._x*=this.parent.width),this.align%2===0?this.dom.style.left=this._x+"px":this.dom.style.right=this._x+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"y",{get:function(){return null!==this._y&&void 0!==this._y||(this.align<2?this._y=this.dom.offsetTop:this._y=this.parent.height-this.dom.offsetTop-this.height),this.absolute?this._y:this._y/this.parent.height},set:function(a){this._y=a,this.absolute||(this._y*=this.parent.height),this.align<2?this.dom.style.top=this._y+"px":this.dom.style.bottom=this._y+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"width",{get:function(){return null!==this._width&&void 0!==this._width||(this._width=this.dom.offsetWidth),this._width},set:function(a){this._width=a,this.dom.style.width=this._width+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"height",{get:function(){return null!==this._height&&void 0!==this._height||(this._height=this.dom.offsetHeight),this._height},set:function(a){this._height=a,this.dom.style.height=this._height+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"size",{get:function(){return this._size},set:function(a){this._size=a,this.dom.style.fontSize=this._size+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"color",{get:function(){return this._color},set:function(a){this._color=a;var b=a.toString(16);b=b.length>=6?b:new Array(6-b.length+1).join("0")+b,this.dom.style.color="#"+b,0===this._color&&(this.dom.className=this.parent.options.global.className+" rshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"alpha",{get:function(){return this._alpha},set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(this._alpha,this.parent.options.global.opacity)+""},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"border",{get:function(){return this._border},set:function(a){this._border=a,this._border?this.dom.style.border="1px solid #00ffff":this.dom.style.border="none"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"shadow",{get:function(){return this._shadow},set:function(a){this._shadow=a,this._shadow||(this.dom.className=this.parent.options.global.className+" noshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"font",{get:function(){return this._font},set:function(a){this._font=a,this._font.length>0?this.dom.style.fontFamily=this._font:this.dom.style.fontFamily=""},enumerable:!0,configurable:!0}),a.prototype.time=function(a){this.ttl-=a,this.ttl<0&&(this.ttl=0),this.movable&&this.update(),this.ttl<=0&&this.finish()},a.prototype.update=function(){this.animate()},a.prototype.invalidate=function(){this._x=null,this._y=null,this._width=null,this._height=null},a.prototype._execMotion=function(a,b){for(var c in a)if(a.hasOwnProperty(c)){var d=a[c];this[c]=d.easing(Math.min(Math.max(b-d.delay,0),d.dur),d.from,d.to-d.from,d.dur)}},a.prototype.animate=function(){if(this._alphaMotion&&(this.alpha=(this.dur-this.ttl)*(this._alphaMotion.to-this._alphaMotion.from)/this.dur+this._alphaMotion.from),0!==this.motion.length){var a=Math.max(this.ttl,0),b=this.dur-a-this._motionStart[this._curMotion];return this._execMotion(this.motion[this._curMotion],b),this.dur-a>this._motionEnd[this._curMotion]?(this._curMotion++,void(this._curMotion>=this.motion.length&&(this._curMotion=this.motion.length-1))):void 0}},a.prototype.finish=function(){this.parent.finish(this)},a.prototype.toString=function(){return["[",this.stime,"|",this.ttl,"/",this.dur,"]","(",this.mode,")",this.text].join("")},a.LINEAR=function(a,b,c,d){return a*c/d+b},a}(),ScrollComment=function(a){function b(b,c){a.call(this,b,c),this.dur*=this.parent.options.scroll.scale,this.ttl*=this.parent.options.scroll.scale}return __extends(b,a),Object.defineProperty(b.prototype,"alpha",{set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(Math.min(this._alpha,this.parent.options.global.opacity),this.parent.options.scroll.opacity)+""},enumerable:!0,configurable:!0}),b.prototype.init=function(b){void 0===b&&(b=null),a.prototype.init.call(this,b),this.x=this.parent.width,this.parent.options.scroll.opacity<1&&(this.alpha=this._alpha),this.absolute=!0},b.prototype.update=function(){this.x=this.ttl/this.dur*(this.parent.width+this.width)-this.width},b}(CoreComment),CommentManager=function(){function a(a){var b=0;this._listeners={},this._lastPosition=0,this.stage=a,this.options={global:{opacity:1,scale:1,className:"cmt"},scroll:{opacity:1,scale:1},limit:0},this.timeline=[],this.runline=[],this.position=0,this.limiter=0,this.filter=null,this.csa={scroll:new CommentSpaceAllocator(0,0),top:new AnchorCommentSpaceAllocator(0,0),bottom:new AnchorCommentSpaceAllocator(0,0),reverse:new CommentSpaceAllocator(0,0),scrollbtm:new CommentSpaceAllocator(0,0)},this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.startTimer=function(){if(!(b>0)){var a=(new Date).getTime(),c=this;b=window.setInterval(function(){var b=(new Date).getTime()-a;a=(new Date).getTime(),c.onTimerEvent(b,c)},10)}},this.stopTimer=function(){window.clearInterval(b),b=0}}var b=function(a,b){for(var c=Math.PI/180,d=a*c,e=b*c,f=Math.cos,g=Math.sin,h=[f(d)*f(e),f(d)*g(e),g(d),0,-g(e),f(e),0,0,-g(d)*f(e),-g(d)*g(e),f(d),0,0,0,0,1],i=0;ib.stime?1:0})},a.prototype.validate=function(a){return null!=a&&this.filter.doValidate(a)},a.prototype.load=function(a){this.timeline=a,this.timeline.sort(function(a,b){return a.stime>b.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbidb.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbid0;)this.runline[0].finish();this.dispatchEvent("clear")},a.prototype.setBounds=function(){this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.dispatchEvent("resize");for(var a in this.csa)this.csa[a].setBounds(this.width,this.height);this.stage.style.perspective=this.width*Math.tan(40*Math.PI/180)/2+"px",this.stage.style.webkitPerspective=this.width*Math.tan(40*Math.PI/180)/2+"px"},a.prototype.init=function(){this.setBounds(),null==this.filter&&(this.filter=new CommentFilter)},a.prototype.time=function(a){if(a-=1,this.position>=this.timeline.length||Math.abs(this._lastPosition-a)>=2e3){if(this.seek(a),this._lastPosition=a,this.timeline.length<=this.position)return}else this._lastPosition=a;for(;this.position0&&this.runline.length>this.limiter||this.validate(this.timeline[this.position])&&this.send(this.timeline[this.position])},a.prototype.rescale=function(){},a.prototype.send=function(a){if(8===a.mode)return console.log(a),void(this.scripting&&console.log(this.scripting.eval(a.code)));if(null==this.filter||(a=this.filter.doModify(a),null!=a)){if(1===a.mode||2===a.mode||6===a.mode)var c=new ScrollComment(this,a);else var c=new CoreComment(this,a);switch(c.mode){case 1:c.align=0;break;case 2:c.align=2;break;case 4:c.align=2;break;case 5:c.align=0;break;case 6:c.align=1}switch(c.init(),this.stage.appendChild(c.dom),c.mode){default:case 1:this.csa.scroll.add(c);break;case 2:this.csa.scrollbtm.add(c);break;case 4:this.csa.bottom.add(c);break;case 5:this.csa.top.add(c);break;case 6:this.csa.reverse.add(c);break;case 17:case 7:0===a.rY&&0===a.rZ||(c.dom.style.transform=b(a.rY,a.rZ),c.dom.style.webkitTransform=b(a.rY,a.rZ),c.dom.style.OTransform=b(a.rY,a.rZ),c.dom.style.MozTransform=b(a.rY,a.rZ),c.dom.style.MSTransform=b(a.rY,a.rZ))}c.y=c.y,this.dispatchEvent("enterComment",c),this.runline.push(c)}},a.prototype.sendComment=function(a){console.log("CommentManager.sendComment is deprecated. Please use send instead"),this.send(a)},a.prototype.finish=function(a){this.dispatchEvent("exitComment",a),this.stage.removeChild(a.dom);var b=this.runline.indexOf(a);switch(b>=0&&this.runline.splice(b,1),a.mode){default:case 1:this.csa.scroll.remove(a);break;case 2:this.csa.scrollbtm.remove(a);break;case 4:this.csa.bottom.remove(a);break;case 5:this.csa.top.remove(a);break;case 6:this.csa.reverse.remove(a);break;case 7:}},a.prototype.addEventListener=function(a,b){"undefined"!=typeof this._listeners[a]?this._listeners[a].push(b):this._listeners[a]=[b]},a.prototype.dispatchEvent=function(a,b){if("undefined"!=typeof this._listeners[a])for(var c=0;c=200&&this.status<300?f(this.response):g(new Error(this.status+" "+this.statusText))},h.onerror=function(){g(new Error(this.status+" "+this.statusText))},h.open(a,i),"undefined"!=typeof e?h.send(e):h.send()})},a.JSONProvider=function(b,c,d,e){return a.BaseHttpProvider(b,c,"json",d,e).then(function(a){return a})},a.XMLProvider=function(b,c,d,e){return a.BaseHttpProvider(b,c,"document",d,e).then(function(a){return a})},a.TextProvider=function(b,c,d,e){return a.BaseHttpProvider(b,c,"text",d,e).then(function(a){return a.text})},a.prototype.addStaticSource=function(a,b){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more sources.");return b in this._staticSources||(this._staticSources[b]=[]),this._staticSources[b].push(a),this},a.prototype.addDynamicSource=function(a,b){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more sources.");return b in this._dynamicSources||(this._dynamicSources[b]=[]),this._dynamicSources[b].push(a),this},a.prototype.addTarget=function(a){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more targets.");if(!(a instanceof CommentManager))throw new Error("Expected the target to be an instance of CommentManager.");return this._targets.push(a),this},a.prototype.addParser=function(a,b){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more parsers.");return b in this._parsers||(this._parsers[b]=[]),this._parsers[b].unshift(a),this},a.prototype.applyParsersOne=function(a,b){return new Promise(function(c,d){if(!(b in this._parsers))return void d(new Error('No parsers defined for "'+b+'"'));for(var e=0;e=6){if(b.stime=1e3*parseFloat(c[0]),b.color=parseInt(c[1]),b.mode=parseInt(c[2]),b.size=parseInt(c[3]),b.hash=c[4],b.date=parseInt(c[5]),b.position="absolute",7!==b.mode)b.text=a.m.replace(/(\/n|\\n|\n|\r\n|\\r)/g,"\n"),b.text=b.text.replace(/\r/g,"\n"),b.text=b.text.replace(/\s/g," ");else{try{var d=JSON.parse(a.m)}catch(a){return console.warn("Error parsing internal data for comment"),console.log("[Dbg] "+b.text),null}if(b.position="relative",b.text=d.n,b.text=b.text.replace(/\ /g," "),null!=d.a?b.opacity=d.a:b.opacity=1,null!=d.p?(b.x=d.p.x/1e3,b.y=d.p.y/1e3):(b.x=0,b.y=0),b.shadow=d.b,b.dur=4e3,null!=d.l&&(b.moveDelay=1e3*d.l),null!=d.z&&d.z.length>0){b.movable=!0,b.motion=[];for(var e=0,f={x:b.x,y:b.y,alpha:b.opacity,color:b.color},g=0;g=7&&(f.rZ=parseInt(g[5],10),f.rY=parseInt(g[6],10)),f.motion=[],f.movable=!1,g.length>=11){f.movable=!0;var h=500,i={x:{from:f.x,to:parseFloat(g[7]),dur:h,delay:0},y:{from:f.y,to:parseFloat(g[8]),dur:h,delay:0}};if(""!==g[9]&&(h=parseInt(g[9],10),i.x.dur=h,i.y.dur=h),""!==g[10]&&(i.x.delay=parseInt(g[10],10),i.y.delay=parseInt(g[10],10)),g.length>11&&(f.shadow=g[11],"true"===f.shadow&&(f.shadow=!0),"false"===f.shadow&&(f.shadow=!1),null!=g[12]&&(f.font=g[12]),g.length>14)){"relative"===f.position&&(this._logBadComments&&console.warn("Cannot mix relative and absolute positioning!"),f.position="absolute");for(var j=g[14],k={x:i.x.from,y:i.y.from},l=[],m=new RegExp("([a-zA-Z])\\s*(\\d+)[, ](\\d+)","g"),n=j.split(/[a-zA-Z]/).length-1,o=m.exec(j);null!==o;){switch(o[1]){case"M":k.x=parseInt(o[2],10),k.y=parseInt(o[3],10);break;case"L":l.push({x:{from:k.x,to:parseInt(o[2],10),dur:h/n,delay:0},y:{from:k.y,to:parseInt(o[3],10),dur:h/n,delay:0}}),k.x=parseInt(o[2],10),k.y=parseInt(o[3],10)}o=m.exec(j)}i=null,f.motion=l}null!==i&&f.motion.push(i)}f.dur=2500,g[3]<12&&(f.dur=1e3*g[3]);var p=g[2].split("-");if(null!=p&&p.length>1){var q=parseFloat(p[0]),r=parseFloat(p[1]);f.opacity=q,q!==r&&(f.alpha={from:q,to:r})}}catch(a){this._logBadComments&&(console.warn("Error occurred in JSON parsing. Could not parse comment."),console.log("[DEBUG] "+e))}else 8===f.mode?f.code=e:this._logBadComments&&(console.warn("Unknown comment type : "+f.mode+". Not doing further parsing."),console.log("[DEBUG] "+e));return null!==f.text&&"string"==typeof f.text&&(f.text=f.text.replace(/\u25a0/g,"█")),f},a.XMLParser.prototype.parseMany=function(a){var b=[];try{b=a.getElementsByTagName("d")}catch(a){return null}for(var c=[],d=0;d=0)return a.length;for(var d=0,e=0,f=0,g=a.length-1;d<=g;){if(e=Math.floor((g+d+1)/2),f++,c(b,a[e-1])>=0&&c(b,a[e])<0)return e;c(b,a[e-1])<0?g=e-1:c(b,a[e])>=0?d=e:console.error("Program Error"),f>1500&&console.error("Too many run cycles.")}return-1},a.binsert=function(b,c,d){var e=a.bsearch(b,c,d);return b.splice(e,0,c),e},a}(),__extends=this&&this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);a.prototype=null===b?Object.create(b):(c.prototype=b.prototype,new c)},CommentSpaceAllocator=function(){function a(a,b){void 0===a&&(a=0),void 0===b&&(b=0),this._pools=[[]],this.avoid=1,this._width=a,this._height=b}return a.prototype.willCollide=function(a,b){return a.stime+a.ttl>=b.stime+b.ttl/2},a.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=b.right,f=0;fd||c[f].bottome))return!1;if(this.willCollide(c[f],b))return!1}return!0},a.prototype.assign=function(a,b){for(;this._pools.length<=b;)this._pools.push([]);var c=this._pools[b];if(0===c.length)return a.cindex=b,0;if(this.pathCheck(0,a,c))return a.cindex=b,0;for(var d=0,e=0;ethis._height));e++)if(this.pathCheck(d,a,c))return a.cindex=b,d;return this.assign(a,b+1)},a.prototype.add=function(a){a.height>this._height?(a.cindex=-2,a.y=0):(a.y=this.assign(a,0),BinArray.binsert(this._pools[a.cindex],a,function(a,b){return a.bottomb.bottom?1:0}))},a.prototype.remove=function(a){if(!(a.cindex<0)){if(a.cindex>=this._pools.length)throw new Error("cindex out of bounds");var b=this._pools[a.cindex].indexOf(a);b<0||this._pools[a.cindex].splice(b,1)}},a.prototype.setBounds=function(a,b){this._width=a,this._height=b},a}(),AnchorCommentSpaceAllocator=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.add=function(b){a.prototype.add.call(this,b),b.x=(this._width-b.width)/2},b.prototype.willCollide=function(a,b){return!0},b.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=0;ed||c[e].bottom0&&this.animate()},Object.defineProperty(a.prototype,"x",{get:function(){return null!==this._x&&void 0!==this._x||(this.align%2===0?this._x=this.dom.offsetLeft:this._x=this.parent.width-this.dom.offsetLeft-this.width),this.absolute?this._x:this._x/this.parent.width},set:function(a){this._x=a,this.absolute||(this._x*=this.parent.width),this.align%2===0?this.dom.style.left=this._x+"px":this.dom.style.right=this._x+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"y",{get:function(){return null!==this._y&&void 0!==this._y||(this.align<2?this._y=this.dom.offsetTop:this._y=this.parent.height-this.dom.offsetTop-this.height),this.absolute?this._y:this._y/this.parent.height},set:function(a){this._y=a,this.absolute||(this._y*=this.parent.height),this.align<2?this.dom.style.top=this._y+"px":this.dom.style.bottom=this._y+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"width",{get:function(){return null!==this._width&&void 0!==this._width||(this._width=this.dom.offsetWidth),this._width},set:function(a){this._width=a,this.dom.style.width=this._width+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"height",{get:function(){return null!==this._height&&void 0!==this._height||(this._height=this.dom.offsetHeight),this._height},set:function(a){this._height=a,this.dom.style.height=this._height+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"size",{get:function(){return this._size},set:function(a){this._size=a,this.dom.style.fontSize=this._size+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"color",{get:function(){return this._color},set:function(a){this._color=a;var b=a.toString(16);b=b.length>=6?b:new Array(6-b.length+1).join("0")+b,this.dom.style.color="#"+b,0===this._color&&(this.dom.className=this.parent.options.global.className+" rshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"alpha",{get:function(){return this._alpha},set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(this._alpha,this.parent.options.global.opacity)+""},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"border",{get:function(){return this._border},set:function(a){this._border=a,this._border?this.dom.style.border="1px solid #00ffff":this.dom.style.border="none"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"shadow",{get:function(){return this._shadow},set:function(a){this._shadow=a,this._shadow||(this.dom.className=this.parent.options.global.className+" noshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"font",{get:function(){return this._font},set:function(a){this._font=a,this._font.length>0?this.dom.style.fontFamily=this._font:this.dom.style.fontFamily=""},enumerable:!0,configurable:!0}),a.prototype.time=function(a){this.ttl-=a,this.ttl<0&&(this.ttl=0),this.movable&&this.update(),this.ttl<=0&&this.finish()},a.prototype.update=function(){this.animate()},a.prototype.invalidate=function(){this._x=null,this._y=null,this._width=null,this._height=null},a.prototype._execMotion=function(a,b){for(var c in a)if(a.hasOwnProperty(c)){var d=a[c];this[c]=d.easing(Math.min(Math.max(b-d.delay,0),d.dur),d.from,d.to-d.from,d.dur)}},a.prototype.animate=function(){if(this._alphaMotion&&(this.alpha=(this.dur-this.ttl)*(this._alphaMotion.to-this._alphaMotion.from)/this.dur+this._alphaMotion.from),0!==this.motion.length){var a=Math.max(this.ttl,0),b=this.dur-a-this._motionStart[this._curMotion];return this._execMotion(this.motion[this._curMotion],b),this.dur-a>this._motionEnd[this._curMotion]?(this._curMotion++,void(this._curMotion>=this.motion.length&&(this._curMotion=this.motion.length-1))):void 0}},a.prototype.finish=function(){this.parent.finish(this)},a.prototype.toString=function(){return["[",this.stime,"|",this.ttl,"/",this.dur,"]","(",this.mode,")",this.text].join("")},a.LINEAR=function(a,b,c,d){return a*c/d+b},a}(),ScrollComment=function(a){function b(b,c){a.call(this,b,c),this.dur*=this.parent.options.scroll.scale,this.ttl*=this.parent.options.scroll.scale}return __extends(b,a),Object.defineProperty(b.prototype,"alpha",{set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(Math.min(this._alpha,this.parent.options.global.opacity),this.parent.options.scroll.opacity)+""},enumerable:!0,configurable:!0}),b.prototype.init=function(b){void 0===b&&(b=null),a.prototype.init.call(this,b),this.x=this.parent.width,this.parent.options.scroll.opacity<1&&(this.alpha=this._alpha),this.absolute=!0},b.prototype.update=function(){this.x=this.ttl/this.dur*(this.parent.width+this.width)-this.width},b}(CoreComment),CommentManager=function(){function a(a){var b=0;this._listeners={},this._lastPosition=0,this.stage=a,this.options={global:{opacity:1,scale:1,className:"cmt"},scroll:{opacity:1,scale:1},limit:0},this.timeline=[],this.runline=[],this.position=0,this.limiter=0,this.filter=null,this.csa={scroll:new CommentSpaceAllocator(0,0),top:new AnchorCommentSpaceAllocator(0,0),bottom:new AnchorCommentSpaceAllocator(0,0),reverse:new CommentSpaceAllocator(0,0),scrollbtm:new CommentSpaceAllocator(0,0)},this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.startTimer=function(){if(!(b>0)){var a=(new Date).getTime(),c=this;b=window.setInterval(function(){var b=(new Date).getTime()-a;a=(new Date).getTime(),c.onTimerEvent(b,c)},10)}},this.stopTimer=function(){window.clearInterval(b),b=0}}var b=function(a,b){for(var c=Math.PI/180,d=a*c,e=b*c,f=Math.cos,g=Math.sin,h=[f(d)*f(e),f(d)*g(e),g(d),0,-g(e),f(e),0,0,-g(d)*f(e),-g(d)*g(e),f(d),0,0,0,0,1],i=0;ib.stime?1:0})},a.prototype.validate=function(a){return null!=a&&this.filter.doValidate(a)},a.prototype.load=function(a){this.timeline=a,this.timeline.sort(function(a,b){return a.stime>b.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbidb.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbid0;)this.runline[0].finish();this.dispatchEvent("clear")},a.prototype.setBounds=function(){this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.dispatchEvent("resize");for(var a in this.csa)this.csa[a].setBounds(this.width,this.height);this.stage.style.perspective=this.width*Math.tan(40*Math.PI/180)/2+"px",this.stage.style.webkitPerspective=this.width*Math.tan(40*Math.PI/180)/2+"px"},a.prototype.init=function(){this.setBounds(),null==this.filter&&(this.filter=new CommentFilter)},a.prototype.time=function(a){if(a-=1,this.position>=this.timeline.length||Math.abs(this._lastPosition-a)>=2e3){if(this.seek(a),this._lastPosition=a,this.timeline.length<=this.position)return}else this._lastPosition=a;for(;this.position0&&this.runline.length>this.limiter||this.validate(this.timeline[this.position])&&this.send(this.timeline[this.position])},a.prototype.rescale=function(){},a.prototype.send=function(a){if(8===a.mode)return console.log(a),void(this.scripting&&console.log(this.scripting.eval(a.code)));if(null==this.filter||(a=this.filter.doModify(a),null!=a)){if(1===a.mode||2===a.mode||6===a.mode)var c=new ScrollComment(this,a);else var c=new CoreComment(this,a);switch(c.mode){case 1:c.align=0;break;case 2:c.align=2;break;case 4:c.align=2;break;case 5:c.align=0;break;case 6:c.align=1}switch(c.init(),this.stage.appendChild(c.dom),c.mode){default:case 1:this.csa.scroll.add(c);break;case 2:this.csa.scrollbtm.add(c);break;case 4:this.csa.bottom.add(c);break;case 5:this.csa.top.add(c);break;case 6:this.csa.reverse.add(c);break;case 17:case 7:0===a.rY&&0===a.rZ||(c.dom.style.transform=b(a.rY,a.rZ),c.dom.style.webkitTransform=b(a.rY,a.rZ),c.dom.style.OTransform=b(a.rY,a.rZ),c.dom.style.MozTransform=b(a.rY,a.rZ),c.dom.style.MSTransform=b(a.rY,a.rZ))}c.y=c.y,this.dispatchEvent("enterComment",c),this.runline.push(c)}},a.prototype.sendComment=function(a){console.log("CommentManager.sendComment is deprecated. Please use send instead"),this.send(a)},a.prototype.finish=function(a){this.dispatchEvent("exitComment",a),this.stage.removeChild(a.dom);var b=this.runline.indexOf(a);switch(b>=0&&this.runline.splice(b,1),a.mode){default:case 1:this.csa.scroll.remove(a);break;case 2:this.csa.scrollbtm.remove(a);break;case 4:this.csa.bottom.remove(a);break;case 5:this.csa.top.remove(a);break;case 6:this.csa.reverse.remove(a);break;case 7:}},a.prototype.addEventListener=function(a,b){"undefined"!=typeof this._listeners[a]?this._listeners[a].push(b):this._listeners[a]=[b]},a.prototype.dispatchEvent=function(a,b){if("undefined"!=typeof this._listeners[a])for(var c=0;c=200&&this.status<300?f(this.response):g(new Error(this.status+" "+this.statusText))},h.onerror=function(){g(new Error(this.status+" "+this.statusText))},h.open(a,i),"undefined"!=typeof e?h.send(e):h.send()})},a.JSONProvider=function(b,c,d,e){return a.BaseHttpProvider(b,c,"json",d,e).then(function(a){return a})},a.XMLProvider=function(b,c,d,e){return a.BaseHttpProvider(b,c,"document",d,e).then(function(a){return a})},a.TextProvider=function(b,c,d,e){return a.BaseHttpProvider(b,c,"text",d,e).then(function(a){return a.text})},a.prototype.addStaticSource=function(a,b){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more sources.");return b in this._staticSources||(this._staticSources[b]=[]),this._staticSources[b].push(a),this},a.prototype.addDynamicSource=function(a,b){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more sources.");return b in this._dynamicSources||(this._dynamicSources[b]=[]),this._dynamicSources[b].push(a),this},a.prototype.addTarget=function(a){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more targets.");if(!(a instanceof CommentManager))throw new Error("Expected the target to be an instance of CommentManager.");return this._targets.push(a),this},a.prototype.addParser=function(a,b){if(this._destroyed)throw new Error("Comment provider has been destroyed, cannot attach more parsers.");return b in this._parsers||(this._parsers[b]=[]),this._parsers[b].unshift(a),this},a.prototype.applyParsersOne=function(a,b){return new Promise(function(c,d){if(!(b in this._parsers))return void d(new Error('No parsers defined for "'+b+'"'));for(var e=0;e=6){if(b.stime=1e3*parseFloat(c[0]),b.color=parseInt(c[1]),b.mode=parseInt(c[2]),b.size=parseInt(c[3]),b.hash=c[4],b.date=parseInt(c[5]),b.position="absolute",7!==b.mode)b.text=a.m.replace(/(\/n|\\n|\n|\r\n|\\r)/g,"\n"),b.text=b.text.replace(/\r/g,"\n"),b.text=b.text.replace(/\s/g," ");else{try{var d=JSON.parse(a.m)}catch(a){return console.warn("Error parsing internal data for comment"),console.log("[Dbg] "+b.text),null}if(b.position="relative",b.text=d.n,b.text=b.text.replace(/\ /g," "),null!=d.a?b.opacity=d.a:b.opacity=1,null!=d.p?(b.x=d.p.x/1e3,b.y=d.p.y/1e3):(b.x=0,b.y=0),b.shadow=d.b,b.dur=4e3,null!=d.l&&(b.moveDelay=1e3*d.l),null!=d.z&&d.z.length>0){b.movable=!0,b.motion=[];for(var e=0,f={x:b.x,y:b.y,alpha:b.opacity,color:b.color},g=0;g=7&&(f.rZ=parseInt(g[5],10),f.rY=parseInt(g[6],10)),f.motion=[],f.movable=!1,g.length>=11){f.movable=!0;var h=500,i={x:{from:f.x,to:parseFloat(g[7]),dur:h,delay:0},y:{from:f.y,to:parseFloat(g[8]),dur:h,delay:0}};if(""!==g[9]&&(h=parseInt(g[9],10),i.x.dur=h,i.y.dur=h),""!==g[10]&&(i.x.delay=parseInt(g[10],10),i.y.delay=parseInt(g[10],10)),g.length>11&&(f.shadow=g[11],"true"===f.shadow&&(f.shadow=!0),"false"===f.shadow&&(f.shadow=!1),null!=g[12]&&(f.font=g[12]),g.length>14)){"relative"===f.position&&(this._logBadComments&&console.warn("Cannot mix relative and absolute positioning!"),f.position="absolute");for(var j=g[14],k={x:i.x.from,y:i.y.from},l=[],m=new RegExp("([a-zA-Z])\\s*(\\d+)[, ](\\d+)","g"),n=j.split(/[a-zA-Z]/).length-1,o=m.exec(j);null!==o;){switch(o[1]){case"M":k.x=parseInt(o[2],10),k.y=parseInt(o[3],10);break;case"L":l.push({x:{from:k.x,to:parseInt(o[2],10),dur:h/n,delay:0},y:{from:k.y,to:parseInt(o[3],10),dur:h/n,delay:0}}),k.x=parseInt(o[2],10),k.y=parseInt(o[3],10)}o=m.exec(j)}i=null,f.motion=l}null!==i&&f.motion.push(i)}f.dur=2500,g[3]<12&&(f.dur=1e3*g[3]);var p=g[2].split("-");if(null!=p&&p.length>1){var q=parseFloat(p[0]),r=parseFloat(p[1]);f.opacity=q,q!==r&&(f.alpha={from:q,to:r})}}catch(a){this._logBadComments&&(console.warn("Error occurred in JSON parsing. Could not parse comment."),console.log("[DEBUG] "+e))}else 8===f.mode?f.code=e:this._logBadComments&&(console.warn("Unknown comment type : "+f.mode+". Not doing further parsing."),console.log("[DEBUG] "+e));return null!==f.text&&"string"==typeof f.text&&(f.text=f.text.replace(/\u25a0/g,"█")),f},a.XMLParser.prototype.parseMany=function(a){var b=[];try{b=a.getElementsByTagName("d")}catch(a){return null}for(var c=[],d=0;d it 'smoking test', -> jasmine.getFixtures().fixturesPath = "test/" - comments = AcfunParser(readFixtures 'ac940133.json') + json = JSON.parse readFixtures 'ac940133.json' + comments = (new AcfunFormat.JSONParser()).parseMany json # TODO: Construct a json that cover all types of comments # and use it for smoking test manager.load comments diff --git a/spec/parsers/AcfunFormat_spec.coffee b/spec/parsers/AcfunFormat_spec.coffee index ac71e8b..d55ebdf 100644 --- a/spec/parsers/AcfunFormat_spec.coffee +++ b/spec/parsers/AcfunFormat_spec.coffee @@ -1,16 +1,39 @@ 'use strict' describe 'AcfunFormat', -> - jasmine.getFixtures().fixturesPath = "test/" - it 'works', -> - json = readFixtures 'ACFun.json' - comments = AcfunParser(json) - expect(comments.length).toBe 155 - expect(comments[0]).toEqual - stime: 98200 - color: 16777215 - mode: 1 - size: 25 - hash: 'guest' - date: 1315564729 - position: 'absolute' - text: '我谢了你的爱' + jasmine.getFixtures().fixturesPath = "test/synthetic/" + textfix = (text) -> text.replace(/\ /g, "\u00a0") + + it 'provides json parser', -> + expect(typeof AcfunFormat.JSONParser).toBe "function" + + describe '.JSONParser', -> + raw = readFixtures 'AcfunFormat.json' + parser = data = null + + beforeEach -> + parser = new AcfunFormat.JSONParser() + data = JSON.parse(raw) + + it 'can parse one', -> + expect(parser.parseOne(data[0])).toEqual + stime: 1000 + color: 16763904 + mode: 5 + size: 25 + hash: 'guest' + date: 1315736602.0 + position: 'absolute' + text: textfix 'This is just some test.' + + it 'can parse list', -> + comments = parser.parseMany(data) + expect(comments.length).toBe 2 + expect(comments[0]).toEqual + stime: 1000 + color: 16763904 + mode: 5 + size: 25 + hash: 'guest' + date: 1315736602.0 + position: 'absolute' + text: textfix 'This is just some test.' diff --git a/spec/parsers/BilibiliFormat_spec.coffee b/spec/parsers/BilibiliFormat_spec.coffee index ca3e54f..56dd5d6 100644 --- a/spec/parsers/BilibiliFormat_spec.coffee +++ b/spec/parsers/BilibiliFormat_spec.coffee @@ -1,35 +1,103 @@ 'use strict' describe 'BilibiliFormat', -> jasmine.getFixtures().fixturesPath = "test/" - it 'parses normal comments', -> - # TODO: Update testing to pass in an XML object instead of - # relying on the unsafe innerHTML. - xml_text = readFixtures 'av207527.xml' - comments = BilibiliParser(null, xml_text) - expect(comments.length).toBe 12546 - expect(comments[0]).toEqual - stime: 15105 - size: 25 - color: 16777215 - mode: 1 - date: 1388314569 - pool: 0 - position: 'absolute' - dbid: 364586099 - hash: '1a87dd40' - border: false - text: '关了弹幕瞬间好多了' - - it 'parses scripting comments', -> - xml_text = readFixtures 'scripting/tsubasa.xml' - comments = BilibiliParser(null, xml_text) - expect(comments.length).toBe 654 - expect(comments[0].mode).toEqual 7 - expect(comments[653].mode).toEqual 8 - - it 'parses advanced comments', -> - xml_text = readFixtures 'boss.xml' - comments = BilibiliParser(null, xml_text) - expect(comments.length).toBe 1000 - expect(comments[0].mode).toEqual 7 - expect(comments[0].motion).not.toBe null + + it 'provides xml parser', -> + expect(typeof BilibiliFormat.XMLParser).toBe 'function' + + it 'provides text parser', -> + expect(typeof BilibiliFormat.TextParser).toBe 'function' + + describe '.XMLParser', -> + parser = null + + beforeEach -> + parser = new BilibiliFormat.XMLParser() + + it 'has sane defaults', -> + expect(parser._attemptFix).toBe true + expect(parser._logBadComments).toBe true + + it 'can be configured', -> + parser = new BilibiliFormat.XMLParser + attemptFix: false + logBadComments: false + expect(parser._attemptFix).toBe false + expect(parser._logBadComments).toBe false + + it 'only accepts xml documents', -> + expect( => parser.parseOne "foo").toThrow() + + it 'can parse one', -> + xmltext = readFixtures 'av207527.xml' + dom = (new DOMParser()).parseFromString xmltext, "application/xml" + expect(parser.parseOne dom.getElementsByTagName('d')[0]).toEqual + stime: 15105 + size: 25 + color: 16777215 + mode: 1 + date: 1388314569 + pool: 0 + position: 'absolute' + dbid: 364586099 + hash: '1a87dd40' + border: false + text: '关了弹幕瞬间好多了' + + it 'can parse many', -> + xmltext = readFixtures 'av207527.xml' + dom = (new DOMParser()).parseFromString xmltext, "application/xml" + comments = parser.parseMany dom + expect(comments.length).toBe 12546 + expect(comments[0]).toEqual + stime: 15105 + size: 25 + color: 16777215 + mode: 1 + date: 1388314569 + pool: 0 + position: 'absolute' + dbid: 364586099 + hash: '1a87dd40' + border: false + text: '关了弹幕瞬间好多了' + + describe '.TextParser', -> + parser = null + + beforeEach -> + parser = new BilibiliFormat.TextParser() + + it 'has sane defaults', -> + expect(parser._allowInsecureDomParsing).toBe true + expect(parser._attemptEscaping).toBe true + + it 'can be configured', -> + parser = new BilibiliFormat.TextParser + allowInsecureDomParsing: false + attemptEscaping: false + expect(parser._allowInsecureDomParsing).toBe false + expect(parser._attemptEscaping).toBe false + + it 'propagates parameters', -> + parser = new BilibiliFormat.TextParser + attemptFix: false + logBadComments: false + allowInsecureDomParsing: true + expect(parser._xmlParser instanceof BilibiliFormat.XMLParser).toBe true + expect(parser._xmlParser._attemptFix).toBe false + expect(parser._xmlParser._logBadComments).toBe false + +# it 'parses scripting comments', -> +# xml_text = readFixtures 'scripting/tsubasa.xml' +# comments = BilibiliParser(null, xml_text) +# expect(comments.length).toBe 654 +# expect(comments[0].mode).toEqual 7 +# expect(comments[653].mode).toEqual 8 + +# it 'parses advanced comments', -> +# xml_text = readFixtures 'boss.xml' +# comments = BilibiliParser(null, xml_text) +# expect(comments.length).toBe 1000 +# expect(comments[0].mode).toEqual 7 +# expect(comments[0].motion).not.toBe null diff --git a/src/parsers/BilibiliFormat.js b/src/parsers/BilibiliFormat.js index ceba10a..06a56a2 100644 --- a/src/parsers/BilibiliFormat.js +++ b/src/parsers/BilibiliFormat.js @@ -49,7 +49,11 @@ var BilibiliFormat = (function () { } BilibiliFormat.XMLParser.prototype.parseOne = function (elem) { - var params = elem.getAttribute('p').split(','); + try { + var params = elem.getAttribute('p').split(','); + } catch (e) { + throw new Error("Unsupported object type or could not decompose."); + } if (!elem.childNodes[0]) { // Not a comment or nested comment, skip return null; @@ -232,7 +236,7 @@ var BilibiliFormat = (function () { for (var i = 0; i < elements.length; i++) { var comment = this.parseOne(elements[i]); if (comment !== null) { - commentList.push(); + commentList.push(comment); } } return commentList; @@ -241,6 +245,7 @@ var BilibiliFormat = (function () { BilibiliFormat.TextParser = function (params) { this._allowInsecureDomParsing = true; this._attemptEscaping = true; + this._canSecureParse = false; if (typeof params === 'object') { this._allowInsecureDomParsing = params.allowInsecureDomParsing === false ? false : true; this._attemptEscaping = params.attemptEscaping === false ? false : true; @@ -249,7 +254,10 @@ var BilibiliFormat = (function () { // We can't rely on innerHTML anyways. Maybe we're in a restricted context (i.e. node). this._allowInsecureDomParsing = false; } - if (this._allowInsecureDomParsing) { + if (typeof DOMParser !== 'undefined' && DOMParser !== null) { + this._canSecureNativeParse = true; + } + if (this._allowInsecureDomParsing || this._canSecureNativeParse) { this._xmlParser = new BilibiliFormat.XMLParser(params); } }; @@ -269,8 +277,12 @@ var BilibiliFormat = (function () { } else { return this._xmlParser.parseOne(tags[0]); } - } else { - throw new Error('Secure parsing not implemented yet.'); + } else if (this._canSecureNativeParse) { + var domParser = new DOMParser(); + return this._xmlParser.parseOne( + domParser.parseFromString(comment, 'application/xml')); + } else{ + throw new Error('Secure native js parsing not implemented yet.'); } }; @@ -285,8 +297,13 @@ var BilibiliFormat = (function () { temp.innerHTML = source; var tags = temp.getElementsByTagName('d'); return this._xmlParser.parseMany(tags); + } else if (this._canSecureNativeParse) { + var domParser = new DOMParser(); + return this._xmlParser.parseMany( + domParser.parseFromString(comment, 'application/xml')); + } else { - throw new Error('Secure parsing not implemented yet.'); + throw new Error('Secure native js parsing not implemented yet.'); } }; diff --git a/test/Readme.md b/test/Readme.md index 8213827..a67ce9f 100644 --- a/test/Readme.md +++ b/test/Readme.md @@ -91,3 +91,7 @@ * `scripting/*.biliscript` 测试代码弹幕的各种小脚本 + +* `synthetic/*` + + 人造弹幕文件,目标是测试到所有的属性的解析 diff --git a/test/synthetic/AcfunFormat.json b/test/synthetic/AcfunFormat.json new file mode 100644 index 0000000..500f108 --- /dev/null +++ b/test/synthetic/AcfunFormat.json @@ -0,0 +1,10 @@ +[ + { + "c":"1,16763904,5,25,guest,1315736602.0", + "m":"This is just some test." + }, + { + "c":"1,16777215,1,25,guest,1315736602.0", + "m":"Comment 2." + } +] diff --git a/test/synthetic/BilibiliFormat.xml b/test/synthetic/BilibiliFormat.xml new file mode 100644 index 0000000..86e1508 --- /dev/null +++ b/test/synthetic/BilibiliFormat.xml @@ -0,0 +1,4 @@ + + + 这是一个测试 + diff --git a/test/synthetic/CommonDanmakuFormat.json b/test/synthetic/CommonDanmakuFormat.json new file mode 100644 index 0000000..1270311 --- /dev/null +++ b/test/synthetic/CommonDanmakuFormat.json @@ -0,0 +1,27 @@ +[ + { + "mode": 1, + "text": "This is a normal scrolling comment. Color is white.", + "size": 25, + "color": 16777215, + "stime": 0 + }, + { + "mode": 1, + "text": "This is a normal scrolling comment. Size is large", + "size": 60, + "color": 16777215, + "stime": 100 + }, + { + "mode": 1, + "text": "This is a normal scrolling comment. Color is red.", + "size": 25, + "color": 16711680, + "stime": 200 + }, + { + "mode": 2, + "text": "This is a normal " + } +]