AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   forum bbcode suggestions (https://forums.alliedmods.net/showthread.php?t=330055)

CrazY. 01-18-2021 09:48

forum bbcode suggestions
 
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.

https://i.imgur.com/czKE06A.png

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.

Mordekay 01-18-2021 11:51

Re: forum bbcode suggestions
 
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. ;-)

CrazY. 01-18-2021 12:48

Re: forum bbcode suggestions
 
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

Black Rose 01-22-2021 20:01

Re: forum bbcode suggestions
 
2 Attachment(s)
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(); 


CrazY. 01-23-2021 07:48

Re: forum bbcode suggestions
 
That's cool, thank you for sharing

Black Rose 01-23-2021 08:35

Re: forum bbcode suggestions
 
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.


All times are GMT -4. The time now is 13:18.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.