Google Classroom User Account Redirect

Redirect Google Classroom to correct user Account

  1. // ==UserScript==
  2. // @name Google Classroom User Account Redirect
  3. // @description Redirect Google Classroom to correct user Account
  4. // @version 0.2
  5. // @author Torkelicous
  6. // @icon https://www.gstatic.com/classroom/logo_square_rounded.svg
  7. // @include https://classroom.google.com/*
  8. // @run-at document-start
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @license MIT
  12. // @namespace https://greasyfork.org/users/1403155
  13. // ==/UserScript==
  14.  
  15. (function() {
  16.  
  17.  
  18. let wantedAccount = GM_getValue('wantedAccount', 1)
  19. let isUIVisible = GM_getValue('isUIVisible', true);
  20. let guiContainer;
  21. let toggleButton;
  22.  
  23. // Create toggle
  24. function createToggleButton() {
  25. toggleButton = document.createElement('button');
  26. toggleButton.textContent = isUIVisible ? '➖' : '➕';
  27. toggleButton.style.position = 'fixed';
  28. toggleButton.style.bottom = '10px';
  29. toggleButton.style.right = '70px';
  30. toggleButton.style.zIndex = '1000';
  31. toggleButton.style.padding = '5px';
  32. toggleButton.style.cursor = 'pointer';
  33. toggleButton.style.backgroundColor = 'white';
  34. toggleButton.style.border = '1px solid black';
  35. toggleButton.style.borderRadius = '3px';
  36. toggleButton.style.fontSize = '16px';
  37.  
  38. toggleButton.onclick = function() {
  39. if (isUIVisible) {
  40. guiContainer.style.display = 'none';
  41. toggleButton.textContent = '➕';
  42. } else {
  43. guiContainer.style.display = 'block';
  44. toggleButton.textContent = '➖';
  45. }
  46. isUIVisible = !isUIVisible;
  47. GM_setValue('isUIVisible', isUIVisible);
  48. };
  49.  
  50. document.body.appendChild(toggleButton);
  51. }
  52.  
  53. // GUI for wantedAccount
  54. function createGUI() {
  55. guiContainer = document.createElement('div');
  56. guiContainer.style.position = 'fixed';
  57. guiContainer.style.bottom = '10px';
  58. guiContainer.style.right = '110px';
  59. guiContainer.style.padding = '10px';
  60. guiContainer.style.backgroundColor = 'white';
  61. guiContainer.style.border = '1px solid black';
  62. guiContainer.style.zIndex = '1000';
  63. guiContainer.style.display = isUIVisible ? 'block' : 'none'; // Set initial display based on saved state
  64.  
  65. const label = document.createElement('label');
  66. label.textContent = 'Account: ';
  67. guiContainer.appendChild(label);
  68.  
  69. const input = document.createElement('input');
  70. input.type = 'number';
  71. input.min = '0';
  72. input.max = '9';
  73. input.style.width = '30px';
  74. input.value = wantedAccount;
  75. guiContainer.appendChild(input);
  76.  
  77. const button = document.createElement('button');
  78. button.textContent = 'Save';
  79. button.style.marginLeft = '5px';
  80. button.onclick = function() {
  81. GM_setValue('wantedAccount', input.value);
  82. location.reload();
  83. };
  84. guiContainer.appendChild(button);
  85. document.body.appendChild(guiContainer);
  86. createToggleButton();
  87. }
  88. window.addEventListener('load', createGUI);
  89.  
  90. // Redirect logic
  91. var path0 = window.location.pathname;
  92. var path1 = path0.substring(0, 5);
  93. if (path1 != `/u/${wantedAccount}/`)
  94. {
  95. window.location.replace(`https://classroom.google.com/u/${wantedAccount}/`);
  96. }
  97.  
  98. })();