Remove Sidebar

Remove the suggested call sidebar from Google Voice

  1. // ==UserScript==
  2. // @name Remove Sidebar
  3. // @namespace htt*://voice.google.*
  4. // @version 2.0
  5. // @description Remove the suggested call sidebar from Google Voice
  6. // @author Ian
  7. // @match https://voice.google.com/u/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. function getElementByXpath(path) {
  13. return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  14. }
  15.  
  16. function waitForElm(selector) {
  17. return new Promise(resolve => {
  18. if (getElementByXpath(selector)) {
  19. return resolve(getElementByXpath(selector));
  20. }
  21.  
  22. const observer = new MutationObserver(mutations => {
  23. if (getElementByXpath(selector)) {
  24. resolve(getElementByXpath(selector));
  25. observer.disconnect();
  26. }
  27. });
  28.  
  29. observer.observe(document.body, {
  30. childList: true,
  31. subtree: true
  32. });
  33. });
  34. }
  35.  
  36. (async function() {
  37. 'use strict';
  38.  
  39. var sidebar = getElementByXpath("//*[@id=\"gvPageRoot\"]/div[2]/gv-side-panel/mat-sidenav-container/mat-sidenav-content/div/div[2]/gv-call-sidebar");
  40. sidebar.remove(); // Remove the sidebar!
  41.  
  42. window.onkeypress = async function(event) {
  43. if (event.keyCode == 96) { // Keycode 96 is ` (back quote)
  44. console.log("Keypress");
  45. while (getElementByXpath("//div[contains(@aria-label, 'Unread')]")) {
  46. console.log("Started loop");
  47. var unread = await waitForElm("//div[contains(@aria-label, 'Unread')]"); // Search for the newest unread message
  48. unread.click(); // Click on the message to mark it as read
  49. }
  50. console.log("Ended loop");
  51. }
  52. }
  53. })();