Guest User

ant-search (revision 2022-10-11)

a guest
Oct 11th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.97 KB | Source Code | 0 0
  1. /* This script hides all language options except the searched ones on the Dailymotion video details editing page. This is necessary because the language selector is no conventional HTML-based selector but an inferior JavaScript-based alternative by "ant.design", which lacks searching by typing. Since one can not select a language by typing its name on the keyboard, one would have to inconveniently scroll through the 183 items-long list to find the language.
  2.  
  3. This script can be used as a template for other sites that use the terrible ant.design selector.
  4.  
  5. Instructions: Paste this script into a user script manager  web browser extension such as "GreaseMonkey", "Custom Style Script", or "TamperMonkey", and add javascript:ant_select(); as a bookmarklet. If you wish to pre-select a language, put it inside the parenthesis, for example  javascript:ant_select("German"); .
  6. */
  7.  
  8. function ant_select(search_input) {
  9.     if (!search_input) search_input = prompt("Search language:");
  10.     if (!search_input) return false; // if field left blank or cancelled
  11.     var search_language = search_input.toLowerCase(); // case-insensitive
  12.     var ant_list_container = document.getElementsByClassName("ant-select-dropdown-menu")[0];
  13.     var ant_list = ant_list_container.getElementsByTagName("li");
  14.  
  15.     // creating container that shows the entered search term
  16.     if (! document.getElementsByTagName("ant_search_term")[0] ) {
  17.         ant_list_container.insertBefore(
  18.             document.createElement("ant_search_term"),ant_list[0]
  19.         );
  20.     }
  21.     document.getElementsByTagName("ant_search_term")[0].innerHTML='Search results for "'+search_input+'"';
  22.  
  23.     // filtering out non-matches
  24.     for (var count=0; count < ant_list.length; count++) {
  25.         if (ant_list[count].innerHTML.toLowerCase().search(search_language) < 0 ) {
  26.             ant_list[count].style.display="none";
  27.         } else {
  28.             ant_list[count].style.display="block";
  29.         }
  30.     }
  31. }
  32. /* originally written for use on Dailymotion; feel free to adapt to any other site that uses the garbage by ant.design */
  33.  
Tags: ant.design
Advertisement
Add Comment
Please, Sign In to add comment