EasyImages2.0/public/static/EasyImage.js

348 lines
12 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();
2023-02-22 13:48:14 +00:00
if (navigator.clipboard && window.isSecureContext) {
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("复制失败");
});
2023-02-22 13:48:14 +00:00
} else {
if (document.execCommand('copy', false, null)) {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
} else {
//fail info
alert("复制失败");
}
2021-11-17 14:01:01 +00:00
}
}
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();
2023-02-22 13:48:14 +00:00
if (navigator.clipboard && window.isSecureContext) {
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("复制失败");
});
2023-02-22 13:48:14 +00:00
} else {
if (document.execCommand('copy', false, null)) {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
} else {
//fail info
alert("复制失败");
}
2021-11-17 14:01:01 +00:00
}
}
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();
2023-02-22 13:48:14 +00:00
if (navigator.clipboard && window.isSecureContext) {
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("复制失败");
});
2023-02-22 13:48:14 +00:00
} else {
if (document.execCommand('copy', false, null)) {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
} else {
//fail info
alert("复制失败");
}
2021-11-17 14:01:01 +00:00
}
}
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();
2023-02-22 13:48:14 +00:00
if (navigator.clipboard && window.isSecureContext) {
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("复制失败");
});
2023-02-22 13:48:14 +00:00
} else {
if (document.execCommand('copy', false, null)) {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
} else {
//fail info
alert("复制失败");
}
2021-11-17 14:01:01 +00:00
}
}
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();
2023-02-22 13:48:14 +00:00
if (navigator.clipboard && window.isSecureContext) {
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("复制失败");
});
2023-02-22 13:48:14 +00:00
} else {
if (document.execCommand('copy', false, null)) {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
} else {
//fail info
alert("复制失败");
}
2021-11-17 14:01:01 +00:00
}
}
2023-01-29 22:43:40 +00:00
document.getElementsByClassName('copyBtn6')[0].onclick = function () {
var copyVal = document.getElementById("del");
copyVal.select();
2023-02-22 13:48:14 +00:00
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(copyVal.value).then(function () {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
}, function () {
//fail info
alert("复制失败");
});
2023-02-22 13:48:14 +00:00
} else {
if (document.execCommand('copy', false, null)) {
//success info
new $.zui.Messager("复制成功", {
type: "primary", // 定义颜色主题
icon: "ok-sign" // 定义消息图标
}).show();
console.log("复制成功");
} else {
//fail info
alert("复制失败");
}
}
}
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') {
document.getElementById("links").innerHTML += result.url + "\r\n";
document.getElementById("bbscode").innerHTML += "[img]" + result.url + "[/img]\r\n";
document.getElementById("markdown").innerHTML += "![" + result.srcName + "](" + result.url + ")\r\n";
document.getElementById("html").innerHTML += '<img src="' + result.url + '" alt="' + result.srcName + '" />\r\n';
document.getElementById("thumb").innerHTML += result.thumb + "\r\n";
document.getElementById("del").innerHTML += result.del + "\r\n";
2023-02-24 05:16:57 +00:00
$.zui.messager.show(result.srcName + '上传成功', {
icon: 'bell',
time: 4000,
type: 'success',
placement: 'top'
});
2023-01-30 17:36:48 +00:00
try { // 储存上传记录
console.log('localStorage ok!');
$.zui.store.set(result.srcName, result)
} catch (err) {
console.log('localStorage failed:' + err);
}
} 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
};
2023-03-05 15:11:00 +00:00
xhr.open('POST', './application/upload.php?sign=' + new Date().format("YYYYMMddhh"), true);
2021-11-17 14:01:01 +00:00
xhr.send(formData);
});
})();
2022-05-25 10:23:17 +00:00
2023-02-22 13:48:14 +00:00
/**
* javascript parseUrl函数解析url获取网址url参数
* https://www.cnblogs.com/lazb/p/10144471.html
2023-02-22 13:48:14 +00:00
* 使用示例
* 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'
*/
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('/')
};
}
/** jQuery 读取文件 readTxt('../admin/version.php'); */
2023-02-22 13:48:14 +00:00
function readTxt(filePath = '../admin/version.php') {
$.get(filePath, function (data) {
var lines = data.split("\n"); //按行读取
$.each(lines, function (i, v) {
console.log(v);
});
});
2023-02-24 05:16:57 +00:00
}