您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Removes character limit from search input field
当前为
- // ==UserScript==
- // @name Remove Bing Character Limit
- // @author NOLIMIT
- // @namespace NOLIMIT
- // @version 2
- // @description Removes character limit from search input field
- // @match https://www.bing.com/search?*
- // @run-at document-end
- // @grant none
- // @license MIT
- /* jshint esversion: 8 */
- // ==/UserScript==
- const DEBUG = false;
- // Define an async function that waits for an element to appear in the DOM
- async function waitForElement(root, selector) {
- return new Promise((resolve, reject) => {
- // Check if the element already exists
- if (root.querySelector(selector)) {
- // Resolve the promise with the element
- resolve(root.querySelector(selector));
- } else {
- // Create a mutation observer to watch for changes in the DOM
- const observer = new MutationObserver((mutations) => {
- mutations.forEach((mutation) => {
- // If new nodes are added
- if (mutation.type === "childList") {
- // Check if the element exists now
- if (root.querySelector(selector)) {
- // Resolve the promise with the element
- resolve(root.querySelector(selector));
- // Disconnect the observer and clear the timeout
- observer.disconnect();
- clearTimeout(timeout);
- }
- }
- });
- });
- // Start observing the root element and its descendants for changes
- observer.observe(root, { childList: true, subtree: true });
- // Set a timeout to reject the promise after 10 seconds
- const timeout = setTimeout(() => {
- // Disconnect the observer and reject the promise with an error
- observer.disconnect();
- reject(new Error("Timeout"));
- }, 10000);
- }
- });
- }
- const MAX_RETRIES = 3;
- let retries = 0;
- // Define an async function that removes the character limit from the search input field
- const removeLimitation = async () => {
- try {
- // Wait for the main host element to appear
- const mainHost = await waitForElement(document, ".cib-serp-main");
- // Get the shadow root of the main host element
- const mainRoot = mainHost.shadowRoot;
- // Wait for the second host element to appear inside the main root
- const secondHost = await waitForElement(mainRoot, "#cib-action-bar-main");
- // Get the shadow root of the second host element
- const secondRoot = secondHost.shadowRoot;
- // Wait for the search input element to appear inside the second root
- const searchInput = await waitForElement(secondRoot, "#searchbox");
- // Remove the maxlength attribute from the search input element
- searchInput.removeAttribute("maxlength");
- // Wait for the letter counter element to appear inside the second root
- const letterCounter = await waitForElement(secondRoot, ".letter-counter");
- // Change the inner HTML of the letter counter element to an infinity symbol
- letterCounter.innerHTML = "∞";
- console.log("Character limit was removed.");
- // Create a mutation observer to watch for changes in the second root
- const observer = new MutationObserver((mutationsList) => {
- for (const mutation of mutationsList) {
- // If nodes are removed or replaced
- if (!searchInput.isConnected) {
- // Call the removeLimitation function again and disconnect the observer
- removeLimitation();
- observer.disconnect();
- }
- }
- });
- // Start observing the second root element and its children for changes
- observer.observe(secondRoot, { childList: true });
- } catch (error) {
- console.error(error);
- // If an error occurs, retry up to MAX_RETRIES times
- if (retries < MAX_RETRIES) {
- retries++;
- console.log(`Retrying... (${retries}/${MAX_RETRIES})`);
- removeLimitation();
- } else {
- console.log("Failed to remove character limit.");
- }
- }
- };
- // Call the removeLimitation function when the script runs
- removeLimitation();