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 提交的版本。查看 最新版本

// ==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>");
}