舰R百科是靠无数志愿编辑者持续地建设更新完善的。编辑非常简单,无需代码知识,请勇于更新页面!
编辑入门 | 资助百科 | 留言讨论页 | 微博@舰R百科 | 百科编辑讨论Q群:366818861

MediaWiki:Gadget-search-new-tab.js

来自舰R百科
跳转到导航 跳转到搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存

如果您已登陆但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码?id=1来访问最新页面,添加代码后的本页地址如下: https://www.zjsnrwiki.com/wiki/MediaWiki:Gadget-search-new-tab.js?id=1

/* JSHint-valid */
/* globals $:false */
$(function() {
	// Special:Search for all skins.
	$('#powersearch, #search').on('keydown', function(e) {
		$(this).prop('target', e.ctrlKey || e.metaKey ? '_blank' : '');
	});

	// CodexTypeaheadSearch header search [only on Vector (2022)].
	$('#p-search').on('keydown', '.cdx-typeahead-search #searchform', function(e) {
		if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
			var URI = $(this).find('.cdx-menu-item--selected a.cdx-menu-item__content').prop('href');
			if (URI != undefined) {
				window.open(URI, '_blank');
				return false;
			}
		}
	});

	// Header/Side search on other skins [no auto suggest nav on MinervaNeue].
	// Search box [auto suggest on Vector legacy (2010), MonoBook, Timeless].
	$('div:not(.cdx-typeahead-search) #searchform #searchInput, .searchbox .mw-searchInput').on('keydown', function(e) {
		if ((e.ctrlKey || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
			if ($(this).data('suggestionsContext') != undefined) {
				var selectedIndex = $(this).data('suggestionsContext').config.suggestions.indexOf($(this).val());
				if (selectedIndex != -1) {
					var URI = $('.suggestions-results a:nth-child(' + (selectedIndex + 1) + ')').prop('href');
					if (URI != undefined) {
						window.open(URI, '_blank');
						$(this).trigger('blur');
					}
				}
			}
		}
	});
});