0_1_知乎搜索

打开知乎搜索, 借用了 桃源隐叟 的代码

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            0_1_知乎搜索
// @namespace       http://tampermonkey.net/
// @description     打开知乎搜索, 借用了 桃源隐叟 的代码
// @version         0.1.3
// @author          gtfish
// @include         *
// @grant           GM_openInTab
// @run-at            context-menu
// @homepageURL
// @supportURL
// ==/UserScript==

(function () {
    "use strict";

    // These helpers produce better VM code in JS engines due to their
    // explicitness and function inlining.
    function isUndef(v) {
        return v === undefined || v === null;
    }

    function isDef(v) {
        return v !== undefined && v !== null;
    }

    function isTrue(v) {
        return v === true;
    }

    function isFalse(v) {
        return v === false;
    }

    /**
     * Check if value is primitive.
     */
    function isPrimitive(value) {
        return (
            typeof value === "string" ||
            typeof value === "number" ||
            // $flow-disable-line
            typeof value === "symbol" ||
            typeof value === "boolean"
        );
    }

    /**
     * Quick object check - this is primarily used to tell
     * Objects from primitive values when we know the value
     * is a JSON-compliant type.
     */
    function isObject(obj) {
        return obj !== null && typeof obj === "object";
    }

    /**
     * Get the raw type string of a value, e.g., [object Object].
     */

    function toRawType(value) {
        return _toString.call(value).slice(8, -1);
    }

    /**
     * Strict object type check. Only returns true
     * for plain JavaScript objects.
     */
    function isPlainObject(obj) {
        return _toString.call(obj) === "[object Object]";
    }

    function isRegExp(v) {
        return _toString.call(v) === "[object RegExp]";
    }

    /**
     * Check if val is a valid array index.
     */
    function isValidArrayIndex(val) {
        var n = parseFloat(String(val));
        return n >= 0 && Math.floor(n) === n && isFinite(val);
    }

    function isPromise(val) {
        return isDef(val) && typeof val.then === "function" && typeof val.catch === "function";
    }

    /**
     * Convert a value to a string that is actually rendered.
     */
    function toString(val) {
        return val == null ? "" : Array.isArray(val) || (isPlainObject(val) && val.toString === _toString) ? JSON.stringify(val, null, 2) : String(val);
    }

    /**
     * Convert an input value to a number for persistence.
     * If the conversion fails, return original string.
     */
    function toNumber(val) {
        var n = parseFloat(val);
        return isNaN(n) ? val : n;
    }

    /**
     * Make a map and return a function for checking if a key
     * is in that map.
     */
    function makeMap(str, expectsLowerCase) {
        var map = Object.create(null);
        var list = str.split(",");
        for (var i = 0; i < list.length; i++) {
            map[list[i]] = true;
        }
        return expectsLowerCase
            ? function (val) {
                  return map[val.toLowerCase()];
              }
            : function (val) {
                  return map[val];
              };
    }

    /**
     * Check if a tag is a built-in tag.
     */

    /**
     * Check if an attribute is a reserved attribute.
     */
    var isReservedAttribute = makeMap("key,ref,slot,slot-scope,is");

    /**
     * Remove an item from an array.
     */
    function remove(arr, item) {
        if (arr.length) {
            var index = arr.indexOf(item);
            if (index > -1) {
                return arr.splice(index, 1);
            }
        }
    }

    /**
     * Check whether an object has the property.
     */
    var hasOwnProperty = Object.prototype.hasOwnProperty;
    function hasOwn(obj, key) {
        return hasOwnProperty.call(obj, key);
    }

    /**
     * Create a cached version of a pure function.
     */
    function cached(fn) {
        var cache = Object.create(null);
        return function cachedFn(str) {
            var hit = cache[str];
            return hit || (cache[str] = fn(str));
        };
    }

    /**
     * Camelize a hyphen-delimited string.
     */

    var camelize = cached(function (str) {
        return str.replace(camelizeRE, function (_, c) {
            return c ? c.toUpperCase() : "";
        });
    });

    /**
     * Capitalize a string.
     */
    var capitalize = cached(function (str) {
        return str.charAt(0).toUpperCase() + str.slice(1);
    });

    /**
     * Hyphenate a camelCase string.
     */
    var hyphenateRE = /\B([A-Z])/g;
    var hyphenate = cached(function (str) {
        return str.replace(hyphenateRE, "-$1").toLowerCase();
    });
    var selection = window.getSelection().toString();
    console.log(selection);
    var gotoSite = `https://www.zhihu.com/search?type=content&q=${selection}`;
    GM_openInTab(gotoSite);
})();