mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
Fixed not selecting only one line
This commit is contained in:
+5
-6
@@ -1,14 +1,13 @@
|
||||
var p=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(t,e)=>()=>(t&&(e=t(t=0)),e);var T=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},R=(t,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of S(e))!b.call(t,r)&&r!==n&&p(t,r,{get:()=>e[r],enumerable:!(a=w(e,r))||a.enumerable});return t};var L=t=>R(p({},"__esModule",{value:!0}),t);var E={};T(E,{Tracer:()=>u,libTrace:()=>N});import{actions as f}from"@neptune";var u,N,y=v(()=>{"use strict";u=t=>{let e=o=>{let c=(...i)=>{o(t,...i)};return c.withContext=i=>(...m)=>{o(t,i,...m)},c},n=e(console.log),a=e(console.warn),r=e(console.error),g=e(console.debug),s=(o,c,i)=>{let m=l=>{o(l),c({message:`${t} - ${l}`,category:"OTHER",severity:i})};return m.withContext=l=>{let C=o.withContext(l);return d=>{C(d),d instanceof Error&&(d=d.message),c({message:`${t}.${l} - ${d}`,category:"OTHER",severity:i})}},m};return{log:n,warn:a,err:r,debug:g,msg:{log:s(n,f.message.messageInfo,"INFO"),warn:s(a,f.message.messageWarn,"WARN"),err:s(r,f.message.messageError,"ERROR")}}},N=u("[lib]")});y();y();var h=u("[Copy Lyrics]"),A=`
|
||||
var f=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var O=(t,e)=>()=>(t&&(e=t(t=0)),e);var R=(t,e)=>{for(var n in e)f(t,n,{get:e[n],enumerable:!0})},A=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of v(e))!L.call(t,r)&&r!==n&&f(t,r,{get:()=>e[r],enumerable:!(i=b(e,r))||i.enumerable});return t};var M=t=>A(f({},"__esModule",{value:!0}),t);var C={};R(C,{Tracer:()=>m,libTrace:()=>_});import{actions as E}from"@neptune";var m,_,x=O(()=>{"use strict";m=t=>{let e=o=>{let c=(...a)=>{o(t,...a)};return c.withContext=a=>(...u)=>{o(t,a,...u)},c},n=e(console.log),i=e(console.warn),r=e(console.error),p=e(console.debug),s=(o,c,a)=>{let u=d=>{o(d),c({message:`${t} - ${d}`,category:"OTHER",severity:a})};return u.withContext=d=>{let T=o.withContext(d);return l=>{T(l),l instanceof Error&&(l=l.message),c({message:`${t}.${d} - ${l}`,category:"OTHER",severity:a})}},u};return{log:n,warn:i,err:r,debug:p,msg:{log:s(n,E.message.messageInfo,"INFO"),warn:s(i,E.message.messageWarn,"WARN"),err:s(r,E.message.messageError,"ERROR")}}},_=m("[lib]")});x();x();var y=m("[Copy Lyrics]"),$=`
|
||||
[class^="lyricsText"]>div>span {
|
||||
user-select: text;
|
||||
cursor: text;
|
||||
|
||||
}
|
||||
|
||||
::selection {
|
||||
background:rgb(0, 0, 0);
|
||||
color:rgb(255, 255, 255);
|
||||
background: rgb(0, 0, 0);
|
||||
color: rgb(255, 255, 255);
|
||||
}
|
||||
`;function O(t){let e=document.createElement("style");e.type="text/css",e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t)),document.head.appendChild(e)}function $(t){let e=document.createElement("textarea");e.value=t,e.style.position="fixed",document.body.appendChild(e),e.select();try{if(!document.execCommand("copy"))throw new Error("Failed to copy text.")}catch(n){h.msg.err(n)}finally{document.body.removeChild(e)}}O(A);var x=!1;document.addEventListener("mousedown",function(){x=!0});document.addEventListener("mouseup",function(t){if(x){let e=window.getSelection();if(e.toString().length>0){let n=[],g=e.getRangeAt(0).commonAncestorContainer.getElementsByTagName("span");for(let o of g)e.containsNode(o,!0)&&n.push(o);let s="";n.forEach(o=>{s+=o.textContent+`
|
||||
`;function D(t){let e=document.createElement("style");return e.type="text/css",e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t)),document.head.appendChild(e),e}function w(t){let e=document.createElement("textarea");e.value=t,e.style.position="fixed",document.body.appendChild(e),e.select();try{if(!document.execCommand("copy"))throw new Error("Failed to copy text.")}catch(n){y.msg.err(n)}finally{document.body.removeChild(e)}}var g=D($),h=!1,N=function(){h=!0},S=function(t){if(h){let e=window.getSelection();if(e.toString().length>0){let n=[],r=e.getRangeAt(0).commonAncestorContainer;if(r.nodeType!==Node.ELEMENT_NODE&&r.nodeType!==Node.DOCUMENT_NODE){let o=e.toString().trim();w(o),y.msg.log("Copied to clipboard!");return}let p=r.getElementsByTagName("span");for(let o of p)e.containsNode(o,!0)&&n.push(o);let s="";n.forEach(o=>{s+=o.textContent+`
|
||||
`,[...o.classList].some(c=>c.startsWith("endOfStanza--"))&&(s+=`
|
||||
`)}),s=s.trim(),$(s),h.msg.log("Copied to clipboard!"),window.getSelection&&e.removeAllRanges()}x=!1}});function F(){styleElement&&styleElement.parentNode&&styleElement.parentNode.removeChild(styleElement),document.removeEventListener("mousedown",onMouseDown),document.removeEventListener("mouseup",onMouseUp)}export{F as onUnload};
|
||||
`)}),s=s.trim(),w(s),y.msg.log("Copied to clipboard!"),window.getSelection&&e.removeAllRanges()}h=!1}};document.addEventListener("mousedown",N);document.addEventListener("mouseup",S);function F(){g&&g.parentNode&&g.parentNode.removeChild(g),document.removeEventListener("mousedown",N),document.removeEventListener("mouseup",S)}export{F as onUnload};
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"name":"Copy Lyrics","description":"A working neptune plugin that allows the user to copy the lyrics of a song selecting it.","author":"itzzexcel@github","hash":"aeef96d8ab14451ebe3f42446de81230","metafile":{"inputs":{"plugins/copy-lyrics/src/tracer.js":{"bytes":1596,"imports":[{"path":"@neptune","kind":"import-statement","external":true}],"format":"esm"},"plugins/copy-lyrics/src/index.js":{"bytes":2930,"imports":[{"path":"plugins/copy-lyrics/src/tracer.js","kind":"import-statement","original":"./tracer"},{"path":"plugins/copy-lyrics/src/tracer.js","kind":"require-call","original":"./tracer"}],"format":"esm"}},"outputs":{"plugins/copy-lyrics/dist/index.js":{"imports":[{"path":"@neptune","kind":"import-statement","external":true}],"exports":["onUnload"],"entryPoint":"plugins/copy-lyrics/src/index.js","inputs":{"plugins/copy-lyrics/src/tracer.js":{"bytesInOutput":693},"plugins/copy-lyrics/src/index.js":{"bytesInOutput":1362}},"bytes":2525}}}}
|
||||
{"name":"Copy Lyrics","description":"A working neptune plugin that allows the user to copy the lyrics of a song selecting it.","author":"itzzexcel@github","hash":"ba615a10ac2818b121df8abdfe299c36","metafile":{"inputs":{"plugins/copy-lyrics/src/tracer.js":{"bytes":1596,"imports":[{"path":"@neptune","kind":"import-statement","external":true}],"format":"esm"},"plugins/copy-lyrics/src/index.js":{"bytes":3386,"imports":[{"path":"plugins/copy-lyrics/src/tracer.js","kind":"import-statement","original":"./tracer"},{"path":"plugins/copy-lyrics/src/tracer.js","kind":"require-call","original":"./tracer"}],"format":"esm"}},"outputs":{"plugins/copy-lyrics/dist/index.js":{"imports":[{"path":"@neptune","kind":"import-statement","external":true}],"exports":["onUnload"],"entryPoint":"plugins/copy-lyrics/src/index.js","inputs":{"plugins/copy-lyrics/src/tracer.js":{"bytesInOutput":693},"plugins/copy-lyrics/src/index.js":{"bytesInOutput":1464}},"bytes":2627}}}}
|
||||
@@ -1,8 +1,4 @@
|
||||
/*
|
||||
TODO: Check for the span to be part of the lyrics div.
|
||||
*/
|
||||
|
||||
require("./tracer")
|
||||
require("./tracer");
|
||||
import { Tracer } from "./tracer";
|
||||
|
||||
const trace = Tracer("[Copy Lyrics]");
|
||||
@@ -11,12 +7,11 @@ const unlockSelection = `
|
||||
[class^="lyricsText"]>div>span {
|
||||
user-select: text;
|
||||
cursor: text;
|
||||
|
||||
}
|
||||
|
||||
::selection {
|
||||
background:rgb(0, 0, 0);
|
||||
color:rgb(255, 255, 255);
|
||||
background: rgb(0, 0, 0);
|
||||
color: rgb(255, 255, 255);
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -29,11 +24,13 @@ function ApplyCSS(style) {
|
||||
styleElement.appendChild(document.createTextNode(style));
|
||||
|
||||
document.head.appendChild(styleElement);
|
||||
return styleElement;
|
||||
}
|
||||
|
||||
function SetClipboard(text) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.style.position = 'fixed'; // Avoid scrolling to the bottom
|
||||
textarea.style.position = 'fixed'; // Avoid scrolling to bottom
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
|
||||
@@ -41,7 +38,6 @@ function SetClipboard(text) {
|
||||
const success = document.execCommand('copy');
|
||||
if (!success)
|
||||
throw new Error('Failed to copy text.');
|
||||
|
||||
} catch (err) {
|
||||
trace.msg.err(err);
|
||||
} finally {
|
||||
@@ -49,23 +45,35 @@ function SetClipboard(text) {
|
||||
}
|
||||
}
|
||||
|
||||
ApplyCSS(unlockSelection);
|
||||
const styleElement = ApplyCSS(unlockSelection);
|
||||
|
||||
let isSelecting = false;
|
||||
|
||||
document.addEventListener('mousedown', function() {
|
||||
const onMouseDown = function () {
|
||||
isSelecting = true;
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener('mouseup', function (event) {
|
||||
const onMouseUp = function (event) {
|
||||
if (isSelecting) {
|
||||
const selection = window.getSelection();
|
||||
if (selection.toString().length > 0) {
|
||||
const selectedSpans = [];
|
||||
const ranges = selection.getRangeAt(0);
|
||||
const container = ranges.commonAncestorContainer;
|
||||
const range = selection.getRangeAt(0);
|
||||
let container = range.commonAncestorContainer;
|
||||
|
||||
// Get all spans within the selection
|
||||
// If the container is NOT and element and a document, try to adjust it.
|
||||
if (
|
||||
container.nodeType !== Node.ELEMENT_NODE &&
|
||||
container.nodeType !== Node.DOCUMENT_NODE
|
||||
) {
|
||||
let text_ = selection.toString().trim();
|
||||
SetClipboard(text_);
|
||||
trace.msg.log("Copied to clipboard!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all the spans inside the container.
|
||||
const spans = container.getElementsByTagName('span');
|
||||
for (let span of spans) {
|
||||
if (selection.containsNode(span, true)) {
|
||||
@@ -73,7 +81,7 @@ document.addEventListener('mouseup', function (event) {
|
||||
}
|
||||
}
|
||||
|
||||
// Concatenate text from selected spans
|
||||
// Concat the text of the selected spans.
|
||||
let text = '';
|
||||
selectedSpans.forEach(span => {
|
||||
text += span.textContent + '\n';
|
||||
@@ -91,7 +99,10 @@ document.addEventListener('mouseup', function (event) {
|
||||
}
|
||||
isSelecting = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener('mousedown', onMouseDown);
|
||||
document.addEventListener('mouseup', onMouseUp);
|
||||
|
||||
export function onUnload() {
|
||||
if (styleElement && styleElement.parentNode) {
|
||||
|
||||
Reference in New Issue
Block a user