Skip to content

Instantly share code, notes, and snippets.

@Catsync
Created June 6, 2015 17:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Catsync/4067ce1b69bb1dfb86d2 to your computer and use it in GitHub Desktop.
Save Catsync/4067ce1b69bb1dfb86d2 to your computer and use it in GitHub Desktop.
Put this in the chrome dev tools under Sources -> Snippets. Use when your referee's setUpLevel code prevents loading your level in the editor. It'll add "{}" to the end of your referee's extraCode, which you can remove after you've fixed it.
(function(currentView) {
var thangs = currentView.level.get('thangs');
var refereeThang = null;
for(var i=0; i < thangs.length; i++) {
var thang = thangs[i];
if(thang.components) {
for(var j=0; j < thang.components.length; j++) {
var component = thang.components[j];
if(component.config && component.config.extraCode) {
refereeThang = thang;
refereeCode = component.config.extraCode;
component.config.extraCode = refereeCode + '\n{}';
console.log('Found referee, commenting out extraCode');
currentView.level.set('thangs',thangs);
break;
}
}
}
if(refereeThang !== null) {
break;
}
}
if(refereeThang === null) {
console.log("Referee not found.");
}
})(currentView);
@nwinter
Copy link

nwinter commented Jan 4, 2016

If you can't load the level at all due to an infinite loop in setUpLevel, then you can get to the thangs from any other page on codecombat.com like this:

var thangs = JSON.parse(localStorage["lscache-" + currentView.level.id]).thangs

You could then adapt this script to JSON.stringify() the updated level and put it in localStorage with that cache key.

@Harry-the-Wanderer
Copy link

Harry-the-Wanderer commented Sep 19, 2016

Using Safari's Web Inspector the following HTML can be injected into the broken page. Creating an easy click button to run the above code. This should work on Firefox as well.

<button onclick="var t = currentView.level.get('thangs');var r = null;for(var i=0; i < t.length; i++) {var h = t[i];if(h.components) {for(var j=0; j < h.components.length; j++) {var c = h.components[j];if(c.config && c.config.extraCode) {r = h;var e = c.config.extraCode;c.config.extraCode = e + '\n{}';console.log('Found referee, commenting out extraCode');currentView.level.set('thangs',t);break;}}}if(r !== null) {break;}}if(r === null) {console.log('Referee not found.');}">Click to Fix the referee Code</button><p>Then refresh the browser page</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment