switch pytorch code

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

当前为 2022-10-15 提交的版本,查看 最新版本

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