Greasy Fork 还支持 简体中文。

Codeskulptor Brython

Add the Brython python interpreter to CodeSkulptor

  1. // ==UserScript==
  2. // @name Codeskulptor Brython
  3. // @namespace http://mcimino.reaktix.com/
  4. // @version 0.1
  5. // @description Add the Brython python interpreter to CodeSkulptor
  6. // @match http://www.codeskulptor.org/*
  7. // @copyright 2012+, Saibotshamtul
  8. // ==/UserScript==
  9.  
  10. function BrythonSetup(){
  11. __BRYTHON__.stdout={write:Sk.output};
  12. __BRYTHON__.stderr={write:Sk.debugout};
  13. __BRYTHON__.VFS.simplegui = [".js",Sk.builtinFiles.files['src/lib/simplegui/__init__.js']+";var $module=$builtinmodule;"];
  14. __BRYTHON__.VFS.simpleplot = [".js",Sk.builtinFiles.files['src/lib/simpleplot/__init__.js']+";var $module=$builtinmodule;"];
  15. brython({debug:1})
  16. }
  17.  
  18. b = document.createElement("button")
  19. b.id="runb"
  20. b.accessKey="T"
  21. b.title="Run using Brython (Accesskey T)"
  22. b.className="tb-button-icon ui-button ui-widget ui-corner-all ui-button-icon-only ui-state-default"
  23. b.style.cssText="background:#faa;border:1px solid #faa;"
  24.  
  25. $("#controls")[0].children[0].appendChild(b)
  26.  
  27. b.onmouseover=function(){
  28. runb.classList.remove("ui-state-default")
  29. runb.style.border="1px solid rgb(0,36,106)"
  30. }
  31. b.onmouseout=function(){
  32. runb.classList.add("ui-state-default")
  33. runb.style.border="1px solid #faa"
  34. }
  35. //b.onclick=function(){
  36. // brython(1)
  37. //}
  38. b.onfocus=function(){
  39. //this.onmouseout()
  40. runb.blur()
  41. }
  42. b.onblur=function(){
  43. //this.onmouseover()
  44. }
  45. a = document.createElement("span")
  46. a.className="ui-button-icon-primary ui-icon ui-icon-play"
  47. b.appendChild(a)
  48.  
  49. a = document.createElement("span")
  50. a.className="ui-button-text"
  51. b.appendChild(a)
  52.  
  53. //$("#controls")[0].children[0].appendChild(b)
  54.  
  55. a = document.createElement("script")
  56. a.type="text/python"
  57. a.id="brycode"
  58. //c = "from browser import alert;alert('hi');"
  59.  
  60. c = (function(){/*
  61. from browser import document,alert
  62. import traceback
  63.  
  64. def runcode(ev):
  65. document["reset"].click()
  66.  
  67. a = ""
  68. b=document.get(selector=".CodeMirror-code div pre")
  69. for z in range(len(b)):
  70. c=b[z].innerText
  71. a+=c+"\n"
  72. #print(a)
  73. try:
  74. eval(a)
  75. except:
  76. try:
  77. exec(a)
  78. except:
  79. traceback.print_exc()
  80.  
  81. document['runb'].bind('click',runcode)
  82. */}).toString().slice(14,-3)
  83. a.innerHTML = c
  84. document.body.appendChild(a)
  85.  
  86. $.getScript("http://brython.info/src/brython_dist.js",BrythonSetup)