A tool for browsing mojolabs.nz (Old monkey forum archive)

Ferdi

New member
3rd Party Target Dev
Joined
Jun 21, 2017
Messages
87
So when I browse mojolabs.nz forum I see these links:

http://monkeycoder.co.nz/Community/posts.php?topic=449

If you click on it, it goes to a 404. So I made a javascript tool that can transform the monkeycoder.co.nz URL to mojolabs.nz URL.

Javascript compress code (one liner):

JavaScript:
javascript:var SelectedText=function(){};SelectedText.prototype.get=function(){var text="";if(window.getSelection){text=window.getSelection().toString()}else if(document.selection&&document.selection.type!="Control"){text=document.selection.createRange().text}return text};SelectedText.prototype.set=function(replacementText){var sel,range;if(window.getSelection){sel=window.getSelection();if(sel.rangeCount){range=sel.getRangeAt(0);range.deleteContents();range.insertNode(document.createTextNode(replacementText))}}else if(document.selection&&document.selection.createRange){range=document.selection.createRange();range.text=replacementText}};try{var sText=new SelectedText();var selectedText=sText.get();var topicNumber=selectedText.split("topic=");if(topicNumber.length=2){var removeAmp=topicNumber[1].split("&");var topicId=removeAmp[0].trim();var topicIdLen=topicId.length;for(var i=0;i<(5-topicIdLen);i++){topicId="0"+topicId}var mojolabsUrl="http://mojolabs.nz/posts.php?topic=2"+topicId;sText.set(mojolabsUrl)}}catch(e){alert(e.message)}

Full Javascript code:

JavaScript:
javascript:var SelectedText = function() {};

SelectedText.prototype.get = function() {
    var text = "";
    if (window.getSelection) {
        text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
        text = document.selection.createRange().text;
    }
    return text;
};

SelectedText.prototype.set = function(replacementText) {
    var sel, range;
    if (window.getSelection) {
        sel = window.getSelection();
        if (sel.rangeCount) {
            range = sel.getRangeAt(0);
            range.deleteContents();
            range.insertNode(document.createTextNode(replacementText));
        }
    } else if (document.selection && document.selection.createRange) {
        range = document.selection.createRange();
        range.text = replacementText;
    }
};

try
{
    var sText = new SelectedText();
    var selectedText = sText.get();
    var topicNumber = selectedText.split("topic=");

    if (topicNumber.length = 2)
    {
        var removeAmp = topicNumber[1].split("&");

        var topicId = removeAmp[0].trim();
        var topicIdLen = topicId.length;
        for (var i = 0; i < (5 - topicIdLen); i++)
        {
            topicId = "0" + topicId;
        }

        var mojolabsUrl = "http://mojolabs.nz/posts.php?topic=2" + topicId;
        sText.set(mojolabsUrl);
    }
}
catch(e)
{
    alert(e.message);
}

To install this tool, just drag and drop the javascript one liner to your bookmark bar. You may want to rename it to something more descriptive.

draganddrop.png

To use it, select the monkeycoder.co.nz URL and press the javascript bookmark.

selectandclickbutton.png

Then select it again, right click and use goto mojolabs.nz...

selectandclickbutton.png

I will update this post with pictures. (DONE!)
 

Attachments

  • gotomojolabs.png
    gotomojolabs.png
    20 KB · Views: 326
Last edited:
Top Bottom