diff --git a/Isekai.class.php b/Isekai.class.php index 1ad69d2..c404cde 100644 --- a/Isekai.class.php +++ b/Isekai.class.php @@ -41,7 +41,7 @@ class Isekai { $outputPage->addModuleStyles('ext.isekai.styles'); $outputPage->addModules('ext.isekai'); - $outputPage->addModules('ext.fontawesome'); + //$outputPage->addModules('ext.fontawesome'); //$outputPage->addModules('ext.treeview'); // 加载动画,三秒内未加载完成则强制显示 @@ -84,6 +84,10 @@ var _hmt = _hmt || []; HTML ); + if ($outputPage->getUser() && $outputPage->getUser()->isRegistered()) { + $outputPage->addBodyClasses(['logged-in']); + } + self::showAds($outputPage); } @@ -114,6 +118,7 @@ HTML $outputPage->addHTML( << +window.addEventListener('load', function () { if (window.innerWidth >= 1100) { var adElem = document.createElement('div'); adElem.className = 'googlead-container googlead-container-sidebar'; @@ -124,6 +129,7 @@ HTML (adsbygoogle = window.adsbygoogle || []).push({}); } } +}) HTML ); @@ -176,44 +182,76 @@ HTML if (!$outputPage->isArticle()) return; $title = $outputPage->getTitle(); - if ($title && $title->isSubpage()) { - //更改显示的标题 - $titleText = $title->getPrefixedText(); - - $baseTitleText = basename($titleText); - $htmlTitle = $outputPage->getHTMLTitle(); - if (strpos($htmlTitle, $baseTitleText) === 0) { - // 将HTML标题替换为完整标题 - $outputPage->setHTMLTitle($titleText . substr($htmlTitle, strlen($baseTitleText))); - } + if ($title) { + if ($title->isSubpage()) { + //更改显示的标题 + $titleText = $title->getPrefixedText(); + + $currentDisplayTitle = $outputPage->getDisplayTitle(); + $htmlTitle = $outputPage->getHTMLTitle(); + if (strpos($htmlTitle, $currentDisplayTitle) === 0) { + // 将HTML标题替换为完整标题 + $htmlTitleText = $currentDisplayTitle . ' (' . dirname($titleText) . ')'; + $outputPage->setHTMLTitle($htmlTitleText . substr($htmlTitle, strlen($currentDisplayTitle))); + $outputPage->addMeta('title', $htmlTitleText); + } - //面包屑 - $titlePathList = explode('/', $titleText); - $titlePathLen = count($titlePathList); - $breadcrumbsHtml = [ - Html::openElement('ol', ['class' => 'breadcrumb']), - ]; - $linkRender = MediaWikiServices::getInstance()->getLinkRenderer(); - foreach ($titlePathList as $key => $titleName) { - if ($key === $titlePathLen - 1) { - $breadcrumbsHtml[] = Html::element('li', ['class' => 'active'], $titleName); - } else { - $titleSubPath = implode('/', array_slice($titlePathList, 0, $key + 1)); - $currentTitle = Title::newFromText($titleSubPath); - if ($currentTitle) { - $link = $linkRender->makeLink(Title::newFromText($titleSubPath), $titleName); + //面包屑 + $titlePathList = explode('/', $titleText); + $titlePathLen = count($titlePathList); + $breadcrumbsHtml = [ + Html::openElement('ol', ['class' => 'breadcrumb']), + ]; + $linkRender = MediaWikiServices::getInstance()->getLinkRenderer(); + foreach ($titlePathList as $key => $titleName) { + if ($key === $titlePathLen - 1) { + $breadcrumbsHtml[] = Html::element('li', ['class' => 'active'], $titleName); } else { - $link = $titleSubPath; + $titleSubPath = implode('/', array_slice($titlePathList, 0, $key + 1)); + $currentTitle = Title::newFromText($titleSubPath); + if ($currentTitle) { + $link = $linkRender->makeLink(Title::newFromText($titleSubPath), $titleName); + } else { + $link = $titleSubPath; + } + + if ($key === 0) { + $breadcrumbsHtml[] = Html::openElement('li', ['class' => 'root']) . $link . Html::closeElement('li'); + } else { + $breadcrumbsHtml[] = Html::openElement('li') . $link . Html::closeElement('li'); + } + + $breadcrumbsHtml[] = Html::openElement('span', ['class' => 'breadcrumb-divider']) . '/' . Html::closeElement('span'); } - $breadcrumbsHtml[] = Html::openElement('li') . $link . Html::closeElement('li'); } - } - $breadcrumbsHtml[] = Html::closeElement('ol'); - $html = implode($breadcrumbsHtml); + $breadcrumbsHtml[] = Html::closeElement('ol'); + $html = implode($breadcrumbsHtml); - // 阻止出现subtitle空行 - $subtitle = $outputPage->getSubtitle(); - $outputPage->setSubtitle($subtitle . $html); + // 阻止出现subtitle空行 + $subtitle = $outputPage->getSubtitle(); + $outputPage->setSubtitle($subtitle . $html); + } else { + $currentDisplayTitle = $outputPage->getDisplayTitle(); + if ($currentDisplayTitle) { + $currentDisplayTitle = strip_tags($currentDisplayTitle); + $outputPage->addMeta('title', $currentDisplayTitle); + + if ($currentDisplayTitle !== $title->getPrefixedText()) { + // 输出原标题 + $breadcrumbsHtml = [ + Html::openElement('ol', ['class' => 'breadcrumb']), + Html::element('li', ['class' => 'root active'], $title->getPrefixedText()), + Html::closeElement('ol'), + ]; + $html = implode($breadcrumbsHtml); + + $subtitle = $outputPage->getSubtitle(); + $outputPage->setSubtitle($subtitle . $html); + } + } else { + $outputPage->addMeta('title', $title->getPrefixedText()); + } + } } } @@ -224,7 +262,7 @@ HTML //更改显示的标题 $titleText = $title->getPrefixedText(); if ($titleText) { - $parser->getOutput()->setTitleText('' . basename($titleText) . ''); + $parser->getOutput()->setTitleText(basename($titleText)); } } } @@ -296,4 +334,31 @@ HTML 'section' => 'misc/isekai-ads', ]; } + + public static function onCirrusSearchAnalysisConfig(array &$config, $builder) { + if (isset($config['filter']['smartcn_stop'])) { // 处理中文Analysis Config + + } + } + + public static function onMugenAppGetAvatar(&$avatarUrl, $size, $user) { + if (!$user) { + $avatarUrl = "https://account.isekai.cn/realms/isekai/avatar/default"; + return; + } + + $userName = $user->getName(); + + $avatarBase = 'https://account.isekai.cn/realms/isekai/avatar/by-username/' . $userName; + + if ($size <= 64) { + $avatarUrl = "$avatarBase?size=md"; + } else if ($size <= 128) { + $avatarUrl = "$avatarBase?size=lg"; + } else if ($size <= 256) { + $avatarUrl = "$avatarBase?size=xl"; + } else { + $avatarUrl = "$avatarBase?size=xxl"; + } + } } diff --git a/extension.json b/extension.json index b0c3dbd..e5dfc8b 100644 --- a/extension.json +++ b/extension.json @@ -45,6 +45,12 @@ ], "EditPage::attemptSave": [ "Isekai\\Isekai::onAttemptSave" + ], + "CirrusSearchAnalysisConfig": [ + "Isekai\\Isekai::onCirrusSearchAnalysisConfig" + ], + "MugenAppGetAvatar": [ + "Isekai\\Isekai::onMugenAppGetAvatar" ] }, "ResourceModules": { @@ -52,7 +58,8 @@ "scripts": ["ext.isekai.js"], "dependencies": [ "oojs-ui-core", - "oojs-ui-windows" + "oojs-ui-windows", + "mediawiki.user" ], "targets": [ "desktop", @@ -72,7 +79,8 @@ "isekai-ads-prompt-title", "isekai-ads-prompt-content", "isekai-ads-prompt-btn-cancel", - "nav-login-createaccount" + "nav-login-createaccount", + "visualeditor-savedialog-label-set-categories" ] }, "ext.isekai.styles": { diff --git a/i18n/en.json b/i18n/en.json index cb585ca..5246b90 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -30,5 +30,7 @@ "isekai-ads-prompt-title": "Please allow ads on Fanta World Wiki", "isekai-ads-prompt-content": "
Looks like you're using an ad blocker.
Fanta World Wiki rely on advertising to help fund our site.
If you want to support Fanta World Wiki, you can turn off Adblock, Adblock Pro, and other plugins on this site.
", - "isekai-ads-prompt-btn-cancel": "No longer display" + "isekai-ads-prompt-btn-cancel": "No longer display", + + "visualeditor-savedialog-label-set-categories": "Select categories" } \ No newline at end of file diff --git a/i18n/zh-hans.json b/i18n/zh-hans.json index d33343b..1633954 100644 --- a/i18n/zh-hans.json +++ b/i18n/zh-hans.json @@ -30,5 +30,7 @@ "isekai-ads-prompt-title": "您似乎屏蔽了广告", "isekai-ads-prompt-content": "目前,页面广告是异世界百科的唯一收入来源。
如果您想要支持异世界百科,可以在此站点上关闭Adblock、Adblock Pro等插件。
如果想要移除广告空位,可以在用户-参数设置中关闭广告。
", - "isekai-ads-prompt-btn-cancel": "不再显示" + "isekai-ads-prompt-btn-cancel": "不再显示", + + "visualeditor-savedialog-label-set-categories": "设置分类" } \ No newline at end of file diff --git a/i18n/zh-hant.json b/i18n/zh-hant.json index d520500..df9af09 100644 --- a/i18n/zh-hant.json +++ b/i18n/zh-hant.json @@ -30,5 +30,7 @@ "isekai-ads-prompt-title": "您似乎屏蔽了廣告", "isekai-ads-prompt-content": "目前,頁面廣告是異世界百科的唯一收入來源。
如果您想要支持異世界百科,可以在此網站上關閉Adblock、Adblock Pro等擴展程式。
如果想要移除廣告空位,可以在用戶-參數設置中關閉廣告。
", - "isekai-ads-prompt-btn-cancel": "不再顯示" + "isekai-ads-prompt-btn-cancel": "不再顯示", + + "visualeditor-savedialog-label-set-categories": "設置分類" } \ No newline at end of file diff --git a/modules/ext.isekai.less b/modules/ext.isekai.less index 56bde55..8a1d44a 100644 --- a/modules/ext.isekai.less +++ b/modules/ext.isekai.less @@ -140,6 +140,17 @@ html.content-loaded body.skin-timeless { color: #fff; } +@media (prefers-color-scheme: dark) { + body.auto-color-scheme .black-space { + background-color: #fff; + color: #fff; + + &:hover { + color: #222; + } + } +} + #toc > ul { overflow-y: auto; max-height: 50vh; @@ -188,6 +199,7 @@ html.content-loaded body.skin-timeless { background-color: #f5f5f5; border-radius: 4px; margin-block-start: 0; + margin-left: 0; font-size: 14px; > li { @@ -198,10 +210,15 @@ html.content-loaded body.skin-timeless { } } - > li+li:before { + .breadcrumb-divider { padding: 0 5px; color: #ccc; - content: "/\00a0"; + } + + > li.root:before { + padding: 0 5px 0 0; + color: #ccc; + content: "/"; } a { @@ -261,4 +278,10 @@ html.content-loaded body.skin-timeless { .googlead-container-sidebar { display: none; } +} +// 对登录用户隐藏标题 +@media (max-width: 576px) { + .logged-in #p-logo-text { + display: none; + } } \ No newline at end of file diff --git a/specials/SpecialGetPageModules.php b/specials/SpecialGetPageModules.php new file mode 100644 index 0000000..0c049f7 --- /dev/null +++ b/specials/SpecialGetPageModules.php @@ -0,0 +1,7 @@ +