added delete option for youtube-dl download;added options for copying links;

This commit is contained in:
huangjx
2022-02-19 00:44:45 +08:00
parent d25e0c1ec1
commit 06e1588d06
13 changed files with 219 additions and 23 deletions

66
src/utils/clipboard.js Normal file
View File

@@ -0,0 +1,66 @@
import Tooltip from "../lib/tooltip";
class Clipboard {
element;
text;
constructor(element, text) {
if (typeof element !== 'string' && !(element instanceof HTMLElement))
throw ("invalid element!");
this.element = typeof element == 'object' ? element : document.querySelector(element);
this.text = text || element.getAttribute("data-text");
}
_copy(text) {
let textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
let result;
try {
result = document.execCommand('copy');
//console.log('copied using exceCommand');
} catch (err) {
console.error('failed to copy', err);
result = false;
} finally {
document.body.removeChild(textArea);
}
if (result) {
this.ShowMsg("Copied!");
}
}
ShowMsg(msg) {
let tip = new Tooltip(this.element, msg);
let html = tip.create('copy-alert').html();
document.body.appendChild(html);
const callback = (element) => {
element.remove()
}
setTimeout(() => {
callback(html)
}, 1000);
}
Copy() {
if (!navigator.clipboard) {
return this._copy(this.text);
}
return navigator.clipboard.writeText(this.text).then(() => {
this.ShowMsg("Copied!");
}, function (err) {
console.error('failed to copy text: ', err);
});
}
}
export default Clipboard;

View File

@@ -172,6 +172,12 @@ const helper = {
></span
><span class="visually-hidden">Loading...</span>`;
return html;
},
getCssVar(prop) {
return window.getComputedStyle(document.documentElement).getPropertyValue(prop);
},
getScrollTop() {
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
}
}