|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function () { |
|
'use strict'; |
|
|
|
|
|
function loadNamesFromURL(url, callback) { |
|
GM_xmlhttpRequest({ |
|
method: 'GET', |
|
url: url, |
|
onload: function (response) { |
|
if (response.status === 200) { |
|
const namesText = response.responseText; |
|
const namesList = namesText.split('\n').map(name => name.trim()).filter(Boolean); |
|
callback(namesList); |
|
} else { |
|
console.error('Failed to load Artists from the provided URL.'); |
|
} |
|
}, |
|
onerror: function (error) { |
|
console.error('Error loading Artists:', error); |
|
} |
|
}); |
|
} |
|
|
|
|
|
function addNamesToTextarea(names, count) { |
|
const textarea = document.activeElement; |
|
|
|
if (textarea.tagName === 'TEXTAREA') { |
|
const currentContent = textarea.value; |
|
|
|
|
|
const numberOfNames = count || prompt("How many Artists do you want to add?"); |
|
const namesToAdd = parseInt(numberOfNames, 10); |
|
|
|
if (!isNaN(namesToAdd) && namesToAdd > 0) { |
|
|
|
const randomNames = []; |
|
for (let i = 0; i < namesToAdd; i++) { |
|
const randomIndex = Math.floor(Math.random() * names.length); |
|
|
|
const cleanedName = names[randomIndex].replace(/_/g, ' ').replace(/\(artist\)/g, '\\(artist\\)').trim(); |
|
randomNames.push(cleanedName); |
|
} |
|
|
|
|
|
const formattedNames = randomNames.map(names => `by ${names}`).join(', '); |
|
|
|
|
|
const newContent = currentContent.length > 0 ? currentContent + ', ' + formattedNames : formattedNames; |
|
|
|
|
|
textarea.value = newContent; |
|
} else { |
|
alert('Please enter a valid number greater than 0.'); |
|
} |
|
} else { |
|
alert('Please focus on a textarea before using this script.'); |
|
} |
|
} |
|
|
|
|
|
GM_registerMenuCommand('Add Artists', function () { |
|
const url = 'https://raw.githubusercontent.com/CryDotCom/Random-E621-Artist-A1111/main/Artist-Names-E621.txt'; |
|
loadNamesFromURL(url, function (names) { |
|
addNamesToTextarea(names); |
|
}); |
|
}); |
|
})(); |
|
|