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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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>");
}