Page 1 of 1

Google chrome source code selection [Super resolved]

Posted: Sat Sep 29, 2012 6:45 pm
by Kwai chang caine
Hello,

I use sometime, google chrome for read our best forum PB :D
So for copy the source code between balise

Code: Select all

 
[/b][/color] i use with IE or FF, double clic or CTRL clic
And here, with GOOGLE CHROME nothing works :shock:

Just the traditionnal selection clic at the begin of the text + SHIFT + clic at the end of the text
But sometime the source code is more big than the size of the screen, and i'm forced to scrolldown for see the end of the text :(

Have you a tips for do that ?

Good day

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 7:01 pm
by skywalk
Use ts-soft's Code Fold javascript.
Drag it into Chrome and enable it as an extension.
I edited it to not fold for < 1000 lines.

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 7:20 pm
by Kwai chang caine
Thanks SKYWALK for your quick answer 8)
I have downloaded the ZIP of TsSoft
I have dragged the ZIP into GOOGLE CHROME and the ZIP appears in down of GOOGLE, and i not know how i can enable it to an extension :oops:

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 7:37 pm
by skywalk
No, unzip the contents into a temp folder.
Then drag the "rs.pbf.codefold.user.js" into Chrome.
You can open the file in a text editor and make changes as you like before pasting.

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 7:45 pm
by Kwai chang caine
Yes i move, i move :D
But apparently GOOGLE since not a long time, for the security, not allow adding extension except if this extension is in the GOOGLE WEB STORE :(

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 7:49 pm
by Kwai chang caine
I have found.....in fact i dragged the extension in the page of GOOGLE not in th extension page :oops:
Now the extension is included 8)
I try to see how use it ...

Thanks again a lot for your explanation, and obviously thanks to TsSoft for his usefull tool
Have a good day you two 8)

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 7:51 pm
by skywalk
Doh! I didn't have that problem. I am running latest Chrome. Maybe turn on developer mode and paste again?
Really need a Chrome guru to answer if that fails :oops:

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 8:05 pm
by Kwai chang caine
No no, no problem now.
In fact if you drag the extension into the main page of CHROME you have a msgbox at the left down of the page a little bit like this "Attention extension can corrupt your computer"
You have two button "continue" and "cancel"
If i click on continue, there are a yellow banner in the top "Extensions and user scripts can't be added except from Chrome webStore" :shock:
It's a protection for the site who added extension without allow of the user.
So if i do tools/extension and drag the JS in the extension page..that's works fine 8)

The only thing i have forgotten it's reboot CHROME for the extension works :oops:

Now, i search how not collapse automatically the code. :oops:
Since all the time, i have the behaviour to look the code in his integrality with a little glance :wink:
And now i'm forced to click on the + button for see the full code

Again thank for your precious help, now i can copy/paste the splendid code of all the members in one clic 8)

Re: Google chrome source code selection

Posted: Sat Sep 29, 2012 8:13 pm
by skywalk
Great! Try editing the line:

Code: Select all

if (code.innerHTML.split("<br>").length - 1 >= 1000)
to delay folding until 1000 lines?

Code: Select all

