>8)&0xFF)};var writePixels=function writePixels(){var myencoder=new LZWEncoder(width,height,indexedPixels,colorDepth);myencoder.encode(out)};var stream=exports.stream=function stream(){return out};var setProperties=exports.setProperties=function setProperties(has_start,is_first){started=has_start;firstFrame=is_first};return exports};
// Lap
// 1.0
// 1.1 重写脚本,修正跨域问题
// 1.2 修正翻页、回贴后按钮消失问题
// 1.3 修正被重定向的图片无法获取的问题
// 1.4 添加支持图片插入文本,整合柏拉图样图森破的效果
// 看了柏拉图样图森破的脚本,原来GM_xmlhttpRequest就支持跨域,我真是想多了
(function() {
var contain = {
id: 'LapContain',
title: '\u0028\u0E51\u2022\u0300\u3142\u2022\u0301\u0029\u0648\u2727',
width: 689,
height: 426,
left: function() {
return (document.documentElement.clientWidth / 2 - this.width / 2).toFixed(1) + 'px'
},
top: function() {
return (document.documentElement.clientHeight / 2 - this.height / 2).toFixed(1) + 'px'
}
};
var face = {};
var imageList = {};
var getImage = function(u, n, c) {
var x = createElement('IFRAME', {style:'display:none'});
x.onload = function() {
x.contentWindow.postMessage(n, '*');
var t = setInterval(function() {
if (!imageList[n]) {
return
};
var i = new Image();
i.onload = function() {
c(this)
};
i.src = URL.createObjectURL(imageList[n]);
x.parentNode.removeChild(x), clearInterval(t)
}, 1);
};
x.src = u;
document.documentElement.appendChild(x)
};
var postImage = function(b, c) {
var t = new XMLHttpRequest();
t.open('GET', 'http://tieba.baidu.com/dc/common/imgtbs', true);
t.onreadystatechange = function() {
t.readyState == 4 && (function(tbs) {
var f = new FormData(), x = new XMLHttpRequest();
f.append('file', b);
f.append('tbs', tbs);
x.open('POST', 'http://upload.tieba.baidu.com/upload/pic', true);
x.onreadystatechange = function() {
x.readyState == 4 && (function(i) {
c(i.pic_water.replace(/.*(\/[a-z0-9]{40}.jpg)$/, 'http://imgsrc.baidu.com/forum/pic/item/$1'), i.fullpic_width, i.fullpic_height)
})(JSON.parse(x.responseText).info)
};
x.withCredentials = true;
x.send(f)
})(JSON.parse(t.responseText).data.tbs)
};
t.send()
};
var madeImage = function(l, x, y, m, c) {
var t = this, u = arguments, a = 'image/jpeg', b = t.getContext('2d'), k = lapList[l].layer, v = k[x][y], n, s, f = function(i) {
y == 0 && (x == 1 && (m = new GIFEncoder(), a = 'image/gif', m.setRepeat(lapList[l].repeat || 0), m.setDelay(lapList[l].delay || 84), m.start(), !1) || x > 0 && m.addFrame(b));
b.save();
v.r && b.rotate(v.r);
v.style && (function() {
for (var j in v.style) {
j == 'strokeStyle' && (v.stroke = 1);
b[j] = v.style[j]
}
})();
v.text && (!v.stroke ? b.fillText(replaceText(v.text), v.x || 0, v.y || 0) : b.strokeText(replaceText(v.text), v.x || 0, v.y || 0));
i && b.drawImage(i, v.x || 0, v.y || 0, v.w || t.width, v.h || t.height);
b.restore();
y = y < k[x].length - 1 ? y + 1 : (++x, 0);
x < (!m ? 1 : k.length) ? madeImage.apply(t, u) : (c && c(toBlob((typeof(m) == 'object' ? (m.addFrame(b), m.finish(), m.stream().bin) : Array.prototype.map.call(atob(t.toDataURL(a).replace('data:' + a + ';base64,', '')), function(x) {return x.charCodeAt(0) & 0xff})), a)))
};
x == 0 && y == 0 && (t.height = lapList[l].height, t.width = lapList[l].width);
if (v.text) {
return f()
};
v.src == '[FACE]' ? (n = v.src, s = face.src) : (n = encodeURIComponent(l) + '&' + x + '&' + y, s = v.src);
getImage(s, n, f)
};
var toBlob = function(s, f) {
return new Blob([new Uint8Array(s).buffer], {type: f})
};
var createElement = function(e, s) {
e = document.createElement(e), s = s || {};
for (var i in s) {
e.setAttribute(i, s[i])
};
return e
};
var removeContain = function(e) {
var d = document.getElementById(contain.id);
return d && (e && (e.preventDefault(), e.stopPropagation()) || d.parentNode.removeChild(d), !0)
};
var replaceText = function(t) {
return t.replace(/\[FLOOR\]/g, face.floor).replace(/\[NAME\]/g, face.name).replace(/\[LEVEL\]/g, face.lid).replace(/\[LEVEL_NAME\]/g, face.lname).replace(/\[FOURM_NAME\]/g, !face.fname ? '\u65E0\u540D' : face.fname.getAttribute('fname'))
};
var createContain = function(e) {
var i, j, t, d, o;
removeContain();
d = createElement('DIV', {id: contain.id, class: 'dialogJ dialogJfix dialogJshadow ui-draggable', style: 'z-index:60001;width:' + contain.width + 'px;left:' + contain.left() + ';top:' + contain.top()});
d.innerHTML = '';
document.body.appendChild(d);
o = e.target.parentNode, face.src = o.querySelector('.p_author_face>IMG').src + '?t=' + (new Date()).getTime();
o = JSON.parse(o.parentNode.parentNode.parentNode.parentNode.getAttribute('data-field')), imageList['[FACE]'] = null;
face.floor = o.content.post_no, face.name = o.author.user_name, face.lid = o.author.level_id, face.lname = o.author.level_name, face.fname = document.querySelector('META[fname]');
i = document.querySelector('#' + contain.id + ' .dialogJbody');
for (j in lapList) {
t = createElement('CANVAS', {style: 'cursor:pointer'});
i.appendChild(createElement('DIV', {class: 'lapContent', data: j, style: 'float:left;margin:3px'})).appendChild(t);
madeImage.call(t, j, 0, 0, 0)
}
};
var createButton = function() {
var f = document.querySelectorAll('.icon_relative');
for (var i = f.length - 1; i > -1; i--) {
var j = f[i].appendChild(createElement('DIV', {class: 'LAP_BUTTON', style: 'position:absolute;right:0;bottom:0;background-color:#eee;padding:0 3px 0 3px;border-radius:2px;box-shadow:0 0 1px #333'}));
j.addEventListener('click', createContain, false);
j.textContent = '\u8214'
}
};
if (location.hostname != 'tieba.baidu.com') {
window.addEventListener('message', function(e) {
var i = new Image();
i.onload = function() {
var c = document.createElement('canvas');
c.width = this.width, c.height = this.height;
c.getContext('2d').drawImage(this, 0, 0);
window.parent.postMessage(e.data + '!IMAGE_DATA!' + c.toDataURL(), '*')
};
i.src = location.href;
}, false);
return
};
window.addEventListener('message', function(e) {
if (e.data.indexOf('!IMAGE_DATA!') == -1) {
return
};
e = e.data.split('!IMAGE_DATA!');
imageList[e[0]] = toBlob(Array.prototype.map.call(atob(e[1].replace('data:image/png;base64,', '')), function(x) {return x.charCodeAt(0) & 0xff}), 'image/png');
}, false);
window.addEventListener('resize', function() {
var d = document.getElementById(contain.id);
d && (d.style.left = contain.left(), d.style.top = contain.top())
}, false);
document.addEventListener('click', function(e) {
e.target.className.indexOf('dialogJclose') != -1 && removeContain(e);
e.target.parentNode.className.indexOf('lapContent') != -1 && removeContain(e) && (function() {
var i = e.target.parentNode.getAttribute('data');
window.scrollTo(0, 0xffffff);
madeImage.call(createElement('CANVAS'), i, 0, 0, 1, function(b) {
postImage(b, function(u, w, h) {
document.getElementById('ueditor_replace').innerHTML += (lapList[i].text ? '' + replaceText(lapList[i].text) + '
' : '') + '
' + (lapList[i].afterText ? '' + replaceText(lapList[i].afterText) + '
' : '')
})
})
})()
}, false);
(function() {
var f = function() {
!document.querySelector('.LAP_BUTTON') && createButton()
};
(new MutationObserver(f)).observe(document, {childList: true, subtree: true});
f()
})()
})();