Cuberealm.io Wiki Search / Chat Selection

An easy way to type a search into the Miraheze Cuberealm.io wiki, or just highlight text in chat

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Cuberealm.io Wiki Search / Chat Selection
// @namespace   cooluser1481
// @match       https://cuberealm.io/*
// @version     1.0
// @author      cooluser1481
// @description An easy way to type a search into the Miraheze Cuberealm.io wiki, or just highlight text in chat
// @license     Do whatever you want, I don't care.
// ==/UserScript==

/*
 *This script is safe for bookmarklets, console, or script manager.
 *All comments are ended, (except for the start,) making it easy to put as 1 line
 */


document.body.style.userSelect = "text"; /*allows chat to be selected/coppied*/
document.body.style.webkitUserSelect = "text"; /*for Safari*/

function se(d) {
    return d.selection ? d.selection.createRange().text : d.getSelection(); /*finds selection*/
}

var s = se(document); /*gets selection of document*/

document.addEventListener("keypress", function(event) {
    if (event.keyCode == 104) {
        /*key h pressed, this method avoids interference with cuberealm events*/
        for (var i = 0; i < frames.length && (s == null || s == ''); i++)
            s = se(frames[i].document);
        if (!s || s == '') s = prompt('What to search for:', ''); {
            /*If nothing is selected, ask what to search*/
            if (s !== null && s !== false && s !== '') {
                /*If answer is empty or cancled, ignore*/
                window.open('https://cuberealm.miraheze.org' + (s ? '/w/index.php?title=Special:Search&search=' + encodeURIComponent(s) : '')).focus(); /*open the wiki search page*/
            }
        }
    }
});