Remove Bing Character Limit

Removes character limit from search input field

目前为 2023-06-03 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Remove Bing Character Limit
  3. // @author NOLIMIT
  4. // @namespace NOLIMIT
  5. // @version 2
  6. // @description Removes character limit from search input field
  7. // @match https://www.bing.com/search?*
  8. // @run-at document-end
  9. // @grant none
  10. // @license MIT
  11. /* jshint esversion: 8 */
  12. // ==/UserScript==
  13.  
  14. const DEBUG = false;
  15.  
  16. // Define an async function that waits for an element to appear in the DOM
  17. async function waitForElement(root, selector) {
  18. return new Promise((resolve, reject) => {
  19. // Check if the element already exists
  20. if (root.querySelector(selector)) {
  21. // Resolve the promise with the element
  22. resolve(root.querySelector(selector));
  23. } else {
  24. // Create a mutation observer to watch for changes in the DOM
  25. const observer = new MutationObserver((mutations) => {
  26. mutations.forEach((mutation) => {
  27. // If new nodes are added
  28. if (mutation.type === "childList") {
  29. // Check if the element exists now
  30. if (root.querySelector(selector)) {
  31. // Resolve the promise with the element
  32. resolve(root.querySelector(selector));
  33. // Disconnect the observer and clear the timeout
  34. observer.disconnect();
  35. clearTimeout(timeout);
  36. }
  37. }
  38. });
  39. });
  40. // Start observing the root element and its descendants for changes
  41. observer.observe(root, { childList: true, subtree: true });
  42. // Set a timeout to reject the promise after 10 seconds
  43. const timeout = setTimeout(() => {
  44. // Disconnect the observer and reject the promise with an error
  45. observer.disconnect();
  46. reject(new Error("Timeout"));
  47. }, 10000);
  48. }
  49. });
  50. }
  51.  
  52. const MAX_RETRIES = 3;
  53. let retries = 0;
  54.  
  55. // Define an async function that removes the character limit from the search input field
  56. const removeLimitation = async () => {
  57. try {
  58. // Wait for the main host element to appear
  59. const mainHost = await waitForElement(document, ".cib-serp-main");
  60. // Get the shadow root of the main host element
  61. const mainRoot = mainHost.shadowRoot;
  62. // Wait for the second host element to appear inside the main root
  63. const secondHost = await waitForElement(mainRoot, "#cib-action-bar-main");
  64. // Get the shadow root of the second host element
  65. const secondRoot = secondHost.shadowRoot;
  66. // Wait for the search input element to appear inside the second root
  67. const searchInput = await waitForElement(secondRoot, "#searchbox");
  68. // Remove the maxlength attribute from the search input element
  69. searchInput.removeAttribute("maxlength");
  70. // Wait for the letter counter element to appear inside the second root
  71. const letterCounter = await waitForElement(secondRoot, ".letter-counter");
  72. // Change the inner HTML of the letter counter element to an infinity symbol
  73. letterCounter.innerHTML = "∞";
  74. console.log("Character limit was removed.");
  75.  
  76. // Create a mutation observer to watch for changes in the second root
  77. const observer = new MutationObserver((mutationsList) => {
  78. for (const mutation of mutationsList) {
  79. // If nodes are removed or replaced
  80. if (!searchInput.isConnected) {
  81. // Call the removeLimitation function again and disconnect the observer
  82. removeLimitation();
  83. observer.disconnect();
  84. }
  85. }
  86. });
  87.  
  88. // Start observing the second root element and its children for changes
  89. observer.observe(secondRoot, { childList: true });
  90. } catch (error) {
  91. console.error(error);
  92. // If an error occurs, retry up to MAX_RETRIES times
  93. if (retries < MAX_RETRIES) {
  94. retries++;
  95. console.log(`Retrying... (${retries}/${MAX_RETRIES})`);
  96. removeLimitation();
  97. } else {
  98. console.log("Failed to remove character limit.");
  99. }
  100. }
  101. };
  102.  
  103. // Call the removeLimitation function when the script runs
  104. removeLimitation();