function arrayUnique(arr){
return arr.filter((e,i,a)=>a.indexOf(e)==i)
}
// test
console.info(arrayUnique([1, 2, 1, 10, 5, 3, 4, 40, 50])) // -> [1, 2, 10, 5, 3, 4, 40, 50]
console.info(arrayUnique([1, 2, 3, 1, 2, 33, 33, 55, 66])) // -> [1, 2, 3, 33, 55, 66]
console.info(arrayUnique(['privet', 'privet', 'kakdela'])) // -> ["privet", "kakdela"]
var fs = null;
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(window.PERSISTENT, 2*1024*1024, function(f) {
f = fs;
download(fs, "http://yourdomain.com/example.gif","example.gif",function(){/*success*/},function(){/*fail*/});
});
function download(fs,url,file,win,fail) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.responseType = "blob";
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if(xhr.status === 200){
fs.root.getFile(file,{create:true},function(fileEntry){
fileEntry.createWriter(function(writer){
writer.onwriteend = win;
writer.onerror = fail;
writer.write(xhr.response);
})
},fail)
} else {
fail(xhr.status);
}
}
};
xhr.send();
return xhr;
};
$.post('/getImages.php', {
url: 'http://site.com/images/image.jpg'
}, function (data) {
// Сохраняем изображения
// Правда признаюсь - это извращение ;)
}, 'JSON');
<?php
$url = $_POST['url'];
$filename = end('/', $url);
$path = __DIR__ . '/images_cache/';
file_put_contents($path . $filename, file_get_contents($url));
json_encode([
'image' => '/images_cache/' . $filename,
'filename' => $filename
]);
div { width:90px; height:90px;
position:fixed; z-index:2; left:0; top:0;
-webkit-animation-name: 'anime';
-webkit-animation-duration: 1000ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: normal;
-webkit-animation-timing-function: linear;
animation-name: 'anime';
animation-duration: 1000ms;
animation-iteration-count: infinite;
animation-direction: normal;
animation-timing-function: linear;
background:#1E800E;}
@-webkit-keyframes 'anime' {
from {left:0}
50% {left:60px}
60% {left:50px}
70% {left:60px;}
to {left:0px}
}