This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-23 11:32:36

Servine
Scratcher
Registered: 2011-03-19
Posts: 1000+

JavaScript Help!

I'm making a userscript, like this:

[center]texthi[/center]

but when the text has spaces, the userscript ignores it.

It is based on Antidote:

Code:

// ==UserScript==

// @name          Servines ATS
// @namespace     http://www.scratch.mit.edu/
// @description   Advanced Text Styling for Scratch!
// @include       *

// ==/UserScript==
var version = 10;
if (document.URL.indexOf('http://scratch.mit.edu/forums/viewtopic.php') != -1) {

//replace important tags
 var bodyElement = document.getElementsByTagName("body")[0];
 var bodyInner = bodyElement.innerHTML;
 var imageurls = new Array();
 for (i=0;i<bodyInner.split(/\[important\]/i).length-1;i++) {
  imageurls[i] = bodyInner.split(/\[important\]/i)[i+1].split(/\[\/important\]/i)[0];
  if (imageurls[i].replace(/[a-zA-Z0-9\-_]+/, "") !== ""){
   imageurls[i] = 'Undefined';
  }
 }
 var toPrint = bodyInner;
 for (i=0;i<imageurls.length;i++) {
  toPrint = toPrint.replace(/\[important\]([a-zA-Z0-9\-_]+)\[\/important\]/i, '<b><u>'+ imageurls[i] + '</u></b>');
 }
 
 //replace centering
 var centertags = new Array();
 for (i=0;i<toPrint.split(/\[center\]/i).length-1;i++) {
  centertags[i] = toPrint.split(/\[center\]/i)[i+1].split(/\[\/center\]/i)[0];
  if (centertags[i].replace(/[a-zA-Z0-9\-_]+/, "") !== "") {
   centertags[i] = 'Undefined';
  }
 }
 for (i=0;i<centertags.length;i++) {
  toPrint = toPrint.replace(/\[center\]([a-zA-Z0-9\-_]+)\[\/center\]/i, '<center>' + centertags[i] + '</center>');
 }
 
//replace project tags
  var projectpath = new Array();
 for (i=0;i<toPrint.split(/\[scratch=flash\]/i).length-1;i++) {
  projectpath[i] = toPrint.split(/\[scratch=flash\]/i)[i+1].split(/\[\/scratch\]/i)[0];
  if (projectpath[i].replace(/[a-zA-Z0-9]+\/[0-9]+/i, "") !== "") {
   projectpath[i] = 'Mike16112/675815';
  }
 }
 for (i=0;i<projectpath.length;i++) {
  toPrint = toPrint.replace(/\[scratch=flash\]([a-zA-Z0-9]+\/[0-9]+)\[\/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/' + projectpath[i] + '.sb?version=1"></object>');
 }
 document.getElementsByTagName("body")[0].innerHTML = toPrint;
 document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML.replace(/antidoteexists=false/ig, 'antidoteexists=true&version=' + version);
}

[important]HELP[/important]

Last edited by Servine (2012-08-23 11:34:27)


http://bluetetrarpg.x10.mx/usercard/?name=Servine

Offline

 

#2 2012-08-23 11:53:04

Ecliptic
Scratcher
Registered: 2012-02-27
Posts: 500+

Re: JavaScript Help!


If you can read this you are in range.

Offline

 

#3 2012-08-23 11:56:22

Servine
Scratcher
Registered: 2011-03-19
Posts: 1000+

Re: JavaScript Help!

Ecliptic wrote:

Javascript Topic?

Oh.

But it wont get that much notice. I kinda need it ASALN (As soon as... Like Now!  tongue )


http://bluetetrarpg.x10.mx/usercard/?name=Servine

Offline

 

#4 2012-08-23 12:21:37

Servine
Scratcher
Registered: 2011-03-19
Posts: 1000+

Re: JavaScript Help!

bump


http://bluetetrarpg.x10.mx/usercard/?name=Servine

Offline

 

#5 2012-08-23 12:41:10

Servine
Scratcher
Registered: 2011-03-19
Posts: 1000+

Re: JavaScript Help!

YAYAYAYAYAYAY. I fixed it  big_smile  big_smile  big_smile  big_smile  big_smile  big_smile  big_smile  big_smile


http://bluetetrarpg.x10.mx/usercard/?name=Servine

Offline

 

#6 2012-08-23 13:20:46

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: JavaScript Help!

Closed by request of the topic owner.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer