feat(batch): 复制治理链接补齐label并复制绝对URL
This commit is contained in:
@@ -594,6 +594,22 @@
|
||||
});
|
||||
})();
|
||||
|
||||
function absoluteUrl(href) {
|
||||
var h = String(href || '');
|
||||
if (!h) {
|
||||
return '';
|
||||
}
|
||||
// 已是绝对链接
|
||||
if (h.indexOf('http://') === 0 || h.indexOf('https://') === 0) {
|
||||
return h;
|
||||
}
|
||||
// 仅将站内相对路径补齐为绝对链接
|
||||
if (h.indexOf('/') === 0 && window.location && window.location.origin) {
|
||||
return String(window.location.origin) + h;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
// 批次页:一键复制治理集合链接(例如:本批次失败 / 按Top原因)
|
||||
(function(){
|
||||
var btns = document.querySelectorAll('[data-action="copy-link"][data-href]');
|
||||
@@ -602,13 +618,16 @@
|
||||
btns.forEach(function(btn){
|
||||
btn.addEventListener('click', function(){
|
||||
var href = btn.getAttribute('data-href') || '';
|
||||
copyToClipboard(href).then(function(){
|
||||
if (toastSuccess('已复制链接')) {
|
||||
var label = btn.getAttribute('data-label') || '链接';
|
||||
|
||||
var abs = absoluteUrl(href);
|
||||
copyToClipboard(abs).then(function(){
|
||||
if (toastSuccess('已复制' + label + '链接')) {
|
||||
return;
|
||||
}
|
||||
try { window.alert('已复制链接'); } catch (e) {}
|
||||
try { window.alert('已复制' + label + '链接'); } catch (e) {}
|
||||
}).catch(function(){
|
||||
try { window.alert('复制失败,请手动复制链接'); } catch (e) {}
|
||||
try { window.alert('复制失败,请手动复制' + label + '链接'); } catch (e) {}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user