Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

333 lines
19 KiB

4 years ago
  1. /**
  2. * @name GameActivityToggle
  3. * @version 1.2.6
  4. * @description Simple plugin that adds the \"display game activity\" setting
  5. * on the home toolbar so you can toggle it easier when you don't want your friends knowing how much you play video games.
  6. *
  7. * @authorLink https://github.com/Egrodo
  8. * @source https://github.com/Egrodo/DiscordPlugins/blob/master/GameActivityToggle.plugin.js
  9. */
  10. /*@cc_on
  11. @if (@_jscript)
  12. // Offer to self-install for clueless users that try to run this directly.
  13. var shell = WScript.CreateObject("WScript.Shell");
  14. var fs = new ActiveXObject("Scripting.FileSystemObject");
  15. var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\BetterDiscord\plugins");
  16. var pathSelf = WScript.ScriptFullName;
  17. // Put the user at ease by addressing them in the first person
  18. shell.Popup("It looks like you've mistakenly tried to run me directly. \n(Don't do that!)", 0, "I'm a plugin for BetterDiscord", 0x30);
  19. if (fs.GetParentFolderName(pathSelf) === fs.GetAbsolutePathName(pathPlugins)) {
  20. shell.Popup("I'm in the correct folder already.", 0, "I'm already installed", 0x40);
  21. } else if (!fs.FolderExists(pathPlugins)) {
  22. shell.Popup("I can't find the BetterDiscord plugins folder.\nAre you sure it's even installed?", 0, "Can't install myself", 0x10);
  23. } else if (shell.Popup("Should I copy myself to BetterDiscord's plugins folder for you?", 0, "Do you need some help?", 0x34) === 6) {
  24. fs.CopyFile(pathSelf, fs.BuildPath(pathPlugins, fs.GetFileName(pathSelf)), true);
  25. // Show the user where to put plugins in the future
  26. shell.Exec("explorer " + pathPlugins);
  27. shell.Popup("I'm installed!", 0, "Successfully installed", 0x40);
  28. }
  29. WScript.Quit();
  30. @else@*/
  31. const enabledIcon =
  32. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" width="20" height="20" xml:space="preserve"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11.7C18,11.7,18,11.7,18,11.7C18,11.7,18,11.7,18,11.7z M18.9,10.9c-0.4,0-0.8-0.3-0.8-0.8c0-0.4,0.3-0.8,0.8-0.8c0,0,0,0,0,0c0.4,0,0.8,0.3,0.8,0.8C19.6,10.5,19.3,10.9,18.9,10.9z"/><polygon points="19.3,11.2 19.3,11.2 19.3,11.2 "/><polygon points="19.3,11.2 19.3,11.2 19.3,11.2 "/></g></svg>';
  33. const enabledIconHover =
  34. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" width="20" height="20" xml:space="preserve"><style type="text/css">.st0{fill:#dcddde;}</style><g><path class="st0" d="M20.8,7.7c-0.6-1.2-1.8-1.9-3.1-1.9H6.3C5,5.7,3.8,6.5,3.2,7.6l-2.8,5.8c0,0,0,0,0,0C-0.3,15.1,0.4,17,2,17.8L2.3,18C4,18.7,5.9,18,6.7,16.4l0.1-0.3c0.3-0.6,0.9-1,1.6-1h7.1c0.7,0,1.3,0.4,1.6,1l0.1,0.3c0.8,1.6,2.7,2.4,4.4,1.6l0.3-0.1c1.6-0.8,2.3-2.7,1.6-4.4L20.8,7.7z M8.6,10.5c0,0.2-0.2,0.4-0.4,0.4H7.3c-0.2,0-0.4,0.2-0.4,0.4v0.9c0,0.2-0.2,0.4-0.4,0.4H5.7c-0.2,0-0.4-0.2-0.4-0.4v-0.9c0-0.2-0.2-0.4-0.4-0.4c0,0,0,0,0,0H4.1c-0.2,0-0.4-0.2-0.4-0.4V9.7c0-0.2,0.2-0.4,0.4-0.4h0.9c0.2,0,0.4-0.2,0.4-0.4c0,0,0,0,0,0V8.1c0-0.2,0.2-0.4,0.4-0.4h0.8C6.8,7.7,7,7.9,7,8.1V9c0,0.2,0.2,0.4,0.4,0.4h0.9c0.2,0,0.3,0.2,0.3,0.4V10.5z M15.6,10.9c-0.4,0-0.8-0.3-0.8-0.8c0-0.4,0.3-0.8,0.8-0.8c0,0,0,0,0,0c0.4,0,0.8,0.3,0.8,0.8C16.4,10.5,16.1,10.9,15.6,10.9z M17.2,7.7C17.2,7.7,17.2,7.7,17.2,7.7c0.4,0,0.8,0.3,0.8,0.8c0,0,0,0,0,0c0,0.4-0.4,0.8-0.8,0.8c-0.4,0-0.8-0.4-0.8-0.8S16.8,7.7,17.2,7.7z M18,11.7L18,11.7C18,11.7,18,11.7,18,11.7c0,0.4-0.3,0.8-0.8,0.8c-0.4,0-0.8-0.3-0.8-0.8c0-0.4,0.3-0.8,0.8-0.8c0,0,0,0,0,0C17.7,10.9,18,11.3,18,11.7C18,11.7,18,11.7,18,11.7L18,11.7C18,11.7,18,11.7,18,11.7C18,11.7,18,11.7,18,11.7z M18.9,10.9c-0.4,0-0.8-0.3-0.8-0.8c0-0.4,0.3-0.8,0.8-0.8c0,0,0,0,0,0c0.4,0,0.8,0.3,0.8,0.8C19.6,10.5,19.3,10.9,18.9,10.9z"/><polygon points="19.3,11.2 19.3,11.2 19.3,11.2 "/><polygon points="19.3,11.2 19.3,11.2 19.3,11.2 "/></g></svg>';
  35. const disabledIcon =
  36. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" width="20" height="20" xml:space="preserve"><style type="text/css">.st0{fill:#B9BBBE;}.st1{fill:#F04747;}</style><g><path class="st0" d="M17.7,5.7h-0.8L4.4,18.1c1-0.2,1.9-0.8,2.3-1.8l0.1-0.3c0.3-0.6,0.9-1,1.6-1h1.9l4.7-4.6v0c-0.1-0.1-0.1-0.2-0.1-0.4c0-0.4,0.3-0.8,0.8-0.8c0,0,0,0,0,0c0.1,0,0.2,0,0.3,0.1l0.5-0.5c-0.1-0.1-0.1-0.2-0.1-0.4c0-0.4,0.3-0.8,0.8-0.8c0.1,0,0.3,0,0.4,0.1l1.7-1.7C18.8,5.8,18.3,5.7,17.7,5.7z M23.5,13.4l-2.8-5.8c0,0,0-0.1-0.1-0.1l-1.8,1.8c0.4,0,0.7,0.4,0.7,0.8c0,0.4-0.3,0.8-0.8,0.8c-0.4,0-0.8-0.3-0.8-0.7l-0.8,0.8c0.4,0,0.7,0.4,0.7,0.8c0,0.4-0.4,0.8-0.8,0.8c-0.4,0-0.8-0.3-0.8-0.7L13.1,15h2.4c0.7,0,1.3,0.4,1.6,1l0.1,0.3c0.8,1.6,2.7,2.3,4.4,1.6l0.3-0.1C23.6,17,24.3,15,23.5,13.4z M6.3,5.7C5,5.7,3.8,6.4,3.3,7.6l-2.8,5.8c0,0,0,0,0,0C-0.3,15,0.4,16.9,2,17.7L14,5.7H6.3z M8.2,10.8H7.3c-0.2,0-0.4,0.2-0.4,0.3v0.9c0,0.2-0.2,0.3-0.3,0.3H5.7c-0.2,0-0.3-0.2-0.3-0.3v-0.9c0-0.2-0.2-0.3-0.4-0.3H4.1c-0.2,0-0.4-0.2-0.4-0.4V9.6c0-0.2,0.2-0.4,0.4-0.4H5c0.2,0,0.4-0.2,0.4-0.4V8c0-0.2,0.2-0.4,0.4-0.4h0.8C6.8,7.7,7,7.8,7,8v0.9c0,0.2,0.2,0.4,0.4,0.4h0.9c0.2,0,0.3,0.2,0.3,0.4v0.8C8.6,10.7,8.4,10.8,8.2,10.8z"/><polygon points="19.3,11.1 19.3,11.1 19.3,11.1 "/><polygon points="19.3,11.2 19.3,11.1 19.3,11.1 "/></g><polygon class="st1" points="22.6,2.7 22.6,2.8 19.3,6.1 16,9.3 16,9.4 15,10.4 15,10.4 10.3,15 2.8,22.5 1.4,21.1 21.2,1.3 "/></svg>';
  37. const disabledIconHover =
  38. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 24 24" width="20" height="20" xml:space="preserve"><style type="text/css">.st0{fill:#dcddde;}.st1{fill:#F04747;}</style><g><path class="st0" d="M17.7,5.7h-0.8L4.4,18.1c1-0.2,1.9-0.8,2.3-1.8l0.1-0.3c0.3-0.6,0.9-1,1.6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1.4,21.1 21.2,1.3 "/></svg>';
  39. const micIconPath = `M6.7 11H5C5 12.19 5.34 13.3 5.9 14.28L7.13 13.05C6.86 12.43 6.7 11.74 6.7 11Z`;
  40. const muteIconPath = `M14.99 11C14.99 12.66 13.66 14 12 14C10.34 14 9 12.66 9 11V5C9 3.34 10.34 2 12 2C13.66 2 15 3.34 15 5L14.99 11ZM12 16.1C14.76 16.1 17.3 14 17.3 11H19C19 14.42 16.28 17.24 13 17.72V21H11V17.72C7.72 17.23 5 14.41 5 11H6.7C6.7 14 9.24 16.1 12 16.1ZM12 4C11.2 4 11 4.66667 11 5V11C11 11.3333 11.2 12 12 12C12.8 12 13 11.3333 13 11V5C13 4.66667 12.8 4 12 4Z`;
  41. class GameActivityToggle {
  42. btnReference = null;
  43. tooltipReference = null;
  44. soundReference = null;
  45. observer = null;
  46. soundToggled = true;
  47. gameActivity = true;
  48. constructor() {
  49. this.onToggle = this.onToggle.bind(this);
  50. this.onButtonMouseOut = this.onButtonMouseOut.bind(this);
  51. this.onButtonMouseOver = this.onButtonMouseOver.bind(this);
  52. this.checkForRemoval = this.checkForRemoval.bind(this);
  53. this.checkForChange = this.checkForChange.bind(this);
  54. }
  55. getName() {
  56. return "Game Activity Toggle";
  57. }
  58. getDescription() {
  59. return 'Simple plugin that adds a "Display Game Activity" button on the main toolbar so you can toggle it easier.';
  60. }
  61. getVersion() {
  62. return "1.2.6";
  63. }
  64. getAuthor() {
  65. return "egrodo";
  66. }
  67. load() {
  68. // Not required, but if the user has ZLibrary installed then support auto update.
  69. if (window.ZLibrary) {
  70. ZLibrary.PluginUpdater.checkForUpdate(
  71. this.getName(),
  72. this.getVersion(),
  73. "https://raw.githubusercontent.com/Egrodo/DiscordPlugins/master/GameActivityToggle.plugin.js"
  74. );
  75. }
  76. }
  77. start() {
  78. // On start check what game activity is currently set to.
  79. this.gameActivity = BdApi.findModuleByProps("guildPositions").showCurrentGame;
  80. this.soundReference = BdApi.findModuleByProps("playSound");
  81. // Check if there's a sound setting saved
  82. // For some reason BdApi interprets boolean false's as undefined, so we're storing the toggle as a string and converting it.
  83. const savedSoundSetting = BdApi.loadData(this.getName(), "soundToggled");
  84. if (!savedSoundSetting) {
  85. this.soundToggled = true;
  86. } else if (savedSoundSetting === "true") {
  87. this.savedSoundSetting = true;
  88. } else if (savedSoundSetting === "false") {
  89. this.savedSoundSetting = false;
  90. } else {
  91. console.error(
  92. `Game Activity Toggle Error: soundToggle data somehow corrupted, not true/false: ${savedSoundSetting}`
  93. );
  94. this.savedSoundSetting = true;
  95. BdApi.saveData(this.getName(), "soundToggled", "true");
  96. }
  97. // Create our DOM elements
  98. this.createButton();
  99. this.createTooltip();
  100. // Watch for change
  101. BdApi.findModuleByProps("guildPositions").addChangeListener(this.checkForChange);
  102. }
  103. createButton() {
  104. // Use flexMarginReset prop to find the selector for the taskbar row.
  105. const selector = (BdApi.findModuleByProps("flexMarginReset", "flex").flex || "").split(" ")[0];
  106. if (!selector) {
  107. console.error("GameActivityToggle failed to start up: Selector not found?");
  108. return;
  109. }
  110. // If there are multiple elements found with this selector then the user is most likely in a call. Use the appropriate one
  111. const rows = document.querySelectorAll(`.${selector}`);
  112. let row;
  113. if (rows.length) {
  114. // Find the correct row by looking for one who's DOM structure matches what we expect
  115. for (let i = 0; i < rows.length; ++i) {
  116. try {
  117. if (
  118. rows[i].firstElementChild.firstElementChild.firstElementChild.firstElementChild.getAttribute("d") ===
  119. muteIconPath ||
  120. rows[i].firstElementChild.firstElementChild.firstElementChild.firstElementChild.getAttribute("d") ===
  121. micIconPath
  122. ) {
  123. row = rows[i];
  124. break;
  125. }
  126. } catch (err) {
  127. // If the above firstELementChild accessing fails assume it's not the correct row and continue
  128. continue;
  129. }
  130. }
  131. } else {
  132. row = rows[0];
  133. }
  134. if (!row) {
  135. console.log(rows);
  136. throw new Error("Could not find correct row?");
  137. }
  138. this.btnReference = row.firstElementChild.cloneNode(true);
  139. this.btnReference.firstElementChild.innerHTML = this.gameActivity ? enabledIcon : disabledIcon;
  140. this.btnReference.firstElementChild.style.pointerEvents = "none"; // Ignore pointer events to fix bug that was causing repeated clicks to be ignored.
  141. this.btnReference.id = "GameActivityToggleBtn";
  142. this.btnReference.setAttribute("aria-label", "Toggle Game Activity");
  143. this.btnReference.setAttribute("aria-checked", `${this.gameActivity ? "true" : "false"}`);
  144. this.btnReference.addEventListener("click", this.onToggle);
  145. this.btnReference.addEventListener("mouseenter", this.onButtonMouseOver);
  146. this.btnReference.addEventListener("mouseleave", this.onButtonMouseOut);
  147. row.prepend(this.btnReference);
  148. // Observe changes on the row to watch for our element being overwritten.
  149. if (!this.observer) {
  150. this.observer = new MutationObserver(this.checkForRemoval);
  151. this.observer.observe(row, {
  152. attributes: false,
  153. childList: true,
  154. subtree: false,
  155. });
  156. }
  157. }
  158. createTooltip() {
  159. // Also setup my recreated tooltip that uses Discord's classes.
  160. const tooltipClasses = BdApi.findModuleByProps("tooltipBottom");
  161. const wrapperDiv = document.createElement("div");
  162. this.tooltipReference = wrapperDiv;
  163. wrapperDiv.style.visibility = "hidden";
  164. wrapperDiv.style.position = "absolute";
  165. // wrapperDiv.style.zIndex = "1003";
  166. wrapperDiv.className = [
  167. tooltipClasses.tooltip,
  168. tooltipClasses.tooltipTop,
  169. tooltipClasses.tooltipBlack,
  170. tooltipClasses.tooltipDisablePointerEvents,
  171. ].join(" ");
  172. const textWrapper = document.createElement("div");
  173. textWrapper.className = tooltipClasses.tooltipContent;
  174. textWrapper.innerText = `Turn ${this.gameActivity ? "off" : "on"} game activity`;
  175. const bottomArrow = document.createElement("div");
  176. bottomArrow.className = tooltipClasses.tooltipPointer;
  177. wrapperDiv.appendChild(textWrapper);
  178. wrapperDiv.appendChild(bottomArrow);
  179. document.body.appendChild(wrapperDiv);
  180. }
  181. onToggle() {
  182. this.gameActivity = !this.gameActivity;
  183. BdApi.findModuleByProps("updateRemoteSettings").updateLocalSettings({
  184. showCurrentGame: this.gameActivity,
  185. });
  186. BdApi.findModuleByProps("updateRemoteSettings").updateRemoteSettings({
  187. showCurrentGame: this.gameActivity,
  188. });
  189. this.btnReference.firstElementChild.innerHTML = this.gameActivity ? enabledIcon : disabledIcon;
  190. // In order to preserve the tooltipPointer but also change the message we have to do this
  191. const innerTooltipHTML = this.tooltipReference.firstElementChild.innerHTML.split("Turn");
  192. this.tooltipReference.firstElementChild.innerHTML = `${innerTooltipHTML[0]} Turn ${
  193. this.gameActivity ? "off" : "on"
  194. } game activity`;
  195. this.btnReference.setAttribute("aria-checked", `${this.gameActivity ? "true" : "false"}`);
  196. // If enabled, play the mute / unmute sound on toggle.
  197. if (this.soundToggled) {
  198. if (this.gameActivity) {
  199. this.soundReference.playSound("unmute", 0.4);
  200. } else this.soundReference.playSound("mute", 0.4);
  201. }
  202. }
  203. // On mouse over swap icons to highlight and display tooltip in correct position.
  204. onButtonMouseOver({ target }) {
  205. this.btnReference.firstElementChild.innerHTML = this.gameActivity ? enabledIconHover : disabledIconHover;
  206. const { x, y } = target.getBoundingClientRect();
  207. const tooltipXPos = x + target.clientWidth / 2 - this.tooltipReference.offsetWidth / 2;
  208. const tooltipYPos = y - target.clientHeight - 8; // 8 being a constant amount of space to hover above the btn.
  209. this.tooltipReference.style.left = `${tooltipXPos}px`;
  210. this.tooltipReference.style.visibility = "visible";
  211. this.tooltipReference.style.top = `${tooltipYPos}px`;
  212. this.tooltipReference.visibility = "visible";
  213. }
  214. onButtonMouseOut() {
  215. this.btnReference.firstElementChild.innerHTML = this.gameActivity ? enabledIcon : disabledIcon;
  216. this.tooltipReference.style.visibility = "hidden";
  217. }
  218. // Certain UI actions can result in the row being re-rendered and the button removed. Watch the row and re-add the button when necessary.
  219. checkForRemoval() {
  220. if (!document.getElementById("GameActivityToggleBtn")) {
  221. this.createButton();
  222. }
  223. }
  224. // We need to check for the user toggling game activity in the actual settings menu as well, because we have no event for that.
  225. checkForChange() {
  226. if (this.gameActivity !== BdApi.findModuleByProps("guildPositions").showCurrentGame) {
  227. this.gameActivity = BdApi.findModuleByProps("guildPositions").showCurrentGame;
  228. this.btnReference.firstElementChild.innerHTML = this.gameActivity ? enabledIcon : disabledIcon;
  229. const innerTooltipHTML = this.tooltipReference.firstElementChild.innerHTML.split("Turn");
  230. this.tooltipReference.firstElementChild.innerHTML = `${innerTooltipHTML[0]} Turn ${
  231. this.gameActivity ? "off" : "on"
  232. } game activity`;
  233. this.btnReference.setAttribute("aria-checked", `${this.gameActivity ? "true" : "false"}`);
  234. this.btnReference.addEventListener("click", this.onToggle);
  235. }
  236. }
  237. // Create settings panel that allows users to disable the alert sound
  238. getSettingsPanel() {
  239. // Create wrapper row
  240. const wrapper = document.createElement("div");
  241. wrapper.className = "ui-flex flex-vertical flex-justify-start flex-align-stretch flex-nowrap ui-switch-item";
  242. wrapper.style.marginTop = "1.5rem";
  243. const titleContainer = document.createElement("div");
  244. titleContainer.className = 'class="ui-flex flex-horizontal flex-justify-start flex-align-stretch flex-nowrap"';
  245. titleContainer.style.display = "flex";
  246. const title = document.createElement("h3");
  247. title.innerText = "Alert Sound";
  248. title.className = "ui-form-title h3 margin-reset margin-reset ui-flex-child";
  249. titleContainer.appendChild(title);
  250. // Create switch
  251. const button = document.createElement("div");
  252. button.classList.add("bd-switch", ...(this.soundToggled ? ["bd-switch-checked"] : []));
  253. const input = document.createElement("input");
  254. input.type = "checkbox";
  255. input.className = "bd-checkbox";
  256. button.appendChild(input);
  257. button.style.float = "right";
  258. input.onclick = () => {
  259. this.soundToggled = !this.soundToggled;
  260. BdApi.saveData(this.getName(), "soundToggled", this.soundToggled.toString());
  261. button.classList.remove(...(this.soundToggled ? [] : ["bd-switch-checked"]));
  262. button.classList.add(...(this.soundToggled ? ["bd-switch-checked"] : []));
  263. };
  264. // Create description box and append button to it
  265. const description = document.createElement("div");
  266. description.className = "ui-form-text style-description margin-top-4";
  267. description.innerText = "Toggle the alert sound that plays on button click";
  268. description.style.borderBottom = "none";
  269. description.appendChild(button);
  270. wrapper.appendChild(titleContainer);
  271. wrapper.appendChild(description);
  272. return wrapper;
  273. }
  274. stop() {
  275. this.observer.disconnect();
  276. this.btnReference.removeEventListener("mouseenter", this.onButtonMouseOver);
  277. this.btnReference.removeEventListener("mouseleave", this.onButtonMouseOut);
  278. this.btnReference.parentNode.removeChild(this.btnReference);
  279. this.tooltipReference.parentNode.removeChild(this.tooltipReference);
  280. }
  281. }