TEXT   33   0
   414 5.23 KB    142

Improved Flag Selector

By AnonPPP
Created: 2021-10-01 15:18:38
Expiry: Never

  1. // This is a userscript to make the flagselector more bearable
  2. // For Archival Purpose (I did not make this)
  3. // Source code checks out
  4. // ==UserScript==
  5. // @name Improved Waifu Flag Selection
  6. // @version 1.0.3
  7. // @description Improved flag selection for /mlp/ (icons, search, etc)
  8. // @author Anonymous
  9. // @license MIT
  10. // @grant GM_getResourceText
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. /*global Choices, NodeCreationObserver*/
  17. GM_addStyle(GM_getResourceText("cssMain"));
  18. GM_addStyle(`
  19. .choices__inner {
  20. box-sizing: border-box;
  21. padding: 0 !important;
  22. min-height: 25px !important;
  23. }
  24. .choices[data-type*="select-one"] .choices__inner {
  25. padding-bottom: 0px !important;
  26. }
  27. .choices[data-type*="select-one"] .choices__input {
  28. padding: 3px !important;
  29. }
  30. .choices__list--dropdown .choices__item {
  31. padding: 3px !important;
  32. }
  33. .bfl-0 {
  34. visibility: hidden;
  35. }
  36. #qr > form {
  37. overflow-y: visible !important;
  38. overflow-x: visible !important;
  39. }
  40. `);
  41. if (document.querySelector('link[rel="stylesheet"][href*="flags"]') === null) {
  42. GM_addStyle(GM_getResourceText("cssFlags"));
  43. }
  44.  
  45. let clonedFlagSelector;
  46. let myNodeList = document.querySelectorAll('.flagSelector');
  47. for (let i = 0; i < myNodeList.length; i++) {
  48. let flagSelectorElem = myNodeList[i];
  49. if (i == 0) {
  50. clonedFlagSelector = flagSelectorElem.cloneNode(true);
  51. }
  52. createChoices(flagSelectorElem, 'choices ponyFlagChoices');
  53. console.log("i=" + i);
  54. }
  55.  
  56. function createChoices(flagSelectorElem, outerClass) {
  57. const choices = new Choices(flagSelectorElem, {
  58. searchResultLimit: 80,
  59. searchPlaceholderValue: "Search pony",
  60. noResultsText: 'No ponies found',
  61. itemSelectText: '',
  62. shouldSort: false,
  63. classNames: {
  64. containerOuter: outerClass,
  65. },
  66. fuseOptions: {
  67. includeMatches: true,
  68. includeScore: true,
  69. threshold: 0.1,
  70. distance: 600
  71. },
  72. callbackOnCreateTemplates: () => ({
  73. choice: (...args) => {
  74. const choiceDefault = Choices.defaults.templates.choice.call(this, ...args);
  75. addIcon(choiceDefault, ...args);
  76. return choiceDefault;
  77. },
  78. item: (...args) => {
  79. const itemDefault = Choices.defaults.templates.item.call(this, ...args);
  80. addIcon(itemDefault, ...args);
  81. return itemDefault;
  82. }
  83. }),
  84. });
  85. flagSelectorElem.addEventListener(
  86. 'choice',
  87. function(event) {
  88. setBoardFlag(event.detail.choice.value);
  89. },
  90. false,
  91. );
  92. choices.setChoiceByValue(getBoardFlag());
  93. return choices;
  94. }
  95.  
  96. function addIcon(templateElement, ...args) {
  97. console.log(args[1]);
  98. const icon = document.createElement("span");
  99. icon.classList.add("bfl", "bfl-" + args[1].value.toLowerCase());
  100. const space = document.createTextNode(" ");
  101. templateElement.prepend(icon, space);
  102. }
  103.  
  104. //#qrForm > #qrCaptchaContainer + div > .flagSelector,
  105. let isObserve = true;
  106. NodeCreationObserver.onCreation("#qrForm > #qrCaptchaContainer + div > .ponyFlagChoices", (node) => {
  107. if (isObserve) {
  108. isObserve = false;
  109. let curFlagSelector = clonedFlagSelector.cloneNode(true);
  110. node.parentNode.appendChild(curFlagSelector);
  111. node.remove();
  112. createChoices(curFlagSelector, 'choices');
  113. isObserve = true;
  114. }
  115. });
  116. NodeCreationObserver.onCreation("#qr > form > .flagSelector", (node) => {
  117. if (isObserve) {
  118. isObserve = false;
  119. createChoices(node, 'choices');
  120. isObserve = true;
  121. }
  122. });
  123.  
  124. function setBoardFlag(value) {
  125. var curBoardFlagKey = "4chan_flag_" + location.pathname.split(/\//)[1];
  126. "0" === value ? localStorage.removeItem(curBoardFlagKey) : localStorage.setItem(curBoardFlagKey, value);
  127. }
  128.  
  129. function getBoardFlag() {
  130. var curBoardFlagKey = "4chan_flag_" + location.pathname.split(/\//)[1];
  131. return localStorage.getItem(curBoardFlagKey) || "0";
  132. }
  133.  
  134. // .flagSelector
  135. })();

/mlp/ Flags All ID'S

by AnonPPP

Flag Hider (4ChanX)

by AnonPPP

Flag Filter (4ChanX)

by AnonPPP

A Joint Collection of (almost) all MD5 Image Hashes (EQG)

by AnonPPP

MLP G5 Stream Compilation

by AnonPPP