Browse files

download

  • Loading branch information...
1 parent 8d074ec commit e77fb7a4ca1e2483aa36264ece11e7405f88d666 Fan Yu committed Aug 9, 2012
Showing with 63 additions and 6 deletions.
  1. +7 −0 base.js
  2. +56 −6 contentscript.js
View
7 base.js
@@ -1,6 +1,13 @@
console.log("base script loaded");
var imges = [];
var imgUrls = [];
+imges.contains = function (arr) {
+ for (var i = 0; i < this.length; i++) {
+ if (this[i] == arr)
+ return true;
+ }
+ return false;
+}
$("<div/>").attr({ id: "div_oprationpanel" })
.css({
border: "solid 1px green",
View
62 contentscript.js
@@ -1,19 +1,51 @@
console.log("content script loaded");
-imges.contains = function (arr) {
- for (var i = 0; i < this.length; i++) {
- if (this[i] == arr)
- return true;
+function showImgSaveBtn(img) {
+ var btn = $(img).next();
+ if (btn && btn.html() == "save") {
+ btn.show();
+ }
+ else {
+ var offset = $(img).offset();
+ var w = $(img).outerWidth(false);
+ var h = $(img).outerHeight(false);
+ $("<div/>").css({
+ background: "orange",
+ width: "40px",
+ height: "20px",
+ position: "absolute",
+ top: offset.top + h - 20 + "px",
+ left: offset.left + w + "px",
+ cursor: "pointer",
+ textAlign: "center"
+ }).html('<a href="'+img.src+'" download>save</a>').hover(function (event) {
+ $(this).show();
+ $(img).css("border", "5px solid orange");
+ },
+ function (event) {
+ $(this).hide();
+ $(img).css("border", "");
+ }).insertAfter($(img));
+ }
+
+}
+
+
+function hideImgSaveBtn(img) {
+ var btn = $(img).next();
+ if (btn && btn.html() == "save") {
+ btn.hide();
}
- return false;
}
function addborder(event) {
$(this).css("border", "5px solid orange");
+ showImgSaveBtn(this);
}
function removeborder(event) {
if (!imges.contains(this)) {
$(this).css("border", "");
}
+ hideImgSaveBtn(this);
}
$("img").hover(addborder, removeborder);
@@ -26,4 +58,22 @@ $("img").bind("click", function (event) {
imges.splice($.inArray(this, imges), 1);
$(this).css("border", "");
}
-});
+});
+function downLoadImg(imgurl) {
+ var images_container = $('#image_saveBtn_images_container');
+ if (!images_container[0]) {
+ images_container = $('div').attr({ id: 'image_downloader_images_container' }).css({display:'none'});
+ }
+ images_container.appendTo($(document.body));
+
+ var anchor = $("<a/>").attr({
+ href: imgurl,
+ download: ''
+ });
+
+ anchor.appendTo(images_container);
+
+ anchor.click();
+
+ images_container.remove();
+}

0 comments on commit e77fb7a

Please sign in to comment.