// ==UserScript==
// @name          CodeFold for PureBasic Forums
// @description   CodeFold
// @include      	http://purebasic.fr/*
// @include      	http://www.purebasic.fr/*
// @include      	http://purebasic.com/*
// @include      	http://www.purebasic.com/*
// @include      	http://forums.purebasic.fr/*
// ==/UserScript== 
var hoch    	= "95px";
var select  	= "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAMAAABIK2QJAAAAB3RJTUUH2AYGEg8u3H74gAAAABd0RVh0U29mdHdhcmUAR0xEUE5HIHZlciAzLjRxhaThAAAACHRwTkdHTEQzAAAAAEqAKR8AAAAEZ0FNQQAAsY8L/GEFAAADAFBMVEVFRUWAAAAAgACAgAAAAICAAIAAgIDAwMDA3MCmyvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAACH5BAEHAAEALAAAAAAKAAoAAAMgGDo8+mEQ4mAUosaGG5sEBjJYWQ5ACmAq8AyddWVy+yQAOw==";
var expandfunc =  '\n';
expandfunc +=     'function expand_code(img_id)\n';
expandfunc +=     '{\n';
expandfunc +=     ' var node = document.getElementById(img_id);\n';
expandfunc +=     ' node.src = "'+minus+'" ;\n';
expandfunc +=     ' node.onclick = function() { collapse_code(img_id); };\n';
expandfunc +=     ' var node = document.getElementById("c"+img_id);\n';
expandfunc +=    '  node.style.overflow = "visible";\n';
expandfunc +=    '  node.style.height = "100%";\n';
expandfunc +=     '}\n';
var collapsefunc = '\n';
collapsefunc +=    'function collapse_code(img_id)\n';
collapsefunc +=    '{\n';
collapsefunc +=    ' var node = document.getElementById(img_id);\n';
collapsefunc +=    ' node.src = "'+plus+'" ;\n';
collapsefunc +=    ' node.onclick = function() { expand_code(img_id); };\n';
collapsefunc +=    ' var node = document.getElementById("c"+img_id);\n';
collapsefunc +=    ' node.style.height = "'+hoch+'";\n';
collapsefunc +=    ' node.style.overflow = "scroll";\n';
collapsefunc +=    '}\n';
var selectfunc  = '\n';
selectfunc     += 'function select_code ( img_id )\n';
selectfunc     += '{\n';
selectfunc     += ' if ( window.getSelection() && window.getSelection().removeAllRanges() ) {\n';
selectfunc     += '   window.getSelection().removeAllRanges();\n';
selectfunc     += ' }\n';
selectfunc     += ' div_id = img_id - 1000;\n';
selectfunc     += ' var node = document.getElementById ( "c" + div_id );\n';
selectfunc     += ' if ( document.createRange() ){;\n';
selectfunc     += '   range = document.createRange();\n';
selectfunc     += '   if ( range.selectNode(node) ){;\n';
selectfunc     += '     range.selectNode(node);\n';
selectfunc     += '   };\n';
selectfunc     += ' };\n';
selectfunc     += ' if ( window.getSelection() && window.getSelection().addRange( range ) ){\n';
selectfunc     += '   window.getSelection().addRange( range );\n';
selectfunc     += ' };\n';
// BEGIN Copy Text To ClipBoard
//selectfunc     += ' var s = window.getSelection();\n';
//selectfunc     += ' var text = s.toString();\n';
//selectfunc     += ' chrome.extension.sendRequest(\n';
//selectfunc     += ' {\n';
//selectfunc     += '   "type" : "reformat",\n';
//selectfunc     += '   "text" : text,\n';
//selectfunc     += ' }\n';
//selectfunc     += '   var rv = document.execCommand("copy", false, null);\n';
//selectfunc     += ' var rv = document.execCommand("copy", false, null);\n';
//selectfunc     += ' }\n';
// ENDOF Copy Text To ClipBoard
selectfunc     += '}\n';
var img_id 		= 0;
var len = document.getElementsByTagName("div").length;
var script;
for (var i = 0;i<len;i++)
{
	if (document.getElementsByTagName("div")[i].className == "codetitle")
	{
		var node = document.getElementsByTagName("div")[i];
		var html = node.innerHTML;       
        var count = 0;				
		var code = 0;
		node.innerHTML = '<b>Code :</b>';
		img_id += 1; 
		select_id = img_id + 1000;
		code = node.nextSibling;
		if (code.innerHTML.split("<br>").length - 1 >= 1000)
		{
			node.innerHTML += '&nbsp;<img id="'+ img_id    +'" src="'+plus  +'" onclick="expand_code('+img_id   +')" />';
			code.style.height = hoch;        
			code.style.overflow = "scroll";        
		}		
		code.id = "c" + img_id;  
		node.innerHTML += '&nbsp;<img id="'+ select_id +'" src="'+select+'" onclick="select_code('+select_id+')" />';
	}
}
script = document.createElement( 'script' );
script.innerHTML  = expandfunc; 
script.innerHTML += collapsefunc; 
script.innerHTML += selectfunc; 
document.body.appendChild(script);

Re: Google chrome source code selection [Resolved]

Posted: Sat Sep 29, 2012 10:04 pm
by Kwai chang caine
Yahhhhhoooo !!!!

It's exactely what i want
Thanks a lot SKYWALK your are the best 8)

I wish you the best night of the world