Advertisement
Guest User

ant-search (revision 2022-11-02)

a guest
Nov 2nd, 2022
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.53 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. var ant_list_containers, ant_list_container, ant_list, search_language, search_input;
  9.  
  10. function ant_select(input) {
  11.     search_input = input;
  12.     if (!search_input) search_input = prompt("Search language:");
  13.     if (!search_input) return false; // if field left blank or cancelled
  14.     search_language = search_input.toLowerCase(); // case-insensitive
  15.  
  16.     /* on multiple selectors – multi-upload page */
  17.     ant_list_containers = document.getElementsByClassName("ant-select-dropdown-menu");
  18.     ant_list_container = ant_list_containers[0];
  19.     for (
  20.         var count=0;
  21.         count < ant_list_containers.length; // repeat for each language list
  22.         count++
  23.     ) {
  24.         // detect language boxes
  25.         if ( ant_list_containers[count].innerHTML.search(">German<") > 0 ) {
  26.             ant_list_container = ant_list_containers[count];
  27.             ant_select_core(search_language);
  28.         }
  29.     }
  30. }
  31.  
  32.  
  33.  
  34. function ant_select_core(search_language) {
  35.  
  36.     ant_list = ant_list_container.getElementsByTagName("li");
  37.  
  38.     // creating container that shows the entered search term
  39.     if (! document.getElementsByTagName("ant_search_term")[0] ) {
  40.         ant_list_container.insertBefore(
  41.             document.createElement("ant_search_term"),ant_list[0]
  42.         );
  43.     }
  44.     ant_list_container.getElementsByTagName("ant_search_term")[0].innerHTML='Search results for "'+search_input+'"';
  45.  
  46.     // filtering out non-matches
  47.     for (var count=0; count < ant_list.length; count++) {
  48.         if (ant_list[count].innerHTML.toLowerCase().search(search_language) < 0 ) {
  49.             ant_list[count].style.display="none";
  50.         } else {
  51.             ant_list[count].style.display="block";
  52.         }
  53.     }
  54. }
  55.  
  56. /* originally written for use on Dailymotion; feel free to adapt to any other site that uses the garbage by ant.design */
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement