mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
🎸
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
||||
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=`
|
||||
[class^="lyricsText"]>div>span {
|
||||
user-select: text;
|
||||
cursor: text;
|
||||
|
||||
}
|
||||
|
||||
::selection {
|
||||
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+`
|
||||
`,[...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};
|
||||
@@ -0,0 +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}}}}
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"canvas-confetti": "^1.6.0"
|
||||
"canvas-confetti": "^1.6.0",
|
||||
"neptune-types": "1.0.1"
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,36 @@
|
||||
/*
|
||||
* TODO: Check for the span to be part of the lyrics div.
|
||||
*
|
||||
TODO: Check for the span to be part of the lyrics div.
|
||||
*/
|
||||
|
||||
import toast, { Toaster } from 'react-hot-toast';
|
||||
require("./tracer")
|
||||
import { Tracer } from "./tracer";
|
||||
|
||||
const trace = Tracer("[Copy Lyrics]");
|
||||
|
||||
const unlockSelection = `
|
||||
[class^="lyricsText"]>div>span {
|
||||
user-select: text;
|
||||
cursor: text;
|
||||
}`;
|
||||
|
||||
}
|
||||
|
||||
::selection {
|
||||
background:rgb(0, 0, 0);
|
||||
color:rgb(255, 255, 255);
|
||||
}
|
||||
`;
|
||||
|
||||
function ApplyCSS(style) {
|
||||
const styleElement = document.createElement('style');
|
||||
styleElement.type = 'text/css';
|
||||
if (styleElement.styleSheet)
|
||||
styleElement.styleSheet.cssText = style;
|
||||
else
|
||||
styleElement.appendChild(document.createTextNode(style));
|
||||
const styleElement = document.createElement('style');
|
||||
styleElement.type = 'text/css';
|
||||
if (styleElement.styleSheet)
|
||||
styleElement.styleSheet.cssText = style;
|
||||
else
|
||||
styleElement.appendChild(document.createTextNode(style));
|
||||
|
||||
document.head.appendChild(styleElement);
|
||||
document.head.appendChild(styleElement);
|
||||
}
|
||||
function SetClipboar(text) {
|
||||
function SetClipboard(text) {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.style.position = 'fixed'; // Avoid scrolling to the bottom
|
||||
@@ -30,15 +39,11 @@ function SetClipboar(text) {
|
||||
|
||||
try {
|
||||
const success = document.execCommand('copy');
|
||||
if (success) {
|
||||
console.log('Text copied to clipboard:', text);
|
||||
toast.success('Copied to clipboard!');
|
||||
} else {
|
||||
if (!success)
|
||||
throw new Error('Failed to copy text.');
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error('Failed to copy text:', err);
|
||||
toast.error('Failed to copy to clipboard!');
|
||||
trace.msg.err(err);
|
||||
} finally {
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
@@ -52,24 +57,47 @@ document.addEventListener('mousedown', function() {
|
||||
isSelecting = true;
|
||||
});
|
||||
|
||||
document.addEventListener('mouseup', function() {
|
||||
document.addEventListener('mouseup', function (event) {
|
||||
if (isSelecting) {
|
||||
const selection = window.getSelection();
|
||||
if (selection.toString().length > 0) {
|
||||
let text = selection.toString();
|
||||
SetClipboar(text);
|
||||
toast.success("Copied to clipboard!");
|
||||
if (window.getSelection) {
|
||||
const selection = window.getSelection();
|
||||
selection.removeAllRanges();
|
||||
}
|
||||
} else {
|
||||
const selectedSpans = [];
|
||||
const ranges = selection.getRangeAt(0);
|
||||
const container = ranges.commonAncestorContainer;
|
||||
|
||||
// Get all spans within the selection
|
||||
const spans = container.getElementsByTagName('span');
|
||||
for (let span of spans) {
|
||||
if (selection.containsNode(span, true)) {
|
||||
selectedSpans.push(span);
|
||||
}
|
||||
}
|
||||
|
||||
// Concatenate text from selected spans
|
||||
let text = '';
|
||||
selectedSpans.forEach(span => {
|
||||
text += span.textContent + '\n';
|
||||
if ([...span.classList].some(className => className.startsWith('endOfStanza--'))) {
|
||||
text += '\n';
|
||||
}
|
||||
});
|
||||
text = text.trim();
|
||||
|
||||
SetClipboard(text);
|
||||
trace.msg.log("Copied to clipboard!");
|
||||
if (window.getSelection) {
|
||||
selection.removeAllRanges();
|
||||
}
|
||||
}
|
||||
isSelecting = false;
|
||||
}
|
||||
});
|
||||
|
||||
export function onUnload() {
|
||||
console.log("Goodbye world!");
|
||||
if (styleElement && styleElement.parentNode) {
|
||||
styleElement.parentNode.removeChild(styleElement);
|
||||
}
|
||||
|
||||
document.removeEventListener('mousedown', onMouseDown);
|
||||
document.removeEventListener('mouseup', onMouseUp);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// Based on https://github.com/Inrixia/neptune-plugins/blob/3d28c9ea3252782da830698032dbb49dbe5b9fd6/plugins/_lib/trace.ts
|
||||
// Credits to inrixia
|
||||
|
||||
import { actions } from "@neptune";
|
||||
|
||||
export const Tracer = (source) => {
|
||||
const createLogger = (logger) => {
|
||||
const _logger = (...data) => {
|
||||
logger(source, ...data);
|
||||
return undefined;
|
||||
};
|
||||
_logger.withContext = (context) => (...data) => {
|
||||
logger(source, context, ...data);
|
||||
return undefined;
|
||||
};
|
||||
return _logger;
|
||||
};
|
||||
|
||||
const log = createLogger(console.log);
|
||||
const warn = createLogger(console.warn);
|
||||
const err = createLogger(console.error);
|
||||
const debug = createLogger(console.debug);
|
||||
|
||||
const createMessager = (logger, messager, severity) => {
|
||||
const _messager = (message) => {
|
||||
logger(message);
|
||||
messager({ message: `${source} - ${message}`, category: "OTHER", severity });
|
||||
return undefined;
|
||||
};
|
||||
_messager.withContext = (context) => {
|
||||
const loggerWithContext = logger.withContext(context);
|
||||
return (message) => {
|
||||
loggerWithContext(message);
|
||||
if (message instanceof Error) message = message.message;
|
||||
messager({ message: `${source}.${context} - ${message}`, category: "OTHER", severity });
|
||||
return undefined;
|
||||
};
|
||||
};
|
||||
return _messager;
|
||||
};
|
||||
|
||||
return {
|
||||
log,
|
||||
warn,
|
||||
err,
|
||||
debug,
|
||||
msg: {
|
||||
log: createMessager(log, actions.message.messageInfo, "INFO"),
|
||||
warn: createMessager(warn, actions.message.messageWarn, "WARN"),
|
||||
err: createMessager(err, actions.message.messageError, "ERROR"),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const libTrace = Tracer("[lib]");
|
||||
Reference in New Issue
Block a user