Javascript 在Twitch以外的网站上使用BettertV或FrankerFaceZ
除了twitch.tv之外,有没有其他方法可以使用eg或其他网站来取代表情 我想在twitch上显示在线警报(通过浏览器源代码实现)。发送的信息通常包含类似OMEGALUL或PogU的表情符号 我知道我可以下载图片并替换字符串中的表情。这已经在起作用了。但是,总是缺少一些emote(因为我需要全部实现它们) 那么,除了twitch之外,有没有一种方法可以在其他页面上使用表情替换系统呢 所以我要传达这个信息Javascript 在Twitch以外的网站上使用BettertV或FrankerFaceZ,javascript,replace,twitch,emoticons,Javascript,Replace,Twitch,Emoticons,除了twitch.tv之外,有没有其他方法可以使用eg或其他网站来取代表情 我想在twitch上显示在线警报(通过浏览器源代码实现)。发送的信息通常包含类似OMEGALUL或PogU的表情符号 我知道我可以下载图片并替换字符串中的表情。这已经在起作用了。但是,总是缺少一些emote(因为我需要全部实现它们) 那么,除了twitch之外,有没有一种方法可以在其他页面上使用表情替换系统呢 所以我要传达这个信息 Hey PogU :) 应该成为 Hey <img src="....&
Hey PogU :)
应该成为
Hey <img src="...."> :)
嘿:)
我没有发现任何可能性,但至少对于BetterTV来说,实现javascript文件的选项是有办法的。这不是我最初的意图,因为这仅限于我下载的表情,但我快速而肮脏的方法是(使用Laravel-因此纯php将没有像
storage\u path
或dd
这样的助手):
注意:这些下载需要相当长的时间。因此,如果您仅使用eg 30sphp超时运行它们,则会遇到超时。因此,可以从CLI启动,或者将时间限制设置为无限(例如set_time_limit(0);
或在php.ini中:max_execution_time=0
)
步骤1:下载表情
备选方案1:BTTV
2) 下载PHP中的图像
你有没有在这里之外找到解决方案?我正在尝试做同样的事情,目前!嘿@AaronSoto,不幸的是没有。但我刚刚发布了我的方法(有一些缺点)作为您的答案;)
<?php
// Download emotes first and put them into a json (multiple times using offset): https://api.betterttv.net/3/emotes/shared/top?offset=1199&limit=100
// Merge them into one emotes.json file
function downloadBTTV() {
$emotes = json_decode(file_get_contents(storage_path('emotes.json')), false, 512, JSON_THROW_ON_ERROR);
$used_filenames = [];
$used_emotes = [];
foreach($emotes as $emote) {
try{
$url = 'https://cdn.betterttv.net/emote/' . $emote->emote->id . '/1x';
$filename = $emote->emote->code . '.' . $emote->emote->imageType;
if(!isset($used_filenames[$filename])) {
$used_filenames[$filename] = 0;
}
$used_filenames[$filename]++;
$full_filename = storage_path('emotes/' . $filename);
if(!is_file($full_filename) && in_array($emotes->emote->code, $used_emotes)) {
file_put_contents($full_filename, file_get_contents($url));
$used_emotes[] = $emote->emote->code;
}
} catch(\Exception $e) {
dd(get_defined_vars(), $emote);
}
}
}
<?php
// 2a) Create a variable like that from the clipboard (copied in javascript in step 1)
$ffz_emotes_json = <<<'EOL'
{
"pog": "210748",
"omegalul": "128054",
//...
}
EOL;
function downloadFFZ() {
global $ffz_emotes_json;
$emotes = json_decode($ffz_emotes_json, true, 512, JSON_THROW_ON_ERROR);
$new_emotes = [];
$skipped_emotes = [];
foreach($emotes as $emote => $id) {
$url = 'https://cdn.frankerfacez.com/emoticon/' . $id . '/1';
$filename = $emote . '.png';
$filename_gif = $emote . '.gif';
$full_filename_png = storage_path('emotes/' . $filename);
$full_filename_gif = storage_path('emotes/' . $filename_gif);
if(!is_file($full_filename_png) && !is_file($full_filename_gif) ) {
file_put_contents($full_filename_png, file_get_contents($url));
$new_emotes[] = $emote;
} else {
$skipped_emotes[] = $emote;
}
}
dd($new_emotes, $skipped_emotes);
}
<?php
function generateEmotesJS()
{
$files = glob(public_path('img/emotes/*'));
echo "window.EMOTES = {\n";
/** @var DirectoryIterator $fileInfo */
foreach (new DirectoryIterator(public_path('img/emotes/*')) as $fileInfo) {
if($fileInfo->isDot()) continue;
echo ' "' . $fileInfo->getBasename('.' .$fileInfo->getExtension()) .'": "' . $fileInfo->getExtension() . "\",\n";
}
echo "};";
}
// store this output in your javascript file