switch pytorch code

切换到pytorch代码块,而不是默认的块,仅在第一次进入界面时生效

  1. // ==UserScript==
  2. // @name switch pytorch code
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description 切换到pytorch代码块,而不是默认的块,仅在第一次进入界面时生效
  6. // @description:en switch pytorch code panel instead default when first in!
  7. // @author Letsgo0
  8. // @match https://*.d2l.ai/*/*
  9. // @match http://*.d2l.ai/*/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=d2l.ai
  11. // @grant none
  12. // @run-at document-idle
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Your code here...
  19. let timer = setTimeout( switchPytorch,500)
  20. const stoper = setInterval( ()=>{stopFlag = true;}, 5000);
  21.  
  22. function switchPytorch() {
  23. const selector = 'a[href|="#pytorch"].mdl-tabs__tab';
  24. const pyEle = document.querySelector(selector)
  25. if (pyEle){
  26. const className = pyEle.getAttribute('class') || '';
  27. if (!className.includes('is-active')){
  28. pyEle.click()
  29. }
  30. }
  31. else if (stopFlag == false){
  32. timer = setTimeout( switchPytorch,500);
  33. }
  34. }
  35. })();