Kanka Content Search Shortcut

Adds a link to the Search page to top bar search results, in addition to entity title matches.

当前为 2021-12-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Kanka Content Search Shortcut
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Adds a link to the Search page to top bar search results, in addition to entity title matches.
// @author       Salvatos
// @match        https://kanka.io/*
// @icon         https://www.google.com/s2/favicons?domain=kanka.io
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==


GM_addStyle(`
#content-search-prompt {
	background: white;
	border: 1px solid grey;
	border-color: var(--search-border);
	background-color: var(--search-background);
	margin-bottom: 0;
	border-bottom-right-radius: 4px;
	border-bottom-left-radius: 4px;
	border-top: transparent;
}
#content-search-prompt:hover {
	text-decoration: none;
	background-color: #f5f5f5;
}
#content-search-prompt a {
	display: block;
	color: var(--search-cursor-text) !important;
	padding: 10px 15px;
}
`);

// Prepare base URL for this campaign
const campaignPath = location.pathname.split("/", 4);
let campaign = location.origin + campaignPath.join("/");

// On input, update link
$("#live-search").on("input", updSugg);

function updSugg() {
	let searchtext = $("#live-search").val();
	// Create a container the first time around
	if ($("#content-search-prompt").length == 0) {
		$("#live-search_listbox")[0].insertAdjacentHTML("beforeend", "<div id='content-search-prompt' class='tt-dataset tt-dataset-entityList'></div>");
	}
	// Update link target and text
	$("#content-search-prompt").html("<a href='" + campaign + "/search?q=" + searchtext + "'><i>Search entity contents for \"" + searchtext + "\"</i></a>");
}