mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
chore: remove miHoYo parser from first-party scrapers
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
<div class="flexFlowColumn flex-container">
|
|
||||||
<div class="range-block-title">
|
|
||||||
<h3 data-i18n="miHoYo/HoYoverse HoYoLAB Scraper">miHoYo/HoYoverse HoYoLAB Scraper</h3>
|
|
||||||
</div>
|
|
||||||
<h4 data-i18n="Select a Wiki to parse through.">Select a Wiki to parse through.</h4>
|
|
||||||
<div class="range-block-range wide100p">
|
|
||||||
<select id="mihoyoScrapeWikiDropdown" name="mihoyoScrapeWikiDropdown" class="wide100p">
|
|
||||||
<option value="">--- None ---</option>
|
|
||||||
<option value="hsr" data-i18n="Honkai: Star Rail (H:SR)">Honkai: Star Rail (H:SR)</option>
|
|
||||||
<option value="genshin" data-i18n="Genshin Impact (GI)">Genshin Impact (GI)</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="range-block-title">
|
|
||||||
<h4>
|
|
||||||
<span data-i18n="Enter the Wiki Page ID.">Enter the Wiki Page ID.</span>
|
|
||||||
</h4>
|
|
||||||
</div>
|
|
||||||
<div class="range-block-counter justifyCenter flex-container flexFlowColumn margin-bot-10px">
|
|
||||||
<span data-i18n="This is the last digit in the HoYoLAB URL i.e.">This is the last digit in the HoYoLAB URL i.e.</span>
|
|
||||||
<code>https://wiki.hoyolab.com/pc/hsr/entry/X</code>
|
|
||||||
<small>
|
|
||||||
<span data-i18n="Example:">Example:</span>
|
|
||||||
<code>14</code>
|
|
||||||
</small>
|
|
||||||
</div>
|
|
||||||
<input type="text" id="mihoyoScrapeWikiID" name="mihoyoScrapeWikiID" class="text_pole" placeholder="14">
|
|
||||||
</div>
|
|
@@ -362,153 +362,6 @@ class FandomScraper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Scrapes data from the miHoYo/HoYoverse HoYoLAB wiki.
|
|
||||||
* @implements {Scraper}
|
|
||||||
*/
|
|
||||||
class miHoYoScraper {
|
|
||||||
constructor() {
|
|
||||||
this.id = 'mihoyo';
|
|
||||||
this.name = 'miHoYo';
|
|
||||||
this.description = 'Scrapes a page from the miHoYo/HoYoverse HoYoLAB wiki.';
|
|
||||||
this.iconClass = 'img/mihoyo.svg';
|
|
||||||
this.iconAvailable = false; // There is no miHoYo icon in Font Awesome
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the scraper is available.
|
|
||||||
* @returns {Promise<boolean>}
|
|
||||||
*/
|
|
||||||
async isAvailable() {
|
|
||||||
try {
|
|
||||||
const result = await fetch('/api/plugins/hoyoverse/probe', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: getRequestHeaders(),
|
|
||||||
});
|
|
||||||
|
|
||||||
return result.ok;
|
|
||||||
} catch (error) {
|
|
||||||
console.debug('Could not probe miHoYo plugin', error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Outputs Data Information in a human-readable format.
|
|
||||||
* @param {Object} m Data to be parsed
|
|
||||||
* @returns {string} Human-readable format of the data
|
|
||||||
*/
|
|
||||||
parseOutput(m) {
|
|
||||||
let temp = '';
|
|
||||||
for (const d in m) {
|
|
||||||
if (m[d].key === "") {
|
|
||||||
temp += `- ${m[d].value}\n`;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
temp += `- ${m[d].key}: ${m[d].value}\n`;
|
|
||||||
}
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Scrape data from the miHoYo/HoYoverse HoYoLAB wiki.
|
|
||||||
* @returns {Promise<File[]>} File attachments scraped from the wiki.
|
|
||||||
*/
|
|
||||||
|
|
||||||
async scrape() {
|
|
||||||
let miHoYoWiki = '';
|
|
||||||
let miHoYoWikiID = '';
|
|
||||||
|
|
||||||
const template = $(await renderExtensionTemplateAsync('attachments', 'mihoyo-scrape', {}));
|
|
||||||
|
|
||||||
template.find('select[name="mihoyoScrapeWikiDropdown"]').on('change', function () {
|
|
||||||
miHoYoWiki = String($(this).val());
|
|
||||||
});
|
|
||||||
template.find('input[name="mihoyoScrapeWikiID"]').on('input', function () {
|
|
||||||
miHoYoWikiID = String($(this).val());
|
|
||||||
});
|
|
||||||
|
|
||||||
const confirm = await callGenericPopup(template, POPUP_TYPE.CONFIRM, '', { wide: false, large: false });
|
|
||||||
|
|
||||||
if (confirm !== POPUP_RESULT.AFFIRMATIVE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!miHoYoWiki) {
|
|
||||||
toastr.error('A specific HoYoLab wiki is required');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!miHoYoWikiID) {
|
|
||||||
toastr.error('A specific HoYoLab wiki ID is required');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (miHoYoWiki === 'genshin') {
|
|
||||||
toastr.error('The Genshin Impact parser has not been implemented *yet*');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let toast;
|
|
||||||
if (miHoYoWiki === 'hsr') {
|
|
||||||
toast = toastr.info(`Scraping the Honkai: Star Rail HoYoLAB wiki for Wiki Entry ID: ${miHoYoWikiID}`);
|
|
||||||
} else {
|
|
||||||
toast = toastr.info(`Scraping the Genshin Impact wiki for Wiki Entry ID: ${miHoYoWikiID}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let result;
|
|
||||||
if (miHoYoWiki === 'hsr') {
|
|
||||||
result = await fetch('/api/plugins/hoyoverse/silver-wolf', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: getRequestHeaders(),
|
|
||||||
body: JSON.stringify({ miHoYoWiki, miHoYoWikiID }),
|
|
||||||
});
|
|
||||||
} else if (miHoYoWiki === 'genshin') {
|
|
||||||
result = await fetch('/api/plugins/hoyoverse/furina', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: getRequestHeaders(),
|
|
||||||
body: JSON.stringify({ miHoYoWiki, miHoYoWikiID }),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
throw new Error('Unknown wiki name identifier');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
const error = await result.text();
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await result.json();
|
|
||||||
toastr.clear(toast);
|
|
||||||
|
|
||||||
const fileName = data[0].name;
|
|
||||||
const dataContent = data[0].content;
|
|
||||||
|
|
||||||
//parse the data as a long string of data
|
|
||||||
let combinedContent = '';
|
|
||||||
combinedContent += `Name: ${data[0].name}\n`;
|
|
||||||
|
|
||||||
if (dataContent.description !== "") {
|
|
||||||
combinedContent += `Description: ${dataContent.description}\n\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataContent.modules != []) {
|
|
||||||
for (const m in dataContent.modules) {
|
|
||||||
if (dataContent.modules[m].data.length === 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
combinedContent += dataContent.modules[m].name + '\n';
|
|
||||||
combinedContent += this.parseOutput(dataContent.modules[m].data);
|
|
||||||
combinedContent += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const file = new File([combinedContent], `${fileName}.txt`, { type: 'text/plain' });
|
|
||||||
|
|
||||||
return [file];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrape transcript from a YouTube video.
|
* Scrape transcript from a YouTube video.
|
||||||
* @implements {Scraper}
|
* @implements {Scraper}
|
||||||
@@ -584,5 +437,4 @@ ScraperManager.registerDataBankScraper(new FileScraper());
|
|||||||
ScraperManager.registerDataBankScraper(new Notepad());
|
ScraperManager.registerDataBankScraper(new Notepad());
|
||||||
ScraperManager.registerDataBankScraper(new WebScraper());
|
ScraperManager.registerDataBankScraper(new WebScraper());
|
||||||
ScraperManager.registerDataBankScraper(new FandomScraper());
|
ScraperManager.registerDataBankScraper(new FandomScraper());
|
||||||
ScraperManager.registerDataBankScraper(new miHoYoScraper());
|
|
||||||
ScraperManager.registerDataBankScraper(new YouTubeScraper());
|
ScraperManager.registerDataBankScraper(new YouTubeScraper());
|
||||||
|
Reference in New Issue
Block a user