/www/wwwroot/cloud.lincq.cn/代码整理/layui开发的云盘/static/embed.jslayui.use(['layer','element'], function(){
var layer = layui.layer;
var element = layui.element;
});
protocol = window.location.protocol; //获取协议
host = window.location.host; //获取主机
pageurl = protocol + '//' + host + '/';
$(document).ready(function(){
msg();
});
//清空内容
function clear_msg(){
$("#msg-content").empty();
}
function msg(){
var content = new Array();
content[0] = '欢迎来到LINCQ的静态资源站( ̄▽ ̄)"';
content[1] = '~~~本站提供百兆带宽下载哦~~~。';
var num = parseInt(Math.random()*(content.length)+0,10);
$("#msg-content").append(content[num]);
window.setTimeout("clear_msg()",5800);
window.setTimeout("msg()",6000);
}
//复制按钮
function dehash(c1, c2) {
return c1+'("'+unescape(decodeURIComponent(c2))+'")';
}
function enhash(c1, c2) {
return c1+'-(&)-'+encodeURIComponent(escape(c2));
}
function share_qrcode(name, num) {
var url = share_url(num);
qrcodeapi = runPath + 'functions/qrcode.php?url=' + encodeURIComponent(url);
var qrimg = "
";
var index = layer.open({
type: 1,
area: ['260px', 'auto'],
scrollbar: false,
title: name,
content: qrimg
});
}
function share(num) {
var url = share_url(num);
plaincopy(url, '分享链接已复制');
}
function share_url(num) {
var conmand = String(document.getElementById('url' + num).getAttribute('onclick'));
var hv = conmand.match(/^(\w+)\('(.+)'\)$/i), c1, c2;
if(hv[2].split(/',\s?'/)[1]) {
var shv = hv[2].split(/',\s?'/);
console.log(shv);
if(shv[2]) {
c1 = shv[1];
c2 = shv[2];
}else{
c1 = shv[1];
c2 = shv[0];
}
}else{
c1 = hv[1];
c2 = hv[2];
}
var url = window.location.href.split('#')[0] + '#' + enhash(c1, c2);
return url;
}
function copy(url){
url = url.replace("./","");
//重组url
protocol = window.location.protocol; //获取协议
host = window.location.host; //获取主机
dir = window.location.pathname; //获取目录
dir = dir.replace("index.php","");
url = encodeURI(protocol + '//' + (host + dir + url).replace('//', '/'));
//console.log(url);
//获取文件后缀
var index1=url.lastIndexOf(".");
var index2=url.length;
var suffix=url.substring(index1+1,index2);
switch(suffix){
case 'js':
url = "";
break;
case 'css':
url = "";
default:
//如果是图片
if((suffix == 'jpg') || (suffix == 'jpeg') || (suffix == 'gif') || (suffix == 'bmp') || (suffix == 'png')){
url = "
";
}
else{
url = url;
}
break;
}
var copy = new clipBoard(document.getElementById('list'), {
beforeCopy: function() {
},
copy: function() {
return url;
},
afterCopy: function() {
layer.msg('复制成功!');
}
});
}
//复制按钮
function scopy(url){
if (/\.\.\//.test(url) == false) {
url = url.replace("./","");
}else{
url = url;
}
//重组url
protocol = window.location.protocol; //获取协议
host = window.location.host; //获取主机
dir = window.location.pathname; //获取目录
dir = dir.replace("index.php","");
url = encodeURI(protocol + '//' + (host + dir + url).replace('//', '/'));
//console.log(url);
//获取文件后缀
var index1=url.lastIndexOf(".");
var index2=url.length;
var suffix=url.substring(index1+1,index2);
switch(suffix){
case 'js':
url = "";
break;
case 'css':
url = "";
default:
//如果是图片
if((suffix == 'jpg') || (suffix == 'jpeg') || (suffix == 'gif') || (suffix == 'bmp') || (suffix == 'png')){
url = "
";
}
else{
url = url;
}
break;
}
var copy = new clipBoard(document.getElementById('list'), {
beforeCopy: function() {
},
copy: function() {
return url;
},
afterCopy: function() {
layer.msg('复制成功!');
}
});
}
function plaincopy(content, message='复制成功') {
var copy = new clipBoard(document, {
beforeCopy: function() {},
copy: function() {
return content;
},
afterCopy: function() {
layer.msg(message);
}
});
}
function searchreault(url, conmand, curl=false) {
var index = layer.open({
title: '查看详情',
type: 1,
area: ['340px', 'auto'],
scrollbar: false,
btn: ['打开', '取消'],
yes: function(index) {
if(curl == false) {
curl = url;
}
eval(conmand+'("'+curl+'")');
layer.close(index);
},
btn2: function() {},
content: ' 文件路径:'+url+'
'
})
}
//查看markdown文件
function viewmd(url){
window.location.hash = enhash('viewmd', url);
url = url.replace("./","");
var filename = url.split('/').pop();
//重组url
protocol = window.location.protocol; //获取协议
host = window.location.host; //获取主机
url = protocol + '//' + host + '/' + url;
url = 'https://markdown.win/api.php?url=' + url;
var index = layer.open({
title: filename,
type: 2,
area: ['100%', '100%'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = url;
a.download = filename;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: url //这里content是一个普通的String
});
}
//新版markdown查看器
function newmd(url){
window.location.hash = enhash('newmd', url);
var filename = url.split('/').pop();
var url = runPath+"functions/viewmd.php?file=" + url;
var index = layer.open({
title: filename,
type: 2,
area: ['100%', '100%'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = url;
a.download = filename;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: url //这里content是一个普通的String
});
}
//播放视频文件
function video(url){
window.location.hash = enhash('video', url);
var videourl = runPath+"functions/video.php?url=" + url;
var filename = url.split('/').pop();
//layer.msg(videourl);
var index = layer.open({
title: filename,
type: 2,
// closeBtn: 1,
area: ['100%', '100%'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = url;
a.download = filename;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: videourl //这里content是一个普通的String
});
}
//播放音频
function music(url){
window.location.hash = enhash('music', url);
var videourl = runPath+"functions/music.php?url=" + url;
var filename = url.split('/').pop();
//layer.msg(videourl);
var index = layer.open({
title: filename,
type: 2,
area: ['340px', '182px'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = url;
a.download = filename;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: videourl //这里content是一个普通的String
});
}
function image(url) {
window.location.hash = enhash('image', url);
var name = url.split('/').pop();
var index = layer.open({
title: name,
type: 1,
area: ['340px', '340px'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = url;
a.download = name;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: ''
});
}
//查看文本文档
function viewtext(file){
window.location.hash = enhash('viewtext', file);
var filename = file.split('/').pop();
var url = runPath+"functions/viewtext.php?file=" + file;
var index = layer.open({
title: filename,
type: 2,
area: ['100%', '100%'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = runPath+'functions/readplain.php?path='+file;
a.download = filename;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: url //这里content是一个普通的String
});
}
//预览office
function office(url){
window.location.hash = enhash('office', url);
//文件名
filename = url.split('/').pop();
var uri = url.replace("./","/");
uri = encodeURI(uri);
//获取协议
var protocol = window.location.protocol + '//';
//获取主机
var host = window.location.host;
//获取页面目录,通常是二级目录的情况下
var pathname = window.location.pathname;
pathname = pathname.replace("index.php","");
url = protocol + (host + pathname + uri).replace('//', '/');
var apiurl = "https://api.idocv.com/view/url?url=" + url;
//https://preview.tita.com/op/view.aspx?src=
//https://api.idocv.com/view/url?url=
//https://docview.mingdao.com/op/view.aspx?src=
var index = layer.open({
title:filename,
type: 2,
area: ['100%', '100%'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = url;
a.download = filename;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: apiurl //这里content是一个普通的String
});
}
function queryopen(file){
window.location.hash = enhash('queryopen', file);
var filename = file.split('/').pop();
var qfile = file.replace(/^\.(.*)$/i, '$1');
var index = layer.open({
title: '下载文件',
type: 1,
area: ['340px', 'auto'],
scrollbar: false,
btn: ['下载', '分享', '取消'],
yes: function() {
let a = document.createElement("a");
a.href = file;
a.download = filename;
a.target = '_blank';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
},
btn2: function() {
plaincopy(window.location.href, '链接已复制,快去粘贴吧!');
return false;
},
btn3: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
cancel: function(index) {
window.location.hash = 'viewClosed';
layer.close(index);
},
content: ' 您是否需要对['+qfile+']执行下载?
' //这里content是一个普通的String
});
}
//预览PDF文件
//function viewpdf(filepath){
// //重组url
// protocol = window.location.protocol; //获取协议
// host = window.location.host; //获取主机
// url = protocol + '//' + host + '/' + url;
// alert(url);
//}
//计算文件hash
function filehash(name,path){
var file = path;
//alert(file);
$.post(runPath+"functions/hash.php",{file:file},function(data,status){
var fileinfo = eval('(' + data + ')');
if(fileinfo.code == 1){
var index = layer.open({
title:name,
area: ['340px', 'auto'],
scrollbar: false,
content: 'md5: ' + fileinfo.md5 + '
sha1: ' + fileinfo.sha1
});
}
else{
layer.msg(fileinfo.msg);
}
});
}
//显示图片
function showimg(id,url){
var imgid = "imgid" + id;
//获取上一个id
var upid = id - 1;
//获取下一个ID
var dnid = id + 1;
//隐藏图片
$("#show" + upid).hide();
$("#show" + dnid).hide();
//显示图片
$("#" + imgid).attr('src',url);
$("#show" + id).show();
}
//隐藏图片
function hideimg(id){
var upid = id - 1;
//获取下一个ID
var dnid = id + 1;
$("#show" + id).hide();
$("#show" + upid).hide();
$("#show" + dnid).hide();
}
//显示二维码
function qrcode(name,url){
url = url.replace("./","");
//重组url
protocol = window.location.protocol; //获取协议
host = window.location.host; //获取主机
url = protocol + '//' + host + '/' + url;
//二维码接口
qrcodeapi = runPath + 'functions/qrcode.php?url=' + encodeURIComponent(url);
var qrimg = "
";
var index = layer.open({
type: 1,
area: ['260px', 'auto'],
scrollbar: false,
title: name,
content: qrimg
});
}
//删除文件
function delfile(id,filename,filepath){
id = "id" + id;
layer.prompt({
formType: 1,
title: '请输入密码删除 - ' + filename
}, function(value, index, elem){
$.post(runPath+'functions/delfile.php',{filepath:filepath,password:value},function(data,status){
var redata = eval('(' + data + ')');
if(redata.code == 1){
$("#" + id).remove();
layer.msg(redata.msg + ' ' + filename);
}
else{
layer.msg(redata.msg);
}
});
layer.close(index);
});
}