Last active
July 29, 2017 07:23
-
-
Save GeonoTRON2000/2e67182f291259e132a4986ae60b1f99 to your computer and use it in GitHub Desktop.
Allow Scratch 1.4 projects to be embedded in BBcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: [scratch=flash|java]author/projectID[/scratch] | |
var j; | |
var posts = document.getElementsByClassName("postmsg"); | |
for (j = 0; j < posts.length; j++) { | |
var post = posts[j]; | |
if (post.parentElement.parentElement.parentElement.parentElement.className == "blockpost rowodd firstpost") { | |
var thishtml = post.innerHTML; | |
var javas = []; | |
var i; | |
for (i = 0; i < thishtml.split("[scratch=java]").length - 1; i++) { | |
javas[i] = thishtml.split("[scratch=java]")[i+1].split("[/scratch]")[0]; | |
} | |
for (i = 0; i < javas.length; i++) { | |
var author = javas[i].split("/")[0]; | |
var id = parseInt(javas[i].split("/")[1])+''; | |
if (id == 'NaN') { | |
author="Redrocker227"; | |
id=2691546; | |
} | |
thishtml = thishtml.replace(/\[scratch=java\](.+?)\[\/scratch\]/i, "<applet id='ProjectApplet' style='display:block' code='ScratchApplet' codebase='http://scratch.mit.edu/static/misc' archive='ScratchApplet.jar' height='387' width='482'><param name='project' value='../../static/projects/"+author+"/"+id+".sb'></applet>"); | |
} | |
post.innerHTML = thishtml; | |
} | |
} | |
for (j = 0; j < posts.length; j++) { | |
var post = posts[j]; | |
if (post.parentElement.parentElement.parentElement.parentElement.className == "blockpost rowodd firstpost") { | |
var thishtml = post.innerHTML; | |
var flashes = []; | |
var i; | |
for (i = 0; i < thishtml.split("[scratch=flash]").length - 1; i++) { | |
flashes[i] = thishtml.split("[scratch=flash]")[i+1].split("[/scratch]")[0]; | |
} | |
for (i = 0; i < flashes.length; i++) { | |
var author = flashes[i].split("/")[0]; | |
var id = parseInt(flashes[i].split("/")[1]); | |
if (id == 'NaN') { | |
author="Redrocker227"; | |
id=2691546; | |
} | |
thishtml = thishtml.replace(/\[scratch=flash\](.+?)\[\/scratch\]/i, "<object width='483' height='387' type='application/x-shockwave-flash' data='http://scratch.mit.edu/static/misc/PlayerOnly.swf'><param name='allowScriptAccess' value='always'><param name='allowFullScreen' value='true'><param name='flashvars' value='project=http://scratch.mit.edu/static/projects/"+author+"/"+id+".sb?version=1'></object>"); | |
} | |
post.innerHTML = thishtml; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment