Change Google Classroom User

Switches between /u/0 & /u/1 on google classroom automatically.

目前为 2021-07-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Change Google Classroom User
  3. // @namespace Change Google Classroom User by C4illin
  4. // @description Switches between /u/0 & /u/1 on google classroom automatically.
  5. // @match https://classroom.google.com/*
  6. // @run-at document-idle
  7. // @grant none
  8. // @author C4illin <hi@emrik.org>
  9. // @oujs:author C4illin
  10. // @version 1.2.2
  11. // @homepageURL https://github.com/C4illin/Userscripts/tree/master/Change-Google-Classroom-User
  12. // @license MIT; https://opensource.org/licenses/MIT
  13. // @copyright 2018-2021, C4illin (https://github.com/C4illin)
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. let refresh = setInterval(() => {
  18. if ((document.getElementsByClassName("Lqr2e").length != 0) && (window.location.pathname.length < 7)) {
  19. switchUser()
  20. }
  21. if ((document.getElementsByClassName("tCD5Mc").length != 0) && (window.location.pathname.length > 7)) {
  22. switchUser()
  23. }
  24. }, 350)
  25. function switchUser() {
  26. clearInterval(refresh)
  27. let time = localStorage.getItem('gcsu-switches')
  28. let now = Date.now()
  29. if (now-time > 15000 ) {
  30. localStorage.setItem('gcsu-switches', now)
  31. let user
  32. if (window.location.pathname.substring(3,4) == 0) {
  33. user = 1
  34. } else {
  35. user = 0
  36. }
  37. let newlink = "https://classroom.google.com/u/"+ user + window.location.pathname.substring(4) + window.location.search + window.location.hash
  38. window.location.replace(newlink)
  39. }
  40. }
  41. })()