CodehsHack

Auto get HTML/styles for codeHS assignments

  1. // ==UserScript==
  2. // @name CodehsHack
  3. // @namespace https://gf.qytechs.cn/users/783447
  4. // @version 2.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. function copyStringToClipboard (str) {
  15. // Create new element
  16. var el = document.createElement('textarea');
  17. // Set value (string to be copied)
  18. el.value = str;
  19. // Set non-editable to avoid focus and move outside of view
  20. el.setAttribute('readonly', '');
  21. el.style = {position: 'absolute', left: '-9999px'};
  22. document.body.appendChild(el);
  23. // Select text inside element
  24. el.select();
  25. // Copy text to clipboard
  26. document.execCommand('copy');
  27. // Remove temporary element
  28. document.body.removeChild(el);
  29. }
  30.  
  31. if(window.location.pathname.substring(0, 9) == "/student/") {
  32. var itemID = document.getElementsByClassName('banner alert-warning center')[0].children[1].getAttribute('data-item-id')
  33.  
  34. window.open("https://codehs.com/editor/"+itemID+"/solution/index.html");
  35. window.open("https://codehs.com/editor/"+itemID+"/solution/style.css");
  36. //window.open("https://codehs.com/editor/"+itemID+"/solution/jobinfo.html");
  37. }
  38. else if(window.location.pathname.substring(0, 8) == "/editor/") {
  39.  
  40.  
  41.  
  42.  
  43. setInterval(function(){
  44. if (document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--') !== -1) {
  45. var scriptStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('<noscript>');
  46. var scriptEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('</script>');
  47. var subScript = document.getElementsByTagName('html')[0].innerHTML.slice(scriptStart, scriptEnd+9);
  48. document.getElementsByTagName('html')[0].innerHTML = document.getElementsByTagName('html')[0].innerHTML.replace(subScript, '')
  49.  
  50. var titleStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('&lt;');
  51. var titleEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('&gt;');
  52. var titleSlice = document.getElementsByTagName('html')[0].innerHTML.slice(titleStart, titleEnd+4);
  53. document.getElementsByTagName('html')[0].innerHTML = document.getElementsByTagName('html')[0].innerHTML.replace(titleSlice, '')
  54.  
  55.  
  56. var badStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--');
  57. var badEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('-->');
  58. var badSub = document.getElementsByTagName('html')[0].innerHTML.slice(badStart, badEnd+3);
  59. var newHTML = document.getElementsByTagName('html')[0].innerHTML.replace(badSub, '');
  60. document.getElementsByTagName('html')[0].innerHTML = newHTML
  61.  
  62. badStart = newHTML.indexOf('<!--', '-->')
  63. badEnd = newHTML.indexOf('-->');
  64. badSub = newHTML.slice(badStart, badEnd+3);
  65.  
  66. if (document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--') == -1) {
  67. console.log(newHTML)
  68. document.getElementsByTagName('body')[0].style.color = 'white'
  69. document.getElementsByTagName('body')[0].style.backgroundImage = "url('https://wallpaperaccess.com/full/1129018.jpg')"
  70. document.getElementsByTagName('body')[0].textContent = ''
  71.  
  72. const newButton = document.createElement('button')
  73. newButton.innerHTML = 'Copy'
  74. newButton.style.display = "grid"
  75. newButton.style.border = "none"
  76. newButton.style.padding = "7px"
  77. newButton.style.width = "100px"
  78. newButton.style.backgroundColor = '#0e95cf'
  79. document.getElementsByTagName('body')[0].appendChild(newButton)
  80. newButton.addEventListener('click', function handleClick(event) {
  81. copyStringToClipboard(newHTML)
  82. window.close()
  83. });
  84.  
  85. }
  86. }
  87. }, 1);
  88. }
  89. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址