mirror of
https://github.com/meowarex/TidaLuna-Plugins.git
synced 2026-06-18 03:43:10 +10:00
Temporary thing until I figure out how to get the album cover URL
This commit is contained in:
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
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]"),$=`
|
var p=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var L=(t,e)=>()=>(t&&(e=t(t=0)),e);var O=(t,e)=>{for(var r in e)p(t,r,{get:e[r],enumerable:!0})},R=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of v(e))!A.call(t,o)&&o!==r&&p(t,o,{get:()=>e[o],enumerable:!(i=S(e,o))||i.enumerable});return t};var M=t=>R(p({},"__esModule",{value:!0}),t);var C={};O(C,{Tracer:()=>m,libTrace:()=>_});import{actions as E}from"@neptune";var m,_,h=L(()=>{"use strict";m=t=>{let e=s=>{let n=(...c)=>{s(t,...c)};return n.withContext=c=>(...u)=>{s(t,c,...u)},n},r=e(console.log),i=e(console.warn),o=e(console.error),f=e(console.debug),a=(s,n,c)=>{let u=l=>{s(l),n({message:`${t} - ${l}`,category:"OTHER",severity:c})};return u.withContext=l=>{let T=s.withContext(l);return d=>{T(d),d instanceof Error&&(d=d.message),n({message:`${t}.${l} - ${d}`,category:"OTHER",severity:c})}},u};return{log:r,warn:i,err:o,debug:f,msg:{log:a(r,E.message.messageInfo,"INFO"),warn:a(i,E.message.messageWarn,"WARN"),err:a(o,E.message.messageError,"ERROR")}}},_=m("[lib]")});h();h();var x=m("[Copy Lyrics]"),D=`
|
||||||
[class^="lyricsText"]>div>span {
|
[class^="lyricsText"]>div>span {
|
||||||
user-select: text;
|
user-select: text;
|
||||||
cursor: text;
|
cursor: text;
|
||||||
@@ -8,6 +8,6 @@ var f=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var v=Object.g
|
|||||||
background: rgb(0, 0, 0);
|
background: rgb(0, 0, 0);
|
||||||
color: rgb(255, 255, 255);
|
color: rgb(255, 255, 255);
|
||||||
}
|
}
|
||||||
`;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+`
|
`;function $(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 b(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(r){x.msg.err(r)}finally{document.body.removeChild(e)}}var g=$(D),y=!1,w=function(){y=!0},N=function(t){if(y){let e=window.getSelection();if(e.toString().length>0){let r=[],o=e.getRangeAt(0).commonAncestorContainer;if(o.nodeType!==Node.ELEMENT_NODE&&o.nodeType!==Node.DOCUMENT_NODE){let n=o.parentElement;if(n&&n.hasAttribute("data-current")||o.ELEMENT_NODE.hasAttribute("data-current")){let c=e.toString().trim();b(c),x.msg.log("Copied to clipboard!");return}}let f=o.getElementsByTagName("span");for(let n of f)e.containsNode(n,!0)&&r.push(n);let a=!1,s="";r.forEach(n=>{n.hasAttribute("data-current")&&(a=!0,s+=n.textContent+`
|
||||||
`,[...o.classList].some(c=>c.startsWith("endOfStanza--"))&&(s+=`
|
`,[...n.classList].some(c=>c.startsWith("endOfStanza--"))&&(s+=`
|
||||||
`)}),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};
|
`))}),a&&console.log(a),s=s.trim(),a===!0&&(b(s),x.msg.log("Copied to clipboard!"),window.getSelection&&e.removeAllRanges())}y=!1}};document.addEventListener("mousedown",w);document.addEventListener("mouseup",N);function F(){g&&g.parentNode&&g.parentNode.removeChild(g),document.removeEventListener("mousedown",w),document.removeEventListener("mouseup",N)}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":"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}}}}
|
{"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":"f69f72f93e3010a2597ed0f5f5d504b6","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":4042,"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":1642}},"bytes":2805}}}}
|
||||||
@@ -16,28 +16,25 @@ const unlockSelection = `
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
function ApplyCSS(style) {
|
function ApplyCSS(style) {
|
||||||
const styleElement = document.createElement('style');
|
const styleElement = document.createElement("style");
|
||||||
styleElement.type = 'text/css';
|
styleElement.type = "text/css";
|
||||||
if (styleElement.styleSheet)
|
if (styleElement.styleSheet) styleElement.styleSheet.cssText = style;
|
||||||
styleElement.styleSheet.cssText = style;
|
else styleElement.appendChild(document.createTextNode(style));
|
||||||
else
|
|
||||||
styleElement.appendChild(document.createTextNode(style));
|
|
||||||
|
|
||||||
document.head.appendChild(styleElement);
|
document.head.appendChild(styleElement);
|
||||||
return styleElement;
|
return styleElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetClipboard(text) {
|
function SetClipboard(text) {
|
||||||
const textarea = document.createElement('textarea');
|
const textarea = document.createElement("textarea");
|
||||||
textarea.value = text;
|
textarea.value = text;
|
||||||
textarea.style.position = 'fixed'; // Avoid scrolling to bottom
|
textarea.style.position = "fixed"; // Avoid scrolling to bottom
|
||||||
document.body.appendChild(textarea);
|
document.body.appendChild(textarea);
|
||||||
textarea.select();
|
textarea.select();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const success = document.execCommand('copy');
|
const success = document.execCommand("copy");
|
||||||
if (!success)
|
if (!success) throw new Error("Failed to copy text.");
|
||||||
throw new Error('Failed to copy text.');
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
trace.msg.err(err);
|
trace.msg.err(err);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -60,21 +57,24 @@ const onMouseUp = function (event) {
|
|||||||
const selectedSpans = [];
|
const selectedSpans = [];
|
||||||
const range = selection.getRangeAt(0);
|
const range = selection.getRangeAt(0);
|
||||||
let container = range.commonAncestorContainer;
|
let container = range.commonAncestorContainer;
|
||||||
|
|
||||||
// If the container is NOT and element and a document, try to adjust it.
|
// If the container is NOT and element and a document, try to adjust it.
|
||||||
if (
|
if (
|
||||||
container.nodeType !== Node.ELEMENT_NODE &&
|
container.nodeType !== Node.ELEMENT_NODE &&
|
||||||
container.nodeType !== Node.DOCUMENT_NODE
|
container.nodeType !== Node.DOCUMENT_NODE
|
||||||
) {
|
) {
|
||||||
let text_ = selection.toString().trim();
|
// Get the parent element if it's a text node
|
||||||
SetClipboard(text_);
|
const parentElement = container.parentElement;
|
||||||
trace.msg.log("Copied to clipboard!");
|
if (parentElement && parentElement.hasAttribute("data-current") || container.ELEMENT_NODE.hasAttribute("data-current")) {
|
||||||
|
let text_ = selection.toString().trim();
|
||||||
|
SetClipboard(text_);
|
||||||
|
trace.msg.log("Copied to clipboard!");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all the spans inside the container.
|
// Get all the spans inside the container.
|
||||||
const spans = container.getElementsByTagName('span');
|
const spans = container.getElementsByTagName("span");
|
||||||
for (let span of spans) {
|
for (let span of spans) {
|
||||||
if (selection.containsNode(span, true)) {
|
if (selection.containsNode(span, true)) {
|
||||||
selectedSpans.push(span);
|
selectedSpans.push(span);
|
||||||
@@ -82,33 +82,45 @@ const onMouseUp = function (event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Concat the text of the selected spans.
|
// Concat the text of the selected spans.
|
||||||
let text = '';
|
let hasCorrectAttribute = false;
|
||||||
selectedSpans.forEach(span => {
|
let text = "";
|
||||||
text += span.textContent + '\n';
|
selectedSpans.forEach((span) => {
|
||||||
if ([...span.classList].some(className => className.startsWith('endOfStanza--'))) {
|
if (span.hasAttribute("data-current")) {
|
||||||
text += '\n';
|
hasCorrectAttribute = true;
|
||||||
|
text += span.textContent + "\n";
|
||||||
|
if ([...span.classList].some((className) => className.startsWith("endOfStanza--"))) {
|
||||||
|
text += "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (hasCorrectAttribute) {
|
||||||
|
console.log(hasCorrectAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
text = text.trim();
|
text = text.trim();
|
||||||
|
|
||||||
SetClipboard(text);
|
if (hasCorrectAttribute === true) {
|
||||||
trace.msg.log("Copied to clipboard!");
|
SetClipboard(text);
|
||||||
if (window.getSelection) {
|
trace.msg.log("Copied to clipboard!");
|
||||||
selection.removeAllRanges();
|
if (window.getSelection) {
|
||||||
|
selection.removeAllRanges();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
isSelecting = false;
|
isSelecting = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener('mousedown', onMouseDown);
|
document.addEventListener("mousedown", onMouseDown);
|
||||||
document.addEventListener('mouseup', onMouseUp);
|
document.addEventListener("mouseup", onMouseUp);
|
||||||
|
|
||||||
export function onUnload() {
|
export function onUnload() {
|
||||||
if (styleElement && styleElement.parentNode) {
|
if (styleElement && styleElement.parentNode) {
|
||||||
styleElement.parentNode.removeChild(styleElement);
|
styleElement.parentNode.removeChild(styleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.removeEventListener('mousedown', onMouseDown);
|
document.removeEventListener("mousedown", onMouseDown);
|
||||||
document.removeEventListener('mouseup', onMouseUp);
|
document.removeEventListener("mouseup", onMouseUp);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
var h=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var O=(t,e)=>()=>(t&&(e=t(t=0)),e);var b=(t,e)=>{for(var n in e)h(t,n,{get:e[n],enumerable:!0})},S=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of I(e))!N.call(t,r)&&r!==n&&h(t,r,{get:()=>e[r],enumerable:!(s=x(e,r))||s.enumerable});return t};var _=t=>S(h({},"__esModule",{value:!0}),t);var T={};b(T,{Tracer:()=>m,libTrace:()=>$});import{actions as f}from"@neptune";var m,$,g=O(()=>{"use strict";m=t=>{let e=c=>{let a=(...o)=>{c(t,...o)};return a.withContext=o=>(...d)=>{c(t,o,...d)},a},n=e(console.log),s=e(console.warn),r=e(console.error),w=e(console.debug),p=(c,a,o)=>{let d=l=>{c(l),a({message:`${t} - ${l}`,category:"OTHER",severity:o})};return d.withContext=l=>{let R=c.withContext(l);return i=>{R(i),i instanceof Error&&(i=i.message),a({message:`${t}.${l} - ${i}`,category:"OTHER",severity:o})}},d};return{log:n,warn:s,err:r,debug:w,msg:{log:p(n,f.message.messageInfo,"INFO"),warn:p(s,f.message.messageWarn,"WARN"),err:p(r,f.message.messageError,"ERROR")}}},$=m("[lib]")});g();import{intercept as E}from"@neptune";g();var k=m("[OLED Theme]"),A="https://raw.githubusercontent.com/ItzzExcel/neptune-projects/refs/heads/main/themes/black-neptune-theme.css",C,u;function U(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 D(){u&&u.parentNode&&u.parentNode.removeChild(u)}async function L(t){try{let e=await fetch(t);if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return await e.text()}catch(e){return k.msg.err(`Failed to fetch URL: ${e.message}`),null}}(async()=>(C=await L(A),u=U(C)))();function y([t]){}E("playbackControls/PREFILL_MEDIA_PRODUCT_TRANSITION",y);E("playbackControls/MEDIA_PRODUCT_TRANSITION",y);function z(){D()}export{z as onUnload};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"name":"OLED Theme","description":"A working theme. ong.","author":"itzzexcel@github","hash":"d6f50bec7e0b1f8d7b829666128cb241","metafile":{"inputs":{"plugins/oled-theme/src/tracer.js":{"bytes":1596,"imports":[{"path":"@neptune","kind":"import-statement","external":true}],"format":"esm"},"plugins/oled-theme/src/index.js":{"bytes":1729,"imports":[{"path":"plugins/oled-theme/src/tracer.js","kind":"import-statement","original":"./tracer"},{"path":"@neptune","kind":"import-statement","external":true},{"path":"plugins/oled-theme/src/tracer.js","kind":"require-call","original":"./tracer"}],"format":"esm"}},"outputs":{"plugins/oled-theme/dist/index.js":{"imports":[{"path":"@neptune","kind":"import-statement","external":true},{"path":"@neptune","kind":"import-statement","external":true}],"exports":["onUnload"],"entryPoint":"plugins/oled-theme/src/index.js","inputs":{"plugins/oled-theme/src/tracer.js":{"bytesInOutput":693},"plugins/oled-theme/src/index.js":{"bytesInOutput":800}},"bytes":1963}}}}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"canvas-confetti": "^1.6.0",
|
||||||
|
"neptune-types": "1.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "OLED Theme",
|
||||||
|
"description": "A working theme. ong.",
|
||||||
|
"author": "itzzexcel@github",
|
||||||
|
"main": "./src/index.js"
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
lockfileVersion: '6.1'
|
||||||
|
|
||||||
|
settings:
|
||||||
|
autoInstallPeers: true
|
||||||
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
canvas-confetti:
|
||||||
|
specifier: ^1.6.0
|
||||||
|
version: 1.6.0
|
||||||
|
|
||||||
|
packages:
|
||||||
|
|
||||||
|
/canvas-confetti@1.6.0:
|
||||||
|
resolution: {integrity: sha512-ej+w/m8Jzpv9Z7W7uJZer14Ke8P2ogsjg4ZMGIuq4iqUOqY2Jq8BNW42iGmNfRwREaaEfFIczLuZZiEVSYNHAA==}
|
||||||
|
dev: false
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
require("./tracer")
|
||||||
|
import { Tracer } from "./tracer";
|
||||||
|
import { intercept, store } from "@neptune"
|
||||||
|
|
||||||
|
const trace = Tracer("[OLED Theme]");
|
||||||
|
const themeUrl = "https://raw.githubusercontent.com/ItzzExcel/neptune-projects/refs/heads/main/themes/black-neptune-theme.css";
|
||||||
|
|
||||||
|
let style;
|
||||||
|
let styleElement;
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
document.head.appendChild(styleElement);
|
||||||
|
return styleElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
function CleanUpCSS() {
|
||||||
|
if (styleElement && styleElement.parentNode) {
|
||||||
|
styleElement.parentNode.removeChild(styleElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function HttpGet(url) {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
}
|
||||||
|
const content = await response.text();
|
||||||
|
return content;
|
||||||
|
} catch (error) {
|
||||||
|
trace.msg.err(`Failed to fetch URL: ${error.message}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since HttpGet is async, we need to await its result
|
||||||
|
(async () => {
|
||||||
|
style = await HttpGet(themeUrl);
|
||||||
|
styleElement = ApplyCSS(style);
|
||||||
|
// trace.msg.log("CSS Applied!");
|
||||||
|
})();
|
||||||
|
|
||||||
|
function onTrackChanged([track]) {
|
||||||
|
/* How to get the album cover URL 💔💔💔 */
|
||||||
|
}
|
||||||
|
|
||||||
|
intercept("playbackControls/PREFILL_MEDIA_PRODUCT_TRANSITION", onTrackChanged);
|
||||||
|
intercept("playbackControls/MEDIA_PRODUCT_TRANSITION", onTrackChanged);
|
||||||
|
|
||||||
|
export function onUnload() {
|
||||||
|
CleanUpCSS();
|
||||||
|
// trace.msg.log("Exiting...");
|
||||||
|
}
|
||||||
@@ -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