CodehsHack

Auto get HTML/styles for codeHS assignments

目前为 2022-12-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CodehsHack
  3. // @namespace https://greasyfork.org/users/783447
  4. // @version 1.0
  5. // @description Auto get HTML/styles for codeHS assignments
  6. // @author You
  7. // @match https://codehs.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=codehs.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.  
  14. //Tedious
  15. if(window.location.pathname.substring(0, 9) == "/student/") {
  16. var itemID = document.getElementsByClassName('banner alert-warning center')[0].children[1].getAttribute('data-item-id')
  17.  
  18. window.open("https://codehs.com/editor/"+itemID+"/solution/index.html");
  19. window.open("https://codehs.com/editor/"+itemID+"/solution/style.css");
  20. //window.open("https://codehs.com/editor/"+itemID+"/solution/jobinfo.html");
  21. }
  22. else if(window.location.pathname.substring(0, 8) == "/editor/") {
  23.  
  24.  
  25.  
  26.  
  27. setInterval(function(){
  28. if (document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--') !== -1) {
  29. var scriptStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('<noscript>');
  30. var scriptEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('</script>');
  31. var subScript = document.getElementsByTagName('html')[0].innerHTML.slice(scriptStart, scriptEnd+9);
  32. document.getElementsByTagName('html')[0].innerHTML = document.getElementsByTagName('html')[0].innerHTML.replace(subScript, '')
  33.  
  34. var titleStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('&lt;');
  35. var titleEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('&gt;');
  36. var titleSlice = document.getElementsByTagName('html')[0].innerHTML.slice(titleStart, titleEnd+4);
  37. document.getElementsByTagName('html')[0].innerHTML = document.getElementsByTagName('html')[0].innerHTML.replace(titleSlice, '')
  38.  
  39.  
  40. var badStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--');
  41. var badEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('-->');
  42. var badSub = document.getElementsByTagName('html')[0].innerHTML.slice(badStart, badEnd+3);
  43. var newHTML = document.getElementsByTagName('html')[0].innerHTML.replace(badSub, '');
  44. document.getElementsByTagName('html')[0].innerHTML = newHTML
  45.  
  46. badStart = newHTML.indexOf('<!--', '-->')
  47. badEnd = newHTML.indexOf('-->');
  48. badSub = newHTML.slice(badStart, badEnd+3);
  49.  
  50. if (document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--') == -1) {
  51. console.log(newHTML)
  52. document.getElementsByTagName('body')[0].style.color = 'white'
  53. document.getElementsByTagName('body')[0].style.backgroundImage = "url('https://wallpaperaccess.com/full/1129018.jpg')"
  54. document.getElementsByTagName('body')[0].textContent = ''
  55.  
  56. const newPre = document.createElement('pre')
  57. newPre.id = "preId"
  58. newPre.textContent = newHTML
  59. document.getElementsByTagName('body')[0].appendChild(newPre);
  60.  
  61. }
  62. }
  63. }, 1);
  64. }
  65. })();