From 248f4a21d4db90bfeffa0bf33a1f6359627cb058 Mon Sep 17 00:00:00 2001 From: "DESKTOP-KSVGT20\\shkim" Date: Sat, 2 May 2026 00:28:50 +0900 Subject: [PATCH] Use Tampermonkey requests for Suno WAV checks --- chatgpt-suno-tampermonkey.user.js | 92 ++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 15 deletions(-) diff --git a/chatgpt-suno-tampermonkey.user.js b/chatgpt-suno-tampermonkey.user.js index 53d91bf..a13c672 100644 --- a/chatgpt-suno-tampermonkey.user.js +++ b/chatgpt-suno-tampermonkey.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name ChatGPT to Suno Prompt Copier // @namespace local.suno-helper -// @version 0.7.6 +// @version 0.7.7 // @description Copy structured ChatGPT song prompt versions into Suno fields. // @author local // @match https://chatgpt.com/* @@ -19,6 +19,7 @@ // @grant GM_addStyle // @grant GM_getValue // @grant GM_download +// @grant GM_xmlhttpRequest // @grant GM_setClipboard // @grant GM_setValue // @grant unsafeWindow @@ -27,7 +28,7 @@ (function () { "use strict"; - const SCRIPT_VERSION = "0.7.6"; + const SCRIPT_VERSION = "0.7.7"; const STORAGE_KEY = "chatgptSunoPromptSlots"; const SLOT_COUNT = 2; const isChatGPT = location.hostname.includes("chatgpt.com") || location.hostname.includes("chat.openai.com"); @@ -817,20 +818,10 @@ } async function callSunoJson(url, options = {}) { - const page = typeof unsafeWindow !== "undefined" ? unsafeWindow : window; - const response = await page.fetch(url, { - credentials: "include", - ...options, - headers: { - "accept": "application/json, text/plain, */*", - ...(options.method && options.method !== "GET" ? { "content-type": "application/json" } : {}), - ...(options.headers || {}), - }, - }); - const finalUrl = response.url || url; - const finalWavUrl = extractWavUrl(finalUrl); + const response = await callSunoText(url, options); + const finalWavUrl = extractWavUrl(response.finalUrl || url); if (response.ok && finalWavUrl) return finalWavUrl; - const text = await response.text(); + const text = response.text || ""; const data = tryParseJson(text) || text; rememberSunoResponse(url, data); if (!response.ok) { @@ -839,6 +830,66 @@ return data; } + async function callSunoText(url, options = {}) { + const page = typeof unsafeWindow !== "undefined" ? unsafeWindow : window; + const headers = { + "accept": "application/json, text/plain, */*", + ...(options.method && options.method !== "GET" && options.method !== "HEAD" ? { "content-type": "application/json" } : {}), + ...(options.headers || {}), + }; + try { + const response = await page.fetch(url, { + credentials: "include", + ...options, + headers, + }); + const finalUrl = response.url || url; + if (response.ok && extractWavUrl(finalUrl)) { + return { + ok: true, + status: response.status, + statusText: response.statusText, + finalUrl, + text: "", + }; + } + return { + ok: response.ok, + status: response.status, + statusText: response.statusText, + finalUrl, + text: await response.text(), + }; + } catch (fetchError) { + if (typeof GM_xmlhttpRequest !== "function") throw fetchError; + return callTampermonkeyRequest(url, { ...options, headers }); + } + } + + function callTampermonkeyRequest(url, options = {}) { + return new Promise((resolve, reject) => { + GM_xmlhttpRequest({ + method: options.method || "GET", + url, + headers: options.headers || {}, + data: options.body, + anonymous: false, + timeout: 45000, + onload: (response) => { + resolve({ + ok: response.status >= 200 && response.status < 300, + status: response.status, + statusText: response.statusText || "", + finalUrl: response.finalUrl || url, + text: response.responseText || "", + }); + }, + onerror: (error) => reject(new Error(error?.error || "GM_xmlhttpRequest failed")), + ontimeout: () => reject(new Error("GM_xmlhttpRequest timeout")), + }); + }); + } + function extractWavUrl(value) { if (!value) return ""; if (typeof value === "string") { @@ -900,6 +951,17 @@ } catch (error) { console.warn("[ChatGPT to Suno] URL probe failed", url, error); } + if (typeof GM_xmlhttpRequest === "function") { + try { + const response = await callTampermonkeyRequest(url, { + ...options, + headers: options.headers || {}, + }); + if (response.ok || response.status === 206) return true; + } catch (error) { + console.warn("[ChatGPT to Suno] GM URL probe failed", url, error); + } + } } return false; }