Restrict Suno library detection to current user rows
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name ChatGPT to Suno Prompt Copier
|
// @name ChatGPT to Suno Prompt Copier
|
||||||
// @namespace local.suno-helper
|
// @namespace local.suno-helper
|
||||||
// @version 0.4.1
|
// @version 0.4.2
|
||||||
// @description Copy structured ChatGPT song prompt versions into Suno fields.
|
// @description Copy structured ChatGPT song prompt versions into Suno fields.
|
||||||
// @author local
|
// @author local
|
||||||
// @match https://chatgpt.com/*
|
// @match https://chatgpt.com/*
|
||||||
@@ -595,6 +595,10 @@
|
|||||||
const style = firstValue(object, ["gpt_description_prompt", "style", "tags", "description"]);
|
const style = firstValue(object, ["gpt_description_prompt", "style", "tags", "description"]);
|
||||||
const model = firstValue(object, ["model_name", "model", "major_model_version"]);
|
const model = firstValue(object, ["model_name", "model", "major_model_version"]);
|
||||||
const createdAt = firstValue(object, ["created_at", "createdAt"]);
|
const createdAt = firstValue(object, ["created_at", "createdAt"]);
|
||||||
|
const owner = firstValue(object, ["username", "user_name", "userName", "handle", "user_handle", "userHandle", "display_name", "displayName"]);
|
||||||
|
const ownerFromUser = object.user && typeof object.user === "object"
|
||||||
|
? firstValue(object.user, ["username", "user_name", "userName", "handle", "display_name", "displayName"])
|
||||||
|
: "";
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
@@ -602,6 +606,7 @@
|
|||||||
style,
|
style,
|
||||||
model,
|
model,
|
||||||
createdAt,
|
createdAt,
|
||||||
|
owner: owner || ownerFromUser,
|
||||||
audioUrl,
|
audioUrl,
|
||||||
wavUrl,
|
wavUrl,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
@@ -627,6 +632,12 @@
|
|||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCurrentSunoUsername() {
|
||||||
|
const text = document.body.innerText || "";
|
||||||
|
const match = /([A-Za-z0-9_.-]{3,40})\s+\d+\s+credits/i.exec(text);
|
||||||
|
return match?.[1] || "";
|
||||||
|
}
|
||||||
|
|
||||||
function getVisibleLibraryRows() {
|
function getVisibleLibraryRows() {
|
||||||
const rows = [];
|
const rows = [];
|
||||||
const seen = new Set();
|
const seen = new Set();
|
||||||
@@ -662,7 +673,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function trackMatchesVisibleRows(track, rows) {
|
function trackMatchesVisibleRows(track, rows) {
|
||||||
if (!rows.length) return true;
|
if (!rows.length) return false;
|
||||||
const title = normalizeMatchText(track.title);
|
const title = normalizeMatchText(track.title);
|
||||||
const style = normalizeMatchText(track.style || track.lyrics || "");
|
const style = normalizeMatchText(track.style || track.lyrics || "");
|
||||||
if (!title || title.length > 160) return false;
|
if (!title || title.length > 160) return false;
|
||||||
@@ -674,6 +685,11 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trackMatchesCurrentUser(track, username) {
|
||||||
|
if (!username || !track.owner) return true;
|
||||||
|
return normalizeMatchText(track.owner) === normalizeMatchText(username);
|
||||||
|
}
|
||||||
|
|
||||||
function scanSunoLibraryTracks() {
|
function scanSunoLibraryTracks() {
|
||||||
const sources = readSunoDataSources();
|
const sources = readSunoDataSources();
|
||||||
const objects = sources.flatMap((item) => flattenObjects(item));
|
const objects = sources.flatMap((item) => flattenObjects(item));
|
||||||
@@ -706,8 +722,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const visibleRows = getVisibleLibraryRows();
|
const visibleRows = getVisibleLibraryRows();
|
||||||
|
const currentUser = getCurrentSunoUsername();
|
||||||
return [...tracks.values()]
|
return [...tracks.values()]
|
||||||
.filter((track) => track.id || track.audioUrl || track.imageUrl)
|
.filter((track) => track.id || track.audioUrl || track.imageUrl)
|
||||||
|
.filter((track) => trackMatchesCurrentUser(track, currentUser))
|
||||||
.filter((track) => trackMatchesVisibleRows(track, visibleRows))
|
.filter((track) => trackMatchesVisibleRows(track, visibleRows))
|
||||||
.sort((a, b) => String(a.title).localeCompare(String(b.title), "ko"));
|
.sort((a, b) => String(a.title).localeCompare(String(b.title), "ko"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user