Skip to content

Commit

Permalink
merge branch and update to v2.1 with feature of batch upload
Browse files Browse the repository at this point in the history
  • Loading branch information
suxiaogang committed Jul 7, 2016
1 parent 146b901 commit c211665
Show file tree
Hide file tree
Showing 8 changed files with 1,444 additions and 1,635 deletions.
9 changes: 9 additions & 0 deletions README.MD
Expand Up @@ -4,6 +4,7 @@

#####features
- 支持点选/拖拽/本地粘贴3种方式上传图片至新浪微博图床
- 支持批量上传
- 可选择返回的图片尺寸
- 可生成图片链接,HTML,UBB和Markdown四种格式
- 上传历史浏览和删除.
Expand All @@ -26,6 +27,11 @@
[在作业部落中的使用效果](http://ww4.sinaimg.cn/large/99b8535cjw1f306kv4yljj21gu0oz7cl.jpg)


#####contributors
@liyumeng

@Jackroyal

#####最常被问到的问题
> Q:我上传的图片去哪了?
>
Expand All @@ -42,6 +48,9 @@

#####更新日志
```
2016-07-07 v2.1
支持批量上传(代码由@Jackroyal贡献)
2016-06-28 v2.0
支持自定义Chrome菜单栏图标 (建议使用尺寸接近或者等于38*38的正方形png图片文件)
支持返回https安全协议的图片地址
Expand Down
Binary file removed icon_19_gray.png
Binary file not shown.
Binary file removed icon_38_gray.png
Binary file not shown.
1 change: 0 additions & 1 deletion js/background.js
Expand Up @@ -192,4 +192,3 @@ function pid2url(pid, type) {
}
return url;
}

304 changes: 152 additions & 152 deletions js/option.js
@@ -1,183 +1,183 @@

var storageData = localStorage.weiboData ? JSON.parse(localStorage.weiboData) : [];
var customIconPreview = $('#custom-icon-preview');
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');

Date.prototype.format = function(format) {
var date = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S+": this.getMilliseconds()
};
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1
? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
var date = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S+": this.getMilliseconds()
};
if (/(y+)/i.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var k in date) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
}
}
return format;
}

function buildHtml() {
var html = '';
var imageitemtemplate = $('#image-item-template').html();
var imageitemtemplate = $('#image-item-template').html();
for (var i = 0; i < storageData.length; i++) {
var item = storageData[i];
var timestamp = item.date;
var src = item.imgsrc;
var thumb = src.replace("large/", "bmiddle/");
var d = new Date(timestamp);
var timestamp = item.date;
var src = item.imgsrc;
var thumb = src.replace("large/", "bmiddle/");
var d = new Date(timestamp);
html += imageitemtemplate
.replace(/{{imgsrcthumb}}/g, thumb)
.replace(/{{date}}/g, d.format('yyyy-MM-dd h:m'))
.replace(/{{d}}/g, timestamp)
.replace(/{{imgsrc}}/g, src);
.replace(/{{imgsrcthumb}}/g, thumb)
.replace(/{{date}}/g, d.format('yyyy-MM-dd h:m'))
.replace(/{{d}}/g, timestamp)
.replace(/{{imgsrc}}/g, src);
}
$('.box').html('<h5>上传历史</h5>' + html);
if(localStorage.customIcon == undefined){
$('input:checkbox[id="defaultIcon"]').prop("checked", true);
customIconPreview.attr('src', 'icon_38.png');
} else {
$('input:checkbox[id="customIcon"]').prop("checked", true);
customIconPreview.attr('src', localStorage.customIconBase64);
}
if (localStorage.customIcon == undefined) {
$('input:checkbox[id="defaultIcon"]').prop("checked", true);
customIconPreview.attr('src', 'icon_38.png');
} else {
$('input:checkbox[id="customIcon"]').prop("checked", true);
customIconPreview.attr('src', localStorage.customIconBase64);
}
}

function removeImgItem(d) {
for (var i = 0; i < storageData.length; i++) {
for (var i = 0; i < storageData.length; i++) {
var item = storageData[i];
var timestamp = item.date;
if(timestamp == d) {
storageData.splice(i, 1);
localStorage.weiboData = JSON.stringify(storageData);
return;
}
var timestamp = item.date;
if (timestamp == d) {
storageData.splice(i, 1);
localStorage.weiboData = JSON.stringify(storageData);
return;
}
}
}

$(document).ready(function(){

$('.close').on('click', function () {
event.preventDefault();
window.close();
});

$('.donate').on('click', function () {
swal({ title: "扫码捐助",
text: '<img width="200" height="200" src="http://ww2.sinaimg.cn/large/5fd37818gw1f46gp47ynsj20dw0dwq4i.jpg">'+
'<span style="margin:10px;">或</span>'+
'<img width="200" height="200" src="http://ww3.sinaimg.cn/large/5fd37818gw1f46gph7932j20dw0dwmz6.jpg">',
html: true
});
});
$(".donate").hover(
function(){
$(this).addClass('blinking');
},
function(){
$(this).removeClass('blinking');
});

$(document).ready(function() {

// Build HTML on load
buildHtml();

$(".fancybox").fancybox({
maxWidth : 1000,
openEffect : 'fade',
closeEffect : 'elastic',
helpers : {
title : {
type : 'inside'
}
}
$('.close').on('click', function() {
event.preventDefault();
window.close();
});

$(".imgsrc").hover(
function () {
$(this).select();
},
function () {
$(this).blur();
}
);
$('.donate').on('click', function() {
swal({
title: "扫码捐助",
text: '<img width="200" height="200" src="http://ww2.sinaimg.cn/large/5fd37818gw1f46gp47ynsj20dw0dwq4i.jpg">' +
'<span style="margin:10px;">或</span>' +
'<img width="200" height="200" src="http://ww3.sinaimg.cn/large/5fd37818gw1f46gph7932j20dw0dwmz6.jpg">',
html: true
});
});
$(".donate").hover(
function() {
$(this).addClass('blinking');
},
function() {
$(this).removeClass('blinking');
});


// Build HTML on load
buildHtml();

$(".fancybox").fancybox({
maxWidth: 1000,
openEffect: 'fade',
closeEffect: 'elastic',
helpers: {
title: {
type: 'inside'
}
}
});

$('#defaultIcon').click(function(){
$('input:checkbox[id="customIcon"]').prop("checked", false);
$('input:checkbox[id="defaultIcon"]').prop("checked", true);
customIconPreview.attr('src', 'icon_38.png');
localStorage.removeItem('customIcon');
localStorage.removeItem('customIconBase64');
});
$('#customIcon').click(function(){
$('#custom-icon-file').trigger('click');
$('input:checkbox[id="customIcon"]').prop("checked", false);
});
$(".imgsrc").hover(
function() {
$(this).select();
},
function() {
$(this).blur();
}
);

$('#defaultIcon').click(function() {
$('input:checkbox[id="customIcon"]').prop("checked", false);
$('input:checkbox[id="defaultIcon"]').prop("checked", true);
customIconPreview.attr('src', 'icon_38.png');
localStorage.removeItem('customIcon');
localStorage.removeItem('customIconBase64');
});
$('#customIcon').click(function() {
$('#custom-icon-file').trigger('click');
$('input:checkbox[id="customIcon"]').prop("checked", false);
});

canvas.width = canvas.height = 38;
var dontLoad = true;
customIconPreview.on('load', function () {
if (dontLoad){
dontLoad = false;
return;
}
if(customIconPreview.attr('src') == 'icon_38.png') {
return;
}
ctx.clearRect(0, 0, 38, 38);
ctx.drawImage(document.getElementById("custom-icon-preview"),0,0,38,38);
var imageData = ctx.getImageData(0, 0, 38, 38);
chrome.browserAction.setIcon({imageData: imageData});
localStorage.customIcon = JSON.stringify(imageData.data);
});
canvas.width = canvas.height = 38;
var dontLoad = true;
customIconPreview.on('load', function() {
if (dontLoad) {
dontLoad = false;
return;
}
if (customIconPreview.attr('src') == 'icon_38.png') {
return;
}
ctx.clearRect(0, 0, 38, 38);
ctx.drawImage(document.getElementById("custom-icon-preview"), 0, 0, 38, 38);
var imageData = ctx.getImageData(0, 0, 38, 38);
chrome.browserAction.setIcon({ imageData: imageData });
localStorage.customIcon = JSON.stringify(imageData.data);
});

var customIconFile = document.getElementById('custom-icon-file');
customIconFile.addEventListener('change', function(){
var files = this.files;
if (files && files.length){
var file = files[0];
if (/image\/[a-z]+/i.test(file.type)){
reader = new FileReader();
reader.onload = function(e){
var result = e.target.result;
customIconPreview.attr('src', result);
swal({title: "Woo~!", text: "图标更换成功.", timer:2000, showConfirmButton:false});
localStorage.customIconBase64 = result;
$('input:checkbox[id="customIcon"]').prop("checked", true);
$('input:checkbox[id="defaultIcon"]').prop("checked", false);
};
reader.readAsDataURL(files[0]);
} else {
alert('Not an image. Try another one.');
$('input:checkbox[id="customIcon"]').prop("checked", true);
$('input:checkbox[id="defaultIcon"]').prop("checked", false);
}
}
});
var customIconFile = document.getElementById('custom-icon-file');
customIconFile.addEventListener('change', function() {
var files = this.files;
if (files && files.length) {
var file = files[0];
if (/image\/[a-z]+/i.test(file.type)) {
reader = new FileReader();
reader.onload = function(e) {
var result = e.target.result;
customIconPreview.attr('src', result);
swal({ title: "Woo~!", text: "图标更换成功.", timer: 2000, showConfirmButton: false });
localStorage.customIconBase64 = result;
$('input:checkbox[id="customIcon"]').prop("checked", true);
$('input:checkbox[id="defaultIcon"]').prop("checked", false);
};
reader.readAsDataURL(files[0]);
} else {
alert('Not an image. Try another one.');
$('input:checkbox[id="customIcon"]').prop("checked", true);
$('input:checkbox[id="defaultIcon"]').prop("checked", false);
}
}
});

$('.page-content').bind('contextmenu', function(e) {
e.preventDefault();
var d = $(this).attr("d");
var div = $(this).parent();
swal({title: "确定要删除吗?",
text: "",
type: "error",
showCancelButton: true,
cancelButtonText: "取消",
confirmButtonColor: "#D9534F",
confirmButtonText: "删除"
}, function(){
div.fadeOut("fast");
removeImgItem(d);
});
});
$('.page-content').bind('contextmenu', function(e) {
e.preventDefault();
var d = $(this).attr("d");
var div = $(this).parent();
swal({
title: "确定要删除吗?",
text: "",
type: "error",
showCancelButton: true,
cancelButtonText: "取消",
confirmButtonColor: "#D9534F",
confirmButtonText: "删除"
}, function() {
div.fadeOut("fast");
removeImgItem(d);
});
});

});

0 comments on commit c211665

Please sign in to comment.