This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/filter/main.php
Shish f84bcaec01 microhtml for everything in <head>
I wanted to ensure that all pages (even the downtime page, terms page, home page, etc) had the appropriate `data-` attributes on `<body>` (because those are required for certain javascript, eg autocomplete, to work). One thing led to another and now everything in `head` is microhtml'ed
2024-06-21 18:52:05 +01:00

51 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace Shimmie2;
use function MicroHTML\SCRIPT;
class Filter extends Extension
{
/** @var FilterTheme */
protected Themelet $theme;
public function onInitExt(InitExtEvent $event): void
{
global $config;
$config->set_default_string("filter_tags", "spoilers\nguro\nscat\nfurry -rating:s\n");
}
public function onPageRequest(PageRequestEvent $event): void
{
global $page;
$this->theme->addFilterBox();
$page->add_html_header(SCRIPT("
Array.from(document.getElementsByClassName('thumb')).forEach(function(post) {
post.style.display='none';
});"));
}
public function onSetupBuilding(SetupBuildingEvent $event): void
{
$sb = $event->panel->create_new_block("Filters");
$sb->add_longtext_option("filter_tags", 'Default filtered tags');
$sb->add_label("This controls the tags which are hidden by default. This feature currently requires JavaScript. Separate filters by line, or by commas. You can enter multiple tags per filter, as well as negative tags.");
}
public function onInitUserConfig(InitUserConfigEvent $event): void
{
global $config;
$event->user_config->set_default_string("filter_tags", $config->get_string("filter_tags"));
}
public function onUserOptionsBuilding(UserOptionsBuildingEvent $event): void
{
global $user;
$sb = $event->panel->create_new_block("Filters");
$sb->add_longtext_option("filter_tags", 'Default filtered tags');
$sb->add_label("This controls the tags which are hidden by default. This feature currently requires JavaScript. Separate filters by line, or by commas. You can enter multiple tags per filter, as well as negative tags.");
}
}