Descriptor
757 posts
|
Topic: Userscripts Code Block Fix
dob wrote:
I edited my post, because it was killed by the formatting. It just closes tags that I intentionally leave open, even if they're htmlentities.
Ahh, I see, but put them in <code> tags and it should work. test <input>, but I agree it should at least ignore tags that aren't accepted as markup code. Use &lt; for entities <
|
| |
dob
248 posts
|
Topic: Userscripts Code Block Fix
Descriptor wrote: @dob
turn off Greasemonkey and reload the page, there's nothing wrong with the post - my syntax highlighter is doing the same thing. @Aquilax
You can use a function in replace, so I think there's a shorter way to do that (no time, but intriguing).
I edited my post, because it was killed by the formatting. It just closes tags that I intentionally leave open, even if they're htmlentities.
|
| |
Aquilax
295 posts
|
Topic: Userscripts Code Block Fix
Here a source script, I'm doing it to test the it :)
It seems to work, but if I use the < code > and < / code > inside the regexp, they create some confusion to the forum engine :)
To use it you have to replace the [code] and [/code] with the reals < code > and < / code >
// ==UserScript==
// @name Userscripts
// @namespace Replace inside code block
// @include http://userscripts.org/forums/*/topics/*
// @include http://userscripts.org/scripts/show/*
// @include http://userscripts.org/scripts/edit/*
// ==/UserScript==
init();
function init()
{
addFormsSubmissionEventListener(document);
window.addEventListener("unload",revertTextAreas,false);
document.addEventListener("DOMNodeInserted",function(e){addFormsSubmissionEventListener(e.relatedNode);},false);
unsafeWindow.revertTextAreas=revertTextAreas;
}
function addFormsSubmissionEventListener(node)
{
var array1=node.getElementsByTagName("FORM");
for(var num1=0;num1<array1.length;num1++)
{
var form1=array1[num1];
var text1=form1.getAttribute("onsubmit");
if (text1==null) text1="";
if (text1.indexOf("replaceCodeBlocks")==-1)
{
var text2=text1.indexOf("Ajax")!=1?"; revertTextAreas();":"";
form1.setAttribute("onsubmit","replaceCodeBlocks(this); "+text1+text2);
}
var array2=form1.getElementsByTagName("TEXTAREA");
var replacer=function(str,p1){return "[code]+p1.replace(/</gm,"<").replace(/>/gm,">").replace(/&/gm,"&")+"[/code]";}
for(var num2=0;num2<array2.length;num2++)
{
var textarea1=array2[num2];
if (textarea1.originalValue==null)
{
var text2=textarea1.value.replace(/[code]((?:.|\s)*?)[\/code]/gmi,replacer);
textarea1.value=text2;
textarea1.originalValue=text2;
GM_log(text2);
}
}
}
}
unsafeWindow.replaceCodeBlocks=function(form)
{
var array1=form.getElementsByTagName("TEXTAREA");
var replacer=function(str,p1){return "[code]"+p1.replace(/&/gm,"&").replace(/</gm,"<").replace(/>/gm,">")+"[/code]";}
for(var num1=0;num1<array1.length;num1++)
{
var textarea1=array1[num1];
var text1=textarea1.value;
textarea1.originalValue=text1;
textarea1.value=text1.replace(/[code]((?:.|\s)*?)[\/code]/gmi,replacer);
}
}
function revertTextAreas(e)
{
var array1=document.getElementsByTagName("TEXTAREA");
for(var num1=0;num1<array1.length;num1++)
{
var textarea1=array1[num1];
if (textarea1.originalValue) textarea1.value=textarea1.originalValue;
}
}
|
| |
Aquilax
295 posts
|
Topic: Userscripts Code Block Fix
Wow, I was used with others languages where you could pass a function (lambda expression) to make the replace but not with javascript, this is really nice :), this means that it can be done like this:
mytextarea.value.replace(/<code>((?:.|\s)*?)<\/code>/gmi, function(str,p1,offset,s){ return "<code>"+p1.replace(/</gm,"<").replace(/>/gm,">")+"</code>";})
Now I'm waiting for the named captures :)
|
| |
Descriptor
757 posts
|
Topic: Userscripts Code Block Fix
@dob
turn off Greasemonkey and reload the page, there's nothing wrong with the post - my syntax highlighter is doing the same thing.
@Aquilax
You can use a function in replace, so I think there's a shorter way to do that (no time, but intriguing).
|
| |
Aquilax
295 posts
|
Topic: Userscripts Code Block Fix
I can give you some code, but I'm writing it on the fly, don't expect to be bugs free
var text1=mytextarea.value;
var regexp1=new Regexp("<code>(.|\\s)*?</code>","gmi");
var match1=regexp1.exec(text1);
while(match1)
{
var num1=match1.index+6;
var num2=match1[1].length;
var text2=text1.substring(0,num1); //everything till ...<code>
var text3=text1.substring(num1+1,num2); //everything inside <code>...</code>
var text3=text1.substring(num1+num2+1); //everything after </code>...
text2=text2.replace(/</gmi,"<").replace(/>/gmi,">");
text1=text2+text3+text4;
match1=regexp1.exec(text1);
}
|
| |
dob
248 posts
|
Topic: Userscripts Code Block Fix
Here's your script: http://nopaste.voric.com/paste.php?f=65y61v
|
| |
dob
248 posts
|
Topic: Userscripts Code Block Fix
I'm so sick and tired of this shitty text fomatting.
Seriously, just freaking htmlentities() all of it, PLEASE!
|
| |
Napzter
19 posts
|
Topic: [REQ] Google Music
Im sorry, i missed the part about the Enter button.
You don't need to translate it. What i meant was, that it only includes google.com, wich is a bit of a problem for me because i use google.dk.
Make it include http://www.google.*/.
Napzter
|
| |
Napzter
19 posts
|
Topic: [REQ] Google Music
Hah! I found two bugs. You can't search for music if you press enter, and it only works for the english google.
|
| |
Napzter
19 posts
|
Topic: [REQ] Google Music
Thanks. I'll maybe edit it a bit.
|
| |
Napzter
19 posts
|
Topic: [REQ] Google Music
Thank you. Im not very good at the coding, and i would appreciate if you made the code for it. :D
|
| |
Napzter
19 posts
|
Topic: [REQ] Google Music
[REQUEST]
I thougt of something like "Your source for free music" or something.
It should simply just do something like putting in "indexOf (mp3) " in front of the search word and " -html -php -asp -jsp" at the end of it, when you click a button beside it.
Napzter
|