/**
* SL
*/
liberator.plugins.SL = (function(){
function xmlToDom(xml, xmlns){
if (!xmlns) xmlns = xulNS;
XML.ignoreWhitespace = true;
XML.prettyPrinting = false;
var doc = (new DOMParser).parseFromString('' + xml.toXMLString() + "", "application/xml")
var imported = document.importNode(doc.documentElement, true);
var range = document.createRange();
range.selectNodeContents(imported);
var fragment = range.extractContents();
range.detach();
return fragment.childNodes.length > 1 ? fragment : fragment.firstChild;
}
function getFullScreenAttr(){
let s = window.screen;
return {
top: s.top,
left: s.left,
width: s.availWidth,
height: s.availHeight
};
}
function SL(){ this.init.apply(this, arguments); }
SL.prototype = { // {{{
init: function(elm, width, height, fontSize, frameRate, speed){
this.canvas = elm;
this.width = width + 10;
this.height = height;
this.fontSize = fontSize || 20;
this.frameRate = frameRate || 60;
this.speed = speed || 20;
this.interval = null;
this.slWidth = null;
this.slPositionY = 0;
this.count = 0;
this.rotateRadian = 0;
this.ctx = this.canvas.getContext("2d");
this.ctx.clearRect(0,0, this.width, this.height);
elm.setAttribute("width", this.width);
elm.setAttribute("height", this.height);
},
start: function(isLogo, isAccident, isFly, isLuckyStar){
this.isFly = isFly || false;
this.ctx.clearRect(0,0, this.width, this.height);
this.ctx.font = this.fontSize + 'px monospace';
if (isFly){
let len = Math.sqrt(Math.pow(this.width, 2) + Math.pow(this.height, 2));
this.rotateRadian = Math.acos(this.width / len);
this.width = len;
}
if (isLuckyStar){
luckyStar.init(this.ctx, this.width, this.height);
}
//this.slWidth = isLogo ? this.ctx.mozMeasureText(this.slData.logo[0] + this.slData.lcoal[0] + this.slData.lcar[0]) :
// this.ctx.mozMeasureText(this.slData.body[0] + this.slData.coal[0]);
this.slWidth = isLogo ? this.ctx.measureText(this.slData.logo[0] + this.slData.lcoal[0] + this.slData.lcar[0]).width :
this.ctx.measureText(this.slData.body[0] + this.slData.coal[0]).width;
this.slPositionY = this.getSLPositionY();
let sl = this.slGenerator(isLogo);
let self = this;
this.interval = window.setInterval(function(){
self.draw(sl, isLuckyStar);
}, this.frameRate);
},
getSLPositionY: function(){
return (this.height - (this.slData.steam[0].length + this.slData.body.length + this.slData.wheel[0].length) * this.fontSize) / 2;
},
draw: function(gene, isLuckyStar){
this.count++;
this.ctx.clearRect(0,0, this.width, this.height);
this.ctx.save();
this.ctx.fillStyle = "rgba(0,0,0,0.8)";
this.ctx.fillRect(0, 0, this.width, this.height);
if (this.isFly){
this.ctx.rotate(this.rotateRadian);
this.ctx.translate(0, - this.height/2);
}
this.ctx.fillStyle = "rgb(255,255,255)";
let data = gene.next();
let x = this.width - this.count * this.speed,
fontSize = this.fontSize,
baseHeight = this.slPositionY;
data.forEach(function(str, i){
this.ctx.fillText(str, x, baseHeight + (i+1)*fontSize);
}, this);
this.ctx.restore();
if (isLuckyStar){
luckyStar.draw();
}
if (this.count * this.speed > this.width + this.slWidth){
window.clearInterval(this.interval);
plugins.SL.close();
}
},
merge: function(){
let data = [];
Array.slice(arguments).forEach(function($_){
$_.forEach(function(str, i){
if (!data[i]) data[i] = [];
data[i].push(str);
});
});
return data.map(function($_) $_.join(""));
},
slGenerator: function(isLogo){
let steam = this.createGenerator(this.slData.steam);
if (isLogo){
let sl = this.slData.logo;
let wheel = this.createGenerator(this.slData.logoWheel);
let coal = this.slData.lcoal;
let car = this.slData.lcar;
while(true){
yield [].concat(steam.next(), this.merge(sl.concat(wheel.next()), coal, car, car));
}
} else {
let sl = this.slData.body;
let wheel = this.createGenerator(this.slData.wheel);
let coal = this.slData.coal;
// Vimperator plugin: Ubiquity
// Maintainer: mattn <mattn.jp@gmail.com> - http://mattn.kaoriya.net
// Require: Ubiquity - https://wiki.mozilla.org/Labs/Ubiquity
// Usage:
// :ubiquity command... - show Ubiquity's command dialog.
// :ubiquity! command... - run Ubiquity's command.
(function() {
if (typeof gUbiquity === 'undefined') return;
liberator.commands.addUserCommand(["ubiquity"], "Ubiquity",
function(arg, special){
var anchor = document.getElementById("content");
if (window.location == "chrome://browser/content/browser.xul")
anchor = anchor.selectedBrowser;
gUbiquity.openWindow(anchor);
gUbiquity.__textBox.value = arg||'';
var context = gUbiquity.__makeContext();
var previewBlock = document.getElementById("cmd-preview").contentDocument.getElementById("preview");
gUbiquity.__cmdManager.updateInput(arg||'', context, previewBlock);
if (special) {
gUbiquity.__cmdManager.execute(context);
gUbiquity.closeWindow();
}
},
{ });
})();