EasyImages2.0/public/static/EasyImage.js

291 lines
9.3 KiB
JavaScript
Raw Normal View History

2021-11-17 14:01:01 +00:00
/**
* 来自于copy_btn.js paste.js合并
2023-01-29 22:43:40 +00:00
* 简单图床-复制链接
* 2023-01-30
2021-11-17 14:01:01 +00:00
*/
2023-01-29 22:43:40 +00:00
document.getElementsByClassName('copyBtn1')[0].onclick = function () {
2021-11-17 14:01:01 +00:00
var copyVal = document.getElementById("links");
copyVal.select();
try {
navigator.clipboard.writeText(copyVal.value).then(function () {
2021-11-17 14:01:01 +00:00
//success info
2022-01-12 18:48:08 +00:00
new $.zui.Messager("复制成功", {
2022-01-19 10:56:59 +00:00
type: "primary", // 定义颜色主题
2022-05-09 06:37:58 +00:00
icon: "ok-sign" // 定义消息图标
2022-01-12 18:48:08 +00:00
}).show();
2021-11-17 14:01:01 +00:00
console.log("复制成功");
}, function () {
2021-11-17 14:01:01 +00:00
//fail info
alert("复制失败");
});
2021-11-17 14:01:01 +00:00
} catch (err) {
alert(err);
}
}
2023-01-29 22:43:40 +00:00
document.getElementsByClassName('copyBtn2')[0].onclick = function () {
2021-11-17 14:01:01 +00:00
var copyVal = document.getElementById("bbscode");
copyVal.select();
try {
navigator.clipboard.writeText(copyVal.value).then(function () {
2021-11-17 14:01:01 +00:00
//success info
2022-01-12 18:48:08 +00:00
new $.zui.Messager("复制成功", {
2022-01-19 10:56:59 +00:00
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
2022-01-12 18:48:08 +00:00
}).show();
2021-11-17 14:01:01 +00:00
console.log("复制成功");
}, function () {
2021-11-17 14:01:01 +00:00
//fail info
alert("复制失败");
});
2021-11-17 14:01:01 +00:00
} catch (err) {
alert(err);
}
}
2023-01-29 22:43:40 +00:00
document.getElementsByClassName('copyBtn3')[0].onclick = function () {
2021-11-17 14:01:01 +00:00
var copyVal = document.getElementById("markdown");
copyVal.select();
try {
navigator.clipboard.writeText(copyVal.value).then(function () {
2021-11-17 14:01:01 +00:00
//success info
2022-01-12 18:48:08 +00:00
new $.zui.Messager("复制成功", {
2022-01-19 10:56:59 +00:00
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
2022-01-12 18:48:08 +00:00
}).show();
2021-11-17 14:01:01 +00:00
console.log("复制成功");
}, function () {
2021-11-17 14:01:01 +00:00
//fail info
alert("复制失败");
});
2021-11-17 14:01:01 +00:00
} catch (err) {
alert(err);
}
}
2023-01-29 22:43:40 +00:00
document.getElementsByClassName('copyBtn4')[0].onclick = function () {
2021-11-17 14:01:01 +00:00
var copyVal = document.getElementById("html");
copyVal.select();
try {
navigator.clipboard.writeText(copyVal.value).then(function () {
2021-11-17 14:01:01 +00:00
//success info
2022-01-12 18:48:08 +00:00
new $.zui.Messager("复制成功", {
2022-01-19 10:56:59 +00:00
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
2022-01-12 18:48:08 +00:00
}).show();
2021-11-17 14:01:01 +00:00
console.log("复制成功");
}, function () {
2021-11-17 14:01:01 +00:00
//fail info
alert("复制失败");
});
2021-11-17 14:01:01 +00:00
} catch (err) {
alert(err);
}
}
2023-01-29 22:43:40 +00:00
document.getElementsByClassName('copyBtn5')[0].onclick = function () {
var copyVal = document.getElementById("thumb");
2021-11-17 14:01:01 +00:00
copyVal.select();
try {
navigator.clipboard.writeText(copyVal.value).then(function () {
2021-11-17 14:01:01 +00:00
//success info
2022-01-12 18:48:08 +00:00
new $.zui.Messager("复制成功", {
2022-01-19 10:56:59 +00:00
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
2022-01-12 18:48:08 +00:00
}).show();
2021-11-17 14:01:01 +00:00
console.log("复制成功");
}, function () {
2021-11-17 14:01:01 +00:00
//fail info
alert("复制失败");
});
2021-11-17 14:01:01 +00:00
} catch (err) {
alert(err);
}
}
2023-01-29 22:43:40 +00:00
document.getElementsByClassName('copyBtn6')[0].onclick = function () {
var copyVal = document.getElementById("del");
copyVal.select();
try {
navigator.clipboard.writeText(copyVal.value).then(function () {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
}, function () {
//fail info
alert("复制失败");
});
} catch (err) {
alert(err);
}
}
2021-11-17 14:01:01 +00:00
// 按钮状态
$('#btnLinks, #btnBbscode, #btnMarkDown, #btnHtml, #btnThumb, #btnDel').on('click', function () {
$(this).button('loading').delay(2000).queue(function () {
$(this).button('reset');
})
2021-11-17 14:01:01 +00:00
});
2023-01-29 22:43:40 +00:00
/** 粘贴上传 2023-01-30 */
(function () {
document.addEventListener('paste', function (e) {
2021-11-17 14:01:01 +00:00
var items = ((e.clipboardData || window.clipboardData).items) || [];
var file = null;
if (items && items.length) {
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
file = items[i].getAsFile();
break;
}
}
}
if (!file) {
$.zui.messager.show('粘贴内容非图片!', {
icon: 'bell',
time: 3000,
type: 'danger',
placement: 'top'
});
2021-11-17 14:01:01 +00:00
return;
}
2021-11-17 14:01:01 +00:00
var formData = new FormData();
formData.append('file', file);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 1) {
$.zui.messager.show('粘贴上传中...', {
icon: 'bell',
time: 3000,
type: 'primary',
placement: 'top'
});
$(".uploader").addClass("load-indicator loading"); // 增加正在上传状态
}
2021-11-17 14:01:01 +00:00
if (xhr.readyState >= 4) {
$.zui.messager.show('粘贴上传中...', {
icon: 'bell',
time: 3000,
type: 'primary',
placement: 'top'
});
$(".uploader").removeClass("load-indicator loading"); // 移除正在上传状态
}
}
2021-11-17 14:01:01 +00:00
xhr.onload = function () {
var result = JSON.parse(this.responseText);
if (result.result === 'success') {
var links = document.getElementById("links");
links.innerHTML += result.url + "\n";
var bbscode = document.getElementById("bbscode");
bbscode.innerHTML += "[img]" + result.url + "[/img]\n";
var markdown = document.getElementById("markdown");
markdown.innerHTML += "![](" + result.url + ")\n";
var html = document.getElementById("html");
html.innerHTML += "&lt;img src=\"" + result.url + "\" /&#62;\n";
var del = document.getElementById("thumb");
del.innerHTML += result.thumb + "\n";
var del = document.getElementById("del");
del.innerHTML += result.del + "\n";
$.zui.messager.show('粘贴上传成功...', {
icon: 'bell',
time: 4000,
type: 'success',
placement: 'top'
});
} else {
$.zui.messager.show('上传失败...' + result.message, {
icon: 'bell',
time: 4000,
type: 'primary',
placement: 'top'
});
2021-11-17 14:01:01 +00:00
}
};
xhr.onerror = function () {
$.zui.messager.show('因网络问题导致的上传失败...', {
icon: 'bell',
time: 4000,
type: 'primary',
placement: 'top'
});
2021-11-17 14:01:01 +00:00
};
2022-02-04 17:18:15 +00:00
xhr.open('POST', './application/upload.php', true);
2021-11-17 14:01:01 +00:00
xhr.send(formData);
});
})();
2022-05-25 10:23:17 +00:00
/** javascript parseUrlurlurl
* https://www.cnblogs.com/lazb/p/10144471.html
*/
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':', ''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function () {
var ret = {},
seg = a.search.replace(/^\?/, '').split('&'),
len = seg.length, i = 0, s;
for (; i < len; i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
hash: a.hash.replace('#', ''),
path: a.pathname.replace(/^([^\/])/, '/$1'),
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
segments: a.pathname.replace(/^\//, '').split('/')
};
}
/**
使用实例
var myURL = parseURL('http://abc.com:8080/dir/index.html?id=255&m=hello#top');
myURL.file; // = 'index.html'
myURL.hash; // = 'top'
myURL.host; // = 'abc.com'
myURL.query; // = '?id=255&m=hello'
myURL.params; // = Object = { id: 255, m: hello }
myURL.path; // = '/dir/index.html'
myURL.segments; // = Array = ['dir', 'index.html']
myURL.port; // = '8080'
myURL.protocol; // = 'http'
myURL.source; // = 'http://abc.com:8080/dir/index.html?id=255&m=hello#top'
*/
/** jQuery 读取文件 readTxt('../admin/version.php'); */
function readTxt(filePath) {
$.get(filePath, function (data) {
var lines = data.split("\n"); //按行读取
$.each(lines, function (i, v) {
console.log(v);
});
});
}