Raised This Month: $ Target: $400
 0% 

forum bbcode suggestions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-18-2021 , 10:48   forum bbcode suggestions
Reply With Quote #1

Hey, what's up

So, I was answering some questions in the AMXX scripting help section and I ended up having two ideas that may be useful.

The first is to display the number of each line in the left edge of the code just like https://paste.ofcode.org. Sometimes the question author informs which line he's having problems with but there's no way to know what's that line unless you paste the code in a text editor like sublime or notepad. Also, once you click on the line number, the page is automatically scrolled.



The second one is to have a copy-all button. Currently you have to scroll down through the whole code to copy everything and depending on the length this may take forever.
__________________
Accepting private $$$ plugins requests.

@Steam: crazy770
@Discord: CrazY.#5317

Website | Channel


Last edited by CrazY.; 01-18-2021 at 10:50.
CrazY. is offline
Mordekay
Squirrel of Fortune
Join Date: Apr 2006
Location: Germany
Old 01-18-2021 , 12:51   Re: forum bbcode suggestions
Reply With Quote #2

I doubt this will be done as the work on the forum itself is stalled (and new features should be made at bugzilla), but at least 'til then a tip for marking code for copy:
one klick left onto the first letter/symbol
pull down the scrollbar to the bottom or whatever part you want to mark
hold left shift and one more left klick on the last letter.
done, everything marked. Takes only a few seconds this way. ;-)
__________________

Mordekay is online now
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-18-2021 , 13:48   Re: forum bbcode suggestions
Reply With Quote #3

oh ok
Quote:
one klick left onto the first letter/symbol
pull down the scrollbar to the bottom or whatever part you want to mark
hold left shift and one more left klick on the last letter.
I completely forgot about it, thanks
__________________
Accepting private $$$ plugins requests.

@Steam: crazy770
@Discord: CrazY.#5317

Website | Channel

CrazY. is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, Sweden
Old 01-22-2021 , 21:01   Re: forum bbcode suggestions
Reply With Quote #4

https://chrome.google.com/webstore/d...gnaaelnpjljija (or something similar)

Nothing fancy.
It doesn't add line numbers to edits or new posts, only existing posts on page load.
Edit to your liking.

PHP Code:
var lineHeight 0;
var 
listAlreadyDone = [];
var 
listSpoilers = [];

function 
CalculateLineHeight(element)
{
    var 
temp element.cloneNode(false);
    
temp.innerHTML 'a<br>b';
    
element.parentNode.insertBefore(tempelement);
    var 
retVal temp.offsetHeight 2.0;
    
temp.parentNode.removeChild(temp);
    
    return 
retVal;
}

function 
CreateLineCountBeforeElement(element)
{
    if ( 
listAlreadyDone.includes(element) )
        return;
    if ( ! 
lineHeight )
        
lineHeight CalculateLineHeight(element);
    
    if ( ! 
lineHeight )
        return;
    
    var 
numLines Math.ceil(element.offsetHeight lineHeight);
    
    if ( ! 
numLines )
        return;

    var 
tempDiv document.createElement('div');
    
    for ( var 
<= numLines i++ )
        
tempDiv.innerHTML += '&nbsp;<br>';
    
    
tempDiv.className 'LineCount';
    
tempDiv.style.float 'left';
    
tempDiv.style.textAlign 'right';
    
tempDiv.style.color 'grey';
    
tempDiv.style.borderRight "1px dotted grey";
    
tempDiv.style.marginRight '6px';
    
tempDiv.style.userSelect 'none';

    
element.parentNode.insertBefore(tempDivelement);

    
// Add copy button...

    
var CodeBoxHeader element;
    while ( 
true ) {
        
CodeBoxHeader CodeBoxHeader.parentNode;

        if ( 
CodeBoxHeader.getElementsByClassName('smallfont').length ) {
            
CodeBoxHeader CodeBoxHeader.getElementsByClassName('smallfont')[0];
            break;
        }
    }

    
CodeBoxHeader.style.marginBottom '8px';

    var 
tempButton document.createElement('button');
    
tempButton.style.float 'right';
    
tempButton.className 'smallfont';
    
tempButton.value listAlreadyDone.length;
    
tempButton.innerHTML 'Copy to clipboard';

    
tempButton.addEventListener("click", function() {
        
CopyCode(this.value);
    });

    
CodeBoxHeader.appendChild(tempButton);

    
listAlreadyDone.push(element);
}

function 
CopyCode(index)
{
    var 
range document.createRange();
    
range.selectNode(listAlreadyDone[index]);
    
window.getSelection().addRange(range);

    try {
        
document.execCommand('copy');
    } catch (
err) {
        
alert('An error occured while copying text to clipboard');
    }

    
setTimeout('window.getSelection().removeAllRanges()'100);
}

function 
CheckForNewCodeBoxes() {

    var 
inputElements document.getElementsByTagName('input');


    for ( var 
inputElements.length i++ )
    {
        if ( 
inputElements[i].value == 'Show' )
        {
            
listSpoilers.push(inputElements[i])
            
inputElements[i].click();
        }
    }

    var 
CodeBoxesPawn document.getElementsByClassName('pawn');
    
    for ( var 
CodeBoxesPawn.length i++ )
        
CreateLineCountBeforeElement(CodeBoxesPawn[i]);
    
    var 
CodeBoxesCode document.getElementsByTagName('pre');
    
    for ( var 
CodeBoxesCode.length i++ )
    {
        if ( 
CodeBoxesCode[i].getElementsByClassName('pawn').length )
            continue;

        if ( 
CodeBoxesCode[i].getElementsByTagName('code').length )
            continue;
        
        
CodeBoxesCode[i].innerHTML '<code><code>' CodeBoxesCode[i].innerHTML '</code></code>';
    }
    
    var 
CodeBoxesPHP document.getElementsByTagName('code'); // Which also now includes the normal "Code" boxes.
    
    
for ( var CodeBoxesPHP.length i+=)
    {
        
CreateLineCountBeforeElement(CodeBoxesPHP[i]);
        
CodeBoxesPHP[i].style.display 'block';
    }

    for ( var 
listSpoilers.length i++ )
           
listSpoilers[i].click();

    
listSpoilers.length 0;
}

CheckForNewCodeBoxes(); 
Attached Thumbnails
Click image for larger version

Name:	Untitled-1.png
Views:	17
Size:	93.7 KB
ID:	186624  
__________________

Last edited by Black Rose; 01-23-2021 at 09:55.
Black Rose is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-23-2021 , 08:48   Re: forum bbcode suggestions
Reply With Quote #5

That's cool, thank you for sharing
__________________
Accepting private $$$ plugins requests.

@Steam: crazy770
@Discord: CrazY.#5317

Website | Channel

CrazY. is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, Sweden
Old 01-23-2021 , 09:35   Re: forum bbcode suggestions
Reply With Quote #6

No problem. I love doing stuff with JavaScript.

I had a tug of war with the automatic forum security over onclick event in the code which I eventually won.
Now also contains copy button.
__________________

Last edited by Black Rose; 01-23-2021 at 09:36.
Black Rose is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:19.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